Programming Tips - C/C++: a programmer-friendly graphics format (XPM)

Date: 2008may2 Update: 2025jul5 Domain: graphics Keywords: X Bitmap Q. C/C++: a programmer-friendly graphics format (XPM) A. Most graphics formats are binary. If you open up a JPEG file, for example, in a text editor you can see "JFIF" surrounded but a bunch of noise. But not so with the XPM format! Open up a XPM file and you'll see:
/* XPM */ static char * roundb_xpm[] = { /* width height ncolors cpp [x_hot y_hot] */ "13 13 5 2 7 7", /* colors */ " s none m none c none", ". s topShadowColor m white c lightblue", "X s iconColor1 m black c black", "o s bottomShadowColor m black c #646464646464", "O s selectColor m white c red", /* pixels */ " ", " . . . ", " . . X X X o o ", " . X X X X X X X o ", " . X X X X X X X o ", " . X X X X O X X X X o ", " . X X X O O O X X X o ", " . X X X X O X X X X o ", " . X X X X X X X o ", " . X X X X X X X o ", " o o X X X o o ", " o o o ", " " };
(This example is taken from https://web.archive.org/web/20110513234507/http://www.w3.org/People/danield/xpm_story.html ) It looks like C code and the ball it represents. Now that's what I call programer-friendly! Even though its text its not outragously space-inefficent. That's because it uses a palette. I'd like it if XPM was used more but its not exactly in fashion.