Expand description
Decoding of XPM Images
XPM (X PixMap) Format is a plain text image format, originally designed to store cursor and icon data. XPM images are valid C code.
(This format is obsolete and nobody should make new images in it. If you need to
include an image in a C program, use xxd -i or #embed.)
The XPM format allows for encoding an image which can be expressed differently depending on the display capabilities (X11 visual), providing specialized versions for color, grayscale, black and white, etc. output in the same image. In practice, most XPM images created after the mid 1990s only provide a variant for the color visual. As a result, this decoder implementation only outputs the color version of the input image.
A number of features of the original libXpm are not supported (because they appear to very rarely have been used):
- XPMEXT extensions
- HSV color specifications
- Output for non-color visuals
- More relaxed header comment parsing (allowing different whitespace around
XPMin/* XPM */) - Loading with a different color table
This is a somewhat strict decoder and will reject many broken image files, including:
- those using the XPM2 header or
static char ** name = {array string - those missing a trailing “,” on lines, or which use “;” instead of “,”
- those with color data lines that are too long
- those which have content after the final semicolon which is not a C comment
Note: color values for the X11 color name table were changed for the X11R4 release in Dec 1989; since then there have only been additions.
This overlaps with XPM version development: XPMv1 in Feb 1989, XPMv2 in Feb-August 1990, and XPMv3 in April 1991. Therefore, if you do see an ancient XPMv1 or XPMv2 file somewhere, it may be using different color name values.
This decoder uses the X11 color name table as of X11R6 (May 1994); the only additions since then, in 2014 to add some CSS color names, are not included, to preserve compatibility with other XPM parsers.
§Related Links
- https://www.x.org/docs/XPM/xpm.pdf - XPM Manual version 3.4i, which specifies the format
- https://web.archive.org/web/20060702022929/http://koala.ilog.fr/ftp/pub/xpm/xpm-3-paper.ps.gz - XPM Paper
- https://en.wikipedia.org/wiki/X_PixMap - The XPM format on wikipedia
- https://web.archive.org/web/20110513234507/https://www.w3.org/People/danield/xpm_story.html - XPM format history
- https://gitlab.freedesktop.org/xorg/app/rgb/raw/master/rgb.txt - X color names
- https://www.x.org/wiki/X11R4/#index10h4 - Introduction of modern X11 color name table
- https://web.archive.org/web/20070808230118/http://koala.ilog.fr/ftp/pub/xpm/ - more historical XPM material
Structs§
- XpmDecoder
- XPM decoder