Introduction
An .xp file is an image from
REXPaint, the free ASCII-art editor
from Grid Sage Games. REXPaint was made for drawing the art and maps of roguelike games,
whose screens are grids of text characters, and many such games read .xp
files directly.
The picture is not stored as pixels. It is a grid of cells, and each cell holds one glyph from a 256-glyph code page 437 font, a foreground colour and a background colour. An image can have up to nine layers, drawn one over another, and a cell on any layer can be transparent.
Structure
The whole file is gzip-compressed: REXPaint writes it through zlib’s gzip stream, so it
starts with the gzip bytes 1F 8B. Decompressed, the data is a version number,
the number of layers, and then each layer: its width and height in cells, and then every
cell, column by column.
0Gzip header1F 8B 08, flags, time, operating system10 bytes or more10Deflate data the decompressed data below, compressedvaries…Gzip trailer CRC-32 and size of the decompressed data8 bytes
Numbers in the decompressed data are 32 bits, little-endian. Colours are three bytes: red, green and blue.
0Version a negative number; REXPaint writes −14 bytes4Layer count 1 to 94 bytes8Layer 1 size width and height in cells8 bytes16Layer 1 cells width × height cells, column by column10 bytes a cell…Layer 2 and the rest size and cells, the same wayvaries
0Code the glyph’s number in the font4 bytes4Foreground red, green, blue3 bytes7Background red, green, blue; 255, 0, 255 is transparent3 bytes
An .xp file dropped on any page of this site opens in the explorer. It
shows the gzip wrapper and its Deflate blocks, draws each layer and all layers together,
gives the text of each layer, and lists the glyphs and colours used. The decompressed data
opens as a file of its own, where every cell of the pictures leads to its 10 bytes. The
explorer draws codes 0 to 255 with the IBM PC’s 8 × 8 code page 437 font as a stand-in
for REXPaint’s own fonts, so its pictures differ in detail, and says so beside the
picture. A code above 255 comes from a custom font, whose bitmap is the user’s and not in
the file: it is drawn as a box showing the code, and hover gives the number and
“glyph from the file’s custom font”.
Versions
Versions of REXPaint before release R9 wrote no version number: their files start straight with the layer count. Later versions store the version as a negative number, so that a reader can tell the two apart by the sign of the first number. The layout after that is the same. The manual does not list other changes, and a reader can ignore the version otherwise.
The value REXPaint writes is −1: the REXSpeeder library, written for REXPaint 1.03, writes −1 and says so in its source. No other value is documented. The explorer reads a different negative number as the same layout and marks it as not known.
Files made from an image
REXPaint exports an image to other formats. These do not store the layers apart: they
merge the visible layers into one image first. They are separate files, made from a .xp and not part of one: nothing in an
.xp refers to them, so the .xp viewer does not open them.
Each opens under its own extension: .png, .csv,
.xml and .txt in the general viewers for those formats. No
explorer reads REXPaint's .ans, BBCode, XPM or C:DDA exports as pictures
of cells.
.png– the image as pixels, drawn with the chosen font.txt– the glyphs only, no colours; UTF-8 by default, with no-break spaces, or plain ASCII whentxtOutputUTF8=0is set in REXPaint.cfg.csv– a header line, then a line a cell: X, Y, ASCII code as an integer, foreground and background as hex.xml–<data>holding a<row>a row, each holding<cell>s with<ascii>,<fgd>and<bkg>.ans– ANSI art, with restrictions (manual, Appendix D); BBCode, XPM and C:DDA exports also exist
REXPaint can also build an .xp from a plain text file (command line
option -txt2xp), using black glyphs 0 to 127 on white.
In the explorer
The picture of all layers can be zoomed and moved, and moving the pointer over it says
which cell it is on: for each layer, the glyph code, the foreground and background
colours and the offset of the cell’s 10 bytes in the decompressed data. In the
options bar a checkbox for each layer hides it from the picture of all layers and
from its text, and a choice says whether a place transparent on every layer is black
(as REXPaint draws it) or clear. A file that is not an .xp image, such as
a text file with that name, is shown with the reason it was turned down.
In this reference
- Compression and header – the gzip wrapper, the version number and the layer count
- Layers and cells – each layer’s size, the 10 bytes of a cell, column order and transparency
- Glyphs and drawing – code page 437, and how the layers are drawn over one another
Not described
The pages follow the REXPaint manual (Appendix B) and the open-source readers listed under Links, and the explorer was run on 14 real images from their test files. These parts are not covered.
Not a gap: the files REXPaint exports from an image (.csv, .xml,
.txt, .ans, .png) are separate formats, not
parts of a .xp file, and the layers, glyphs and colours of the
.xp itself are all shown.
Unknown
- Reference and viewer: versions other than −1. The manual calls the value private to REXPaint and no reader documents another, so the explorer reads any negative version as the −1 layout and flags it.
Links
Software
- REXPaint – Grid Sage Games’ free ASCII-art editor, which makes and opens .xp images (Windows)
Developers
- REXSpeeder – library that loads and saves .xp images (C++)
- rexpaint – crate that reads and writes .xp images (Rust)
Reference
- REXPaint manual – Appendix B describes the .xp format, and Appendix C lists libraries for many languages