Introduction
XBM is the black and white image format of the X Window System, used for icons,
cursors and fill patterns on Unix desktops. An XBM file is a piece of C source code,
so a program can #include it and get the image as an array of bytes,
with no image loader at all.
Each pixel is one bit, set or clear, so there are no colours. Colour icons in X use the related XPM format. Early web browsers could show XBM images, but modern ones no longer do.
Structure
The file defines the width and height as C macros, then an array of bytes with the
pixels. The macro names start with the image name. Two optional macros,
_x_hot and _y_hot, give the hotspot of a cursor.
#define arrow_width 16
#define arrow_height 16
static unsigned char arrow_bits[] = {
0x00, 0x00, 0x02, 0x00, 0x06, 0x00, …
};
Pixels are stored row by row from the top. Each row is padded to a whole number of
bytes, and within each byte the leftmost pixel is the lowest bit. A set bit is a
foreground pixel. Old X10 files use an array of 16-bit short values
instead of bytes. See Syntax and bits.
Not described
The syntax page was re-checked against the libX11 source (CrBFData.c, RdBitF.c, WrBitF.c) and the Xlib manual page; its reading rules are in How Xlib reads the file. Not yet covered:
Known, not yet covered
- Reference: variants that real files carry beyond the libX11 reader are not described: declarations with
const(such asstatic const unsigned char) or withoutstatic, which the libX11 reader does not accept, and how other readers (Tk, GTK, Qt, ImageMagick, netpbm) treat them. Not yet checked against those sources. - Viewer: there is no XBM plugin yet.
Links
Software
- GIMP – free image editor that opens and saves XBM (Windows, macOS, Linux)
- ImageMagick – command-line tool that converts images to and from XBM (Windows, macOS, Linux)
- bitmap – the X Window System bitmap editor (Linux, Unix)
Developers
- libX11 – the X client library, which reads and writes XBM with
XReadBitmapFileandXWriteBitmapFile(C)
Reference
- XReadBitmapFile(3) – the Xlib manual page for reading, writing and creating bitmaps