XPM went through three forms. XPM 1 (1989) imitated XBM with C defines; XPM 2 (1990) dropped C for plain lines of text; XPM 3 (1991) went back to C, as one array of strings. libXpm still reads all three and writes only XPM 3.
Telling them apart
libXpm looks at the first words of the file:
| Start of the file | Version | Syntax |
|---|---|---|
#define name_format | XPM 1 | C defines and two arrays |
/* XPM */ | XPM 3 | C array of strings |
! XPM2 | XPM 2 | plain lines |
/* XPM2 C */ | XPM 2 | C strings |
; XPM2 Lisp | XPM 2 | Lisp strings |
More exactly, libXpm skips the first word and reads the second: XPM
means XPM 3, and XPM2 means XPM 2, with the third word naming the syntax
(none for plain, C or Lisp). Anything else that does not
start with #define is not an XPM file.
XPM 2
XPM 2 has the same four parts as XPM 3, in the same order and with the same
contents: a values line, ncolors colour lines with the keys
c, g, g4, m and s,
height pixel lines, and optional extensions ending XPMENDEXT.
In the plain syntax each part is one line of the file, with no quotes and no commas,
and a line starting with ! is a comment.
! XPM2
4 3 2 1
. c None
# c #000000
.##.
####
.##.
A colour line’s first cpp characters are its pixel code, whatever they
are, exactly as in XPM 3. The C and Lisp syntaxes put
each line in double quotes, C separating them with commas and Lisp with new lines
inside (setq name '( … )).
XPM 1
An XPM 1 file starts with a define whose name ends in _format, then
four more defines, in any order, each exactly once:
| Define suffix | Meaning |
|---|---|
_format | first; marks the file as XPM 1 (the value, 1, is not checked) |
_width | the width in pixels |
_height | the height in pixels |
_ncolors | the number of colours |
_chars_per_pixel | characters per pixel |
Then come two arrays of strings. In the colours array each colour is two strings:
its pixel code, then its colour as a name or # RGB value. There are no
keys; the colour is used as the c colour. The pixels array has one string
per row, as in XPM 3. XPM 1 has no hotspot and no extensions.
#define dot_format 1
#define dot_width 4
#define dot_height 3
#define dot_ncolors 2
#define dot_chars_per_pixel 1
static char *dot_colors[] = {
".", "white",
"#", "black"
};
static char *dot_pixels[] = {
".##.",
"####",
".##."
};