| X PixMap | |
|---|---|
Sometext editors, for examplegvim, can display xpm images in graphical form. | |
| Filename extension | .xpm |
| Internet media type | image/x-xpixmap[1] |
| Developed by | BULL Research |
| Type of format | Image file formats |
| Extended from | XBM |
| Open format? | yes |
X PixMap (XPM) is animage file format used by theX Window System, created in 1989 by Daniel Dardailler and Colas Nahaboo working atBull Research Center atSophia Antipolis, France, and later enhanced by Arnaud Le Hors.[2][3]
It is intended primarily for creatingiconpixmaps, and supportstransparent pixels. Derived from the earlierXBM syntax, it is aplain text file in the XPM2 format or of aC programming language syntax, which can be included in a C program file.[2]
The first (1989) XPM format is relatively similar to the XBM format.[a] Compared to XBM, it uses additional macro definitions and variables for indexed colors, and replaces bits with characters for describing the image. The following is a black-and-white image in the 1989 XPM format.
#define XFACE_format 1#define XFACE_width 48#define XFACE_height 48#define XFACE_ncolors 2#define XFACE_chars_per_pixel 1staticchar*XFACE_colors[]={"a","#ffffff","b","#000000"};staticchar*XFACE_pixels[]={"abaabaababaaabaabababaabaabaababaabaaababaabaaab",// and so on for 48 rows with 48 pixels
XPM2 (1990) simplifies the format by removing allC code.[b][c] The structure is simplified to
! XPM2<Values><Colors><Pixels><Optional Extensions>
#define statements.The above file, with width 48, height 4, 2 colors, and 1 character per pixel, becomes:
! XPM248 4 2 1a c #FFFFFFb c #000000abaabaababaaabaabababaabaabaababaabaaababaabaaababaabaababaaabaabababaabaabaababaabaaababaabaaababaabaababaaabaabababaabaabaababaabaaababaabaaababaabaababaaabaabababaabaabaababaabaaababaabaaab
In addition to hexcodes, the colors can be any of theX11 color names. In addition,None indicates transparency.[4][5]
The "symbolic" feature permits adjusting colors depending on the context where they are used. Code such ass border c blue could be adjusted on a blue background.
One tool is known to use onlya top for 16 colors, switching toaa up todp for 64 colors, but still reading single character encodings for 64 colors; compareBase64.
With more colors the codes use more characters, e.g.aa up topp for 16 × 16 = 256 colors. This is less useful for text editors, because a stringab could be actually the middle of two adjacent pixelsdabc. Spaces are allowed as color code, but might be a bad idea depending on the used text editor. Without control codes, backslash, and quote (needed in XPM1 and XPM3) 128 − 33 − 2 = 93ASCII characters are available for single character color codes.
Simplified example: 90 US-ASCII characters could be arranged into nine non-overlapping sets of 10 characters. Thus unambiguous strings of nine characters could set the color of each pixel by its XPM palette index with up to 109 =1000000000 colors (compare toGIF, which supports only 256).
For XPM2 it is clear how many lines belong to the image – two header lines, the second header line announcing the number of color codes (2 lines in the example above) and rows (height 4 in the example above), e.g. 2 + 2 + 4 = 8 lines.
The current and last format is XPM3 (1991). It re-introduces the C wrapper, but instead of explicitly showing a file's structure, the strings stored are essentially identical to XPM2.
/* XPM */staticchar*XFACE[]={"48 4 2 1","a c #ffffff","b c #000000","abaabaababaaabaabababaabaabaababaabaaababaabaaab","abaabaababaaabaabababaabaabaababaabaaababaabaaab","abaabaababaaabaabababaabaabaababaabaaababaabaaab","abaabaababaaabaabababaabaabaababaabaaababaabaaab"};
If the "values" line contains six instead of four numbers, the additional values indicate the coordinates of a "hotspot", where0 0 is the upper left corner of a box containing the icon and the default. A "hotspot" is used for mouse pointers and similar applications.

The following code displays the same blarg file in theXBM, XPM andPBM formats.
XBM version:
#define test_width 16#define test_height 7staticchartest_bits[]={0x13,0x00,0x15,0x00,0x93,0xcd,0x55,0xa5,0x93,0xc5,0x00,0x80,0x00,0x60};

XPM2 version:
! XPM216 7 2 1* c #000000. c #ffffff**..*...........*.*.*...........**..*..**.**..***.*.*.*.*.*..*.***..*..**.*...**...............*.............**.
XPM3 version:
/* XPM */staticchar*blarg_xpm[]={"16 7 2 1","* c #000000",". c #ffffff","**..*...........","*.*.*...........","**..*..**.**..**","*.*.*.*.*.*..*.*","**..*..**.*...**","...............*",".............**."};
PBM file:
P116 71 1 0 0 1 0 0 0 0 0 0 0 0 0 0 01 0 1 0 1 0 0 0 0 0 0 0 0 0 0 01 1 0 0 1 0 0 1 1 0 1 1 0 0 1 11 0 1 0 1 0 1 0 1 0 1 0 0 1 0 11 1 0 0 1 0 0 1 1 0 1 0 0 0 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
ACDSee,Amaya,CorelDRAW,GIMP,ImageMagick,IrfanView (formats plugin),PaintShop Pro,PMView,Photoshop (plugins), andXnView among others support XPM.[6][7]Gravatar also supports XPM.[8][9]
AnX11 libXpmvulnerability was fixed in 2005,[10] and three more in 2023.[11]
FFmpeg version 3.3 or later can decode XPM.[12]
{{cite book}}:|work= ignored (help)picons are in either monochrome XBM format or color XPM and GIF formats
XPM decoder