The XPM (X Pixmap) file format is a C declaration of a char * array.

The first array element is the header string. It contains 4 integers. Width, height, number of colors, and bytes per point.

After the header are the colors. "%s\tc %s", where %s is the color's ASCII mapping, \t is a tab character, and the second %s is the actual color (#RRGGBB hex, or "None" for transparency) Each color has its own array element.

After the colors is the pixmap itself. Each line is its own string. Colors are mapped to ASCII using the table declared above. so you can #include "somepixmap.xpm" and parse it quite easily. There are also some things like "XPM extensions" and Xlib resource-configurable color scheming, but I don't know anything about those. As such, there may be string-based color values that vary with configuration (ex: "red", rather than rather static RGB values), and there also may be an XPM extension string or two at the end of the header, and after the pixmap data. Thus, it's probably not a good idea to write an XPM parser based only on this information: use Xlib/GDK's, etc., unless you want to break specifcations with your own cross-platform implementation. (as I did during a project at the time of this writing)

Log in or registerto write something here or to contact authors.