Girish Mahajan (Editor)

X PixMap

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Filename extension
  
.xpm

Developed by
  
BULL Research

Extended from
  
XBM

Internet media type
  
image/x‑xpixmap

Type of format
  
Image file formats

Open format?
  
yes

X PixMap

X PixMap (XPM) is an image file format used by the X Window System, created in 1989 by Daniel Dardailler and Colas Nahaboo working at Bull Research Center at Sophia Antipolis, France, and later enhanced by Arnaud Le Hors.

Contents

It is intended primarily for creating icon pixmaps, and supports transparent pixels. Derived from the earlier XBM syntax, it is a plain text file in the XPM2 format or of a C programming language syntax, which can be included in a C program file.

XPM

The XPM format is an array of strings composed of six different sections as follows:

This is a black-and-white image in the first (1989) XPM format.

The values section contains the width, height, number of colors, and number of characters per pixel.

XPM2

XPM2 simplifies the format by removing all C codes. An example:

! XPM248 4 2 1a c #FFFFFFb c #000000abaabaababaaabaabababaabaabaababaabaaababaabaaababaabaababaaabaabababaabaabaababaabaaababaabaaababaabaababaaabaabababaabaabaababaabaaababaabaaababaabaababaaabaabababaabaabaababaabaaababaabaaab

This is an XPM2 file with width 48, height 4, 2 colors, and 1 character per pixel. One tool is known to use only a to p for 16 colors, switching to aa up to dp for 64 colors, but still reading single character encodings for 64 colors; compare Base64.

With more colors the codes use more characters, e.g. aa up to pp for 16 × 16 = 256 colors. This is less useful for text editors, because a string ab could be actually the middle of two adjacent pixels dabc. Spaces are allowed as color code, but might be a bad idea depending on the used text editor. Without control codes, space, and quote (needed in XPM1 and XPM3) 128 − 33 − 2 = 93 ASCII 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 to GIF, 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.

XPM3

The other styles XPM1 and XPM3 are designed to be used as is in C source code, example:

The latter format is XPM3, the common format used for the X Window System since about 1991. The c means "color", it's possible to add m for "monochrome" output, g for "grayscale", and s for "symbolic", explaining what a defined color is supposed to do.

In addition to the X11 color names the name none indicates transparency.

The "symbolic" feature permits adjusting colors depending on the context where they are used. Code such as s border c blue could be adjusted on a blue background.

If the width, height, colors, and characters per pixel line contains six instead of four numbers, the additional values indicate the coordinates of a "hotspot", 0 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.

Comparison with other formats

The following code displays the same blarg file in the XBM, XPM and PBM formats.

XBM version:

XPM2 version:

! XPM216 7 2 1* c #000000. c #ffffff**..*...........*.*.*...........**..*..**.**..***.*.*.*.*.*..*.***..*..**.*...**...............*.............**.


XPM3 version:

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

Application support

ACDSee, Amaya, CorelDRAW, GIMP, ImageMagick, IrfanView (formats plugin), PaintShop Pro, Photoshop (plugins), and XnView among others support XPM. Gravatar and picons also support XPM.

An X11 libXpm vulnerability was fixed in 2005.

References

X PixMap Wikipedia


Similar Topics