An .xp file is a gzip file. Its data, once decompressed, starts with a
version number and the number of layers. All numbers in the data are 32 bits,
little-endian (low byte first).
Gzip wrapper
REXPaint’s manual says the files are compressed with zlib, as gzip files written through a gzip output stream. So the file is one gzip member (RFC 1952): a header, Deflate data and a trailer. Nothing in the gzip header is particular to REXPaint, and any gzip or zlib library can decompress the file.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 2 | magic | 1F 8B, the gzip signature. |
| 2 | 1 | method | 8, Deflate. |
| 3 | 1 | flags | Which optional fields follow the fixed header. |
| 4 | 4 | time | A modification time, or 0. |
| 8 | 1 | extra flags | How hard the compressor worked. |
| 9 | 1 | operating system | The system the file was written on. |
| 10 | varies | Deflate data | The decompressed data, compressed (after any optional fields). |
| end − 8 | 4 | CRC-32 | The CRC-32 of the decompressed data. |
| end − 4 | 4 | size | The size of the decompressed data. |
The gzip reference describes the header fields and the trailer in full, and its Deflate page the compressed data.
Layout
The decompressed data starts with this header. Files from before REXPaint R9 have no version, so their header is the layer count alone.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | i32 | version | The format version, a negative number. |
| 4 | 4 | u32 | layer count | The number of layers, 1 to 9. |
| 8 | varies | layers | layers | Each layer in turn. |
0VersionFF FF FF FF(−1)4 bytes4Layer count for example02 00 00 00(2)4 bytes8Layers the first layer’s width, height and cells, then the nextvaries
Version
A signed 32-bit number. REXPaint’s manual says it is the internal format version, used
only by REXPaint itself in case the format has to change, and that a reader can ignore
it. It is stored as a negative number. The manual does not give its value; libraries that
read the format, such as the Rust rexpaint crate, expect −1
(FF FF FF FF).
Files from before R9
Versions of REXPaint before release R9 wrote no version number. Their data starts with the layer count, which is always positive. That is why the version is negative: the sign of the first number tells the two kinds of file apart, and REXPaint updates old files when it opens them.
| First number | Meaning | Layers start at |
|---|---|---|
| negative | the version; the layer count follows | 8 |
| positive | the layer count of a file from before R9 | 4 |
Layer count
An unsigned 32-bit number: how many layers follow. Every image has at least one, its base layer, and current versions of REXPaint allow up to nine. The layers follow one another with nothing between them, and the data ends with the last one.