The Plexdata XPixMapper is a program that is able to convert X11 Pix Maps into images and vise versa.
- Conversion of X11 Pix Maps into images.
- Conversion of images into X11 Pix Maps.
- GUI tool to perform conversion.
- Library to include in own projects.
The software has been published under the terms of MIT License.
The latest release can be obtained from https://github.com/akesseler/xpixmapper/releases/latest.
The master branch can be downloaded as ZIP from https://github.com/akesseler/xpixmapper/archive/master.zip.
An X11 Pix Map is a bitmap, defined at the end of the 1980s, that can be put in any source code and are parsed and converted at runtime. The XPM definition was originally made for UNIX operating systems, but why shouldn't it be available on Windows too. The original documentation is part of this project and can found here.
Each X11 Pix Map consists of at least three parts, the header, the color definition and the pixel definition. Additionally, it will be possible to have an extension section, e.g. for copyright statements or other useful information. In fact, each X11 Pix Map just consists of an array of strings. Below please find a C# example of such an X11 Pix Map.
private static readonly String[] xpm = new String[]
{
/* Header */
"16 16 6 1",
/* Colors */
". c None",
"# c Black",
"- c LightBlue",
"* c Yellow",
": c DarkGreen",
"; c Khaki",
/* Pixels */
"................",
"................",
"................",
".##############.",
"#--------------#",
"#--------#-----#",
"#-------#*#----#",
"#----#---#-----#",
"#---#:#-----#--#",
"#--#:::#---#;#-#",
"#-#:::::#-#;;;##",
"##:::::::#;;;;;#",
".##############.",
"................",
"................",
"................"
};
The above example defines an X11 Pix Map with a size of 16x16 pixels, six colors and one character per pixel representation. Hotspot and extensions are not used.
Each X11 Pix Map header consists of a mandatory part and an optional part and follows the definition shown below.
<w> <h> <n> <c> [<x> <y>] [XPMEXT]
Verb | Meaning | Required |
---|---|---|
w |
The width of the X11 Pix Map. | yes |
h |
The height of the X11 Pix Map. | yes |
n |
The number of characters per pixel. | yes |
c |
The number of colors per pixel, actually the row count of the color section. | yes |
x |
The X-offset of the hotspot (e.g. used by a cursor; y is mandatory if x is used). |
no |
y |
The Y-offset of the hotspot (e.g. used by a cursor). | no |
XPMEXT |
An extension is applied at the end. | no |
The color section consists of set of lines, whereby each line defines the pixel name and pairs of color type and color value. Furthermore, each color type and value pair can exist multiple times. Such a color section line follows the format shown as next.
<p> {<k> <c>}+
Verb | Meaning | Required |
---|---|---|
p |
The pixel name. | yes |
k |
The color type. | yes |
c |
The color value. | yes |
p
: The pixel name can consist of any ASCII character, but must have a length of number of characters used per pixel. Furthermore, each pixel name must be unique!k
: Is one of the valuesc
,m
,g
,g4
ors
.c
: Color definition (most used).m
: Monochrom color (could serve as a fallback).g
,g4
: Grayscaled color (see Limitations below).s
: Symbolic color name (see Limitations below).
c
: Represents the color value and can be either an RGB value, or an HSV value, or a Named Color, or a Symbolic Name.- An RGB color value is preceded by a number sign (
#
), e.g.#C0C0C0
. - An HSV color value is preceded by a percent sign (
%
) (see Limitations below). - A Named Color is a string of a known color, but without any white spaces.
- A Symbolic Name is just a string, but without any white spaces (see Limitations below).
- An RGB color value is preceded by a number sign (
Limitations
- Grayscaled colors for
g
org4
are treated the same way, which means only one of both is used internally. - HSV Colors are not supported at the moment and will cause an Exception!
- Symbolic Names can be provided but aren't really used.
- RGB Colors must consist of either three, or six, or eight hexadecimal digits (see Color Treatment below).
- Extensions are supported, but handled a little bit sloppily.
Color Treatment
- An RGB color value of
None
is treated as Transparent color. - An RGB color consisting of three hexadecimal digits is expanded to its ARGB representation.
- A value of
#19C
is expanded to#FF1199CC
.
- A value of
- An RGB color consisting of six hexadecimal digits is expanded to its ARGB representation.
- A value of
#C0C0C0
is expanded to#FFC0C0C0
.
- A value of
- An RGB color consisting of eight hexadecimal digits remains unchanged, which in turn means that
every RGB color implicitly supports the alpha channel.
- A value of
#0A1122BB
is expanded to#0A1122BB
.
- A value of
Code snippet below shows how to create an image using the X11 Pix Map definition from above.
Image image = XPixMapParser.Parse(xpm, XPixMapType.Default);
Following table shows the XPixMapType
values and their meaning.
Value | Meaning |
---|---|
Default |
Creating a colored image is tried. |
BestFit |
Creating an image using first valid color is tried (search order: first c , then g and finally m ). |
Colored |
All colors are taken from c color definition. |
Grayscale |
All colors are taken from g (or g4 ) color definition. |
Monochrome |
All colors are taken from m color definition. |
An editor is also part of this project. This editor is able to create images from X11 Pix Maps and vice versa. See below for an example.
The definition of the X11 Pix Map is entered into the left panel (the Text Editor) and then it
is transferred to the right using button [>>]
.
The other way round, to create an X11 Pix Map from an existing image file, it is possible to
open it using the context menu of the right panel (the Image View). After that button [<<]
is
clicked to convert it into its X11 Pix Map version.
The Text Editor provides a context menu with the functions Open, Save, Copy, Paste, etc. It is also possible to copy an X11 Pix Maps as code snippet for C#, C/C++ as well as for Visual Basic.
The Image View provides a context menu with the functions Open, Save, Copy, Paste, etc. It is also possible to explicitly copy an image as BASE-64 string, as PNG type as well as type of BMP. Furthermore, pasting an image as BASE-64 string is possible as well via context menu.
There are two transfer buttons between the Text Editor and the Image View that can be used to convert an X11 Pix Map into an image or an image into an X11 Pix Map. Both buttons provide a sub-menu that allow to choose a specific color scheme.
No bugs known at the moment.