Friday, October 12, 2007

XPM File format

Intro
XPM or XPixMap is a bitmap format in unix based systems. It is a relatively easy format to understand, XPM files have a format similar to a C source code of a string array.


/* XPM */
static char * var name[] = {
"","","" //etc....
};


The first line is XPM in standard C comments. Second is an array declaration with a valid token as variable name.
The array index 0 [0] : contains the following %d %d %d %d [%d %d] [%d]
which are :
Width,Height,Number of colors, Characters Per Pixel, optional X & Y Hotspots, optional XPM Extension.
The array indexes 1-> number of colors indicates the color section.
The strings in these section take the following format :
%s %s %s
The first contains the characters that represent the pixels. The number of characters used to represent a pixel is given by Characters Per Pixel field in array[0].
The second string represents control characters that defines what the following field is about.
switch(control character)
{
case 'm' : Mono color
case 's' : Symbolic name
case 'c' : Color value
case 'g4': 4 Level Gray Scale
case 'g' : Grayscale
}

the third string is then
a color name eg: black
a # followed by RGB Hex
a % followed by HSV Hex
a symbolic name
a "None" indicating a transparent.

The rest of the section contains the actual pixels. With each (Character Per Pixel) representing a pixel on the screen. Each string is width pixels long and there will be height number of strings.

There might be an optional XPM Extension following the pixels.

Examples:

/* XPM */
static char * plaid[] =
{
/* plaid pixmap */
/* width height ncolors chars_per_pixel */
"22 22 4 2 0 0 XPMEXT",
/* colors */
" c red m white s light_color",
"Y c green m black s ines_in_mix",
"+ c yellow m white s lines_in_dark ",
"x m black s dark_color ",
/* pixels */
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
"Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
"x x x x x x x x x x x x x x x x x x x x x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
"XPMEXT ext1 data1",
"XPMEXT ext2",
"data2_1",
"data2_2",
"XPMEXT ext3",
"data3",
"XPMEXT",
"data4",
"XPMENDEXT"
};

Another one :

/* XPM */
static char * example_xpm[] = {
"24 20 3 1",
" c None",
". c #0000FF",
"+ c #FF0000",
" ",
" .. ",
" .... ",
" ......++++++++ ",
" .........+++++++ ",
" ..........+++++++ ",
" ............++++++ ",
" .............++++++ ",
" ..............++++ ",
" +.............+++ ",
" ++.............++ ",
" +++.............+ ",
" +++++............. ",
" ++++++.............. ",
" ++++++++............ ",
" +++++++++........... ",
" +++++++++......... ",
" ++++++++++....... ",
" ++++++++++..... ",
" +++++++++ ... "};


Thats all
for a Hi Fi version
refer this.

0 comments: