Plexdata.Utilities.XPixMapper 1.0.0

dotnet add package Plexdata.Utilities.XPixMapper --version 1.0.0                
NuGet\Install-Package Plexdata.Utilities.XPixMapper -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plexdata.Utilities.XPixMapper" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plexdata.Utilities.XPixMapper --version 1.0.0                
#r "nuget: Plexdata.Utilities.XPixMapper, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plexdata.Utilities.XPixMapper as a Cake Addin
#addin nuget:?package=Plexdata.Utilities.XPixMapper&version=1.0.0

// Install Plexdata.Utilities.XPixMapper as a Cake Tool
#tool nuget:?package=Plexdata.Utilities.XPixMapper&version=1.0.0                

<p align="center"> <a href="https://github.com/akesseler/xpixmapper/blob/master/LICENSE.md" alt="license"> <img src="https://img.shields.io/github/license/akesseler/xpixmapper.svg" /> </a> <a href="https://github.com/akesseler/xpixmapper/releases/latest" alt="latest"> <img src="https://img.shields.io/github/release/akesseler/xpixmapper.svg" /> </a> <a href="https://github.com/akesseler/xpixmapper/archive/master.zip" alt="master"> <img src="https://img.shields.io/github/languages/code-size/akesseler/xpixmapper.svg" /> </a> </p>

XPixMapper

The Plexdata XPixMapper is a program that is able to convert X11 Pix Maps into images and vise versa.

Features

  • 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.

Licensing

The software has been published under the terms of MIT License.

Downloads

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.

Description

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.

Image Format

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
Colors

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 values c, m, g, g4 or s.
    • 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).

Limitations

  • Grayscaled colors for g or g4 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.
  • An RGB color consisting of six hexadecimal digits is expanded to its ARGB representation.
    • A value of #C0C0C0 is expanded to #FFC0C0C0.
  • 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.

Example

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.

Editor

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.

Editor Main Window

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.

Text Editor

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.

Image View

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.

Transfer Buttons

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.

Known Bugs

No bugs known at the moment.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 236 3/31/2024

Initial draft.