XPM (image format)
Encyclopedia
X Pixmap is an image file format
Image file formats
Image file formats are standardized means of organizing and storing digital images. Image files are composed of either pixels, vector data, or a combination of the two. Whatever the format, the files are rasterized to pixels when displayed on most graphic displays...

 used by the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

, created in 1989 by Daniel Dardailler and Colas Nahaboo working at Bull Research Center
Groupe Bull
-External links:* * — Friends, co-workers and former employees of Bull and Honeywell* *...

 at Sophia Antipolis
Sophia Antipolis
Sophia Antipolis is a technology park northwest of Antibes and southwest of Nice, France. Much of the park falls within the commune of Valbonne. Created in 1970-84, it houses primarily companies in the fields of computing, electronics, pharmacology and biotechnology. Several institutions of higher...

, France, and later enhanced by Arnaud Le Hors.

It is intended primarily for creating icon
Icon
An icon is a religious work of art, most commonly a painting, from Eastern Christianity and in certain Eastern Catholic churches...

 pixmaps, and supports transparent color. Derived from the earlier XBM syntax, it is a plain text
Plain text
In computing, plain text is the contents of an ordinary sequential file readable as textual material without much processing, usually opposed to formatted text....

 file of a C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 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:


static char* [] = {




};


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


/* XPM */
static char * XFACE[] = {
/* */
"48 4 2 1",
/* */
"a c #ffffff",
"b c #000000",
/* */
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
"abaabaababaaabaabababaabaabaababaabaaababaabaaab"
};


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

XPM2

XPM2 simplifies the format by removing all C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 idiosyncrasies. An example:


! XPM2
128 128 64 1
z c #f6f6f6
Z c #eeeeee
etc., palette using 1 character codes

@ c #080808
. c #000000
............................................


This is an XPM2 file with width 128, height 128, 64 colors, using one 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
Base64
Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation...

.

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, see links, 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
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

 characters are available for single character color codes.

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 (64 lines in the example above) and rows (height 128 in the example above), e.g. 2+64+128=194 lines.

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

  1. define XFACE_format 1
  2. define XFACE_width 48
  3. define XFACE_height 48
  4. define XFACE_ncolors 2
  5. define XFACE_chars_per_pixel 1

static char *XFACE_colors[] = {
"a", "#ffffff",
"b", "#000000"
};
static char *XFACE_pixels[] = {
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
// and so on for 48 rows with 48 pixels

XPM3

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.

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 XBM, XPM and PGM formats.

XBM version:

  1. define blarg_xbm_width 16
  2. define blarg_xbm_height 7

static char blarg_xbm_bits[] = {
0xec, 0xff, 0xea, 0xff, 0x6c, 0x32, 0xaa,
0x5a, 0x6c, 0x3a, 0xff, 0x7f, 0xff, 0x9f};


XPM version:


/* XPM */
static char * blarg_xpm[] = {
"16 7 2 1",
"* c #000000",
". c #ffffff",
"**..*...........",
"*.*.*...........",
"**..*..**.**..**",
"*.*.*.*.*.*..*.*",
"**..*..**.*...**",
"...............*",
".............**."
}


XPM2 version:


! XPM2
16 7 2 1
  • c #000000

. c #ffffff
    • ..*...........
  • .*.*...........
    • ..*..**.**..**
  • .*.*.*.*.*..*.*
    • ..*..**.*...**

...............*
.............**.


PGM file:

P1
16 7
1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1
1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1
1 1 0 0 1 0 0 1 1 0 1 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0

Application support

The Arena
Arena (web browser)
The Arena browser was an early testbed web browser and web authoring tool for Unix. Originally authored by Dave Raggett in 1993, the browser continued its development at CERN and the World Wide Web Consortium and subsequently by Yggdrasil Computing...

 web browser
Web browser
A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...

 has full support since version 0.3.33 (21 July 1997)
The Agora
Agora (web browser)
Agora was a World Wide Web email browser and was a proof of concept to help people to use the full internet. Agora was an email-based web browser designed for non-graphic terminals and to help people without full access to the internet such as in developing countries or without a permanent internet...

world wide web email browser was also able to handle XPM.

The pixmap editor is a tool to edit and create XPM images graphically.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK