X PixMap

from Wikipedia, the free encyclopedia
X PixMap
File extension : .xpm
MIME type : image / x-xpixmap, image / x-xpm
Developed by: Daniel Dardailler and Colas Nahaboo
Initial release: 1989
Type: Raster graphics


X PixMap ( XPM ) is an ASCII text format for displaying raster graphics , mainly icons .

The first version of XPM dates back to 1989 and was developed by Daniel Dardailler and Colas Nahaboo (also author of the window manager GWM for the X Window System ), who both worked at INRIA in France . The format was later expanded by Arnaud Le Hors . The intention behind the format is to display colored icons on the computer. The structure of the data format is simple and based on the older monochrome XBM format. The graphics consist of pure text files; they can be edited with a simple text editor and, like XBM files, directly integrated in C source code.

example

The following example demonstrates the syntax of the XPM format using a red octagon on a transparent background that is covered by a blue crossbar.

XPM source code Resulting image
/* XPM */
static char *XPM_example[] = {
"24 20 3 1 12 10 XPMEXT",
"  c None",
". c #0000FF",
"+ c #FF0000",
"                        ",
"    ..                  ",
"   ....                 ",
"  ......++++++++        ",
" .........+++++++       ",
" ..........+++++++      ",
" ............++++++     ",
" .............++++++    ",
"  ..............++++    ",
"   +.............+++    ",
"   ++.............++    ",
"   +++.............+    ",
"   +++++.............   ",
"   ++++++.............. ",
"   ++++++++............ ",
"   +++++++++........... ",
"    +++++++++.........  ",
"     ++++++++++.......  ",
"      ++++++++++.....   ",
"       +++++++++ ...    ",
"XPMEXT author Anonymous",
"XPMEXT address",
"Beispielweg 42a",
"0815 Beispielstadt",
"LUMMERLAND",
"mailto:anonymous@beispielstadt.lum",
"XPMENDEXT"
};
XPM example.png

Format description

An XPM file consists of seven parts:

  1. Header line
  2. Declaration line ("Declaration and Beginning of Assignment line")
  3. "Values"
  4. Colors (English "cColors")
  5. Pixels
  6. Extensions (English "extensions")
  7. End of Assignment

The format has been defined so that an XPM file is always valid C source code. This means that XPM files can be #includeintegrated directly into C programs via directives.

Since most programs that process XPM files do not have fully-fledged parsers for C source code, you should strictly adhere to the format described in the format specification when creating XPM files.

The lines following the declaration line each consist of C character string constants. This means that their content is enclosed in ASCII quotation marks and separated by commas.

File header

The header consists of a C comment /* XPM */. This serves as a magic number to recognize XPM files.

Declaration line

The next line is the so-called declaration line, which represents a variable declaration in C. The variable name can be anything; it must be a valid C identifier. Usually the name of the image file is used for this:

static char* bildname[] = {

Values ​​line

The value line contains four or six decimal numbers with the following meanings:

  1. Width of the image (in pixels)
  2. Height of the image (in pixels)
  3. Number of colors in the picture
  4. Number of characters per pixel value
  5. (X position of the "hotspot")
  6. (Y position of the "hotspot")

The last two values ​​indicate the position of a so-called “hotspot”. With mouse cursors, for example, this is the point to which the mouse arrow “points”. This value is not required for normal images and can be omitted.

Has the XPM file extensions (Engl. Extensions ), the value line following the last number of the word XPMEXT.

Color definitions

This is followed by several lines, each defining a color in the image. The number of these color definitions is shown in the third value in the value line.

Each color definition consists of a character code. The length of the character code is given in the fourth value of the value line. A blank is followed by one or more color definitions that assign a color to the character code. As a result of the original purpose of XPM as a file format for icons, different color definitions can be specified for different types of display. This has the advantage that the display can be optimized for different color depths and a black and white display does not have to be calculated from a color display.

The following display types are supported:

c : colored
g4 : four levels of gray
g : More than four levels of gray
m : monochrome (black and white)
s : Symbolic (this means that a color can have a symbolic value, such as "background" or "foreground". The evaluation of this symbol information depends on the program used)

This information is then followed by the actual color definition. This can consist of a symbolic name (eg “white”, “red”), a color in the RGB color space as a hexadecimal color definition ( #RRGGBB) or in the HSV color space ( %HHSSVV). If a color is to be marked as "transparent", the color Nonemust be set to.

Example:

"A c red    m black g gray50 s foreground",
"B c yellow m white g gray80 s background",
"# c black  m black g gray10 s border",

Image data

The image data follow the color definitions. These are stored line by line from top to bottom, in one line from left to right. Each line of the image is saved in a text line in the XPM file. One or more characters are used for each pixel, depending on the value specified above. This notation means that simple images can already be recognized in the source code, see ASCII-Art .

Extensions

If the presence of extensions has been indicated in the value line, extension lines follow the image data, which always have the following format:

  • Single line extension data:
"XPMEXT extension_name extension_value"
  • Multi-line extension data:
"XPMEXT extension_name",
"data",
...

It is not specified how the end of multiline extension data is to be marked.

To avoid name collisions, the XPM specification recommends starting the extension name with the company name. However, it leaves open how this should look in detail.

The end of the entire expansion block is indicated by a line that only has the content XPMENDEXT.

End of file

To complete the C declaration, a line with the character string follows at the end of the file };.

Practical limitations

Since most programs that can process XPM files are not complete C parsers, programs that create XPM files should not deviate from this specification, in particular should not format the "source code" in any other way and should not use C comments (except the mandatory header) or similar.

Also, many programs do not understand the complex color definitions, but only master one type of display or ignore this information completely and only evaluate the color code, and also only understand hexadecimal RGB color codes and Nonefor the transparent color.

The character codes with which a color is coded can consist of any ASCII characters. However, it is advisable to use only letters, numbers and a few "safe" special characters, which can represent around 70 to 80 different colors. If an image contains more colors, character codes consisting of two characters must be used. Although the XPM specification does not stipulate a maximum length of the character codes, one should use a maximum of two characters character codes, which allows up to 80 · 80 = 6400 colors, since some programs otherwise cannot read the XPM file. Some programs also refuse to read more than 256 color definitions, or they generate a color table with a maximum of 256 colors when saving, although the XPM format allows larger color tables.

The XPM specification does not provide any information about what should be in the extension lines; it does not define any extensions. They are therefore practically not used and most programs that do not use libxpm to read XPM files do not understand them either.

Individual evidence

  1. ^ Arnaud Le Hors: XPM Manual: The X PixMap Format. (PS.gz) Chapter 2: The XPM Format. (No longer available online.) September 10, 1996, formerly in the original ; accessed on February 21, 2012 (English, Version: 3.4i).  ( Page no longer available , search in web archivesInfo: The link was automatically marked as defective. Please check the link according to the instructions and then remove this notice.@1@ 2Template: Dead Link / ftp.x.org