PCX files contain static raster graphics, mostly backgrounds, focus masks and interface elements. They are completely unrelated to ZSoft's PCX format, in both origin and structure. The image can be stored as a raw 24bit BGR bitmap or an indexed bitmap with a palette of up to 256 arbitrary 24bit RGB colors (note the order of color channels), both contiguous, without any word-boundary alignment of scanlines or other such optimizations found in other raster formats. The structure of a PCX file is very simple, with a 12-byte header followed by the bitmap and, if applicable, the palette:
struct h3pcx_color_indexed { uint8_t r; uint8_t g; uint8_t b; }; struct h3pcx_indexed { uint32_t bitmap_size; // equals to width*height - 1 byte per pixel uint32_t width; uint32_t height; uint8_t bitmap[width*height]; h3pcx_color_indexed palette[256]; }; struct h3pcx_color_bgr { uint8_t b; uint8_t g; uint8_t r; }; struct h3pcx_bgr { uint32_t bitmap_size; // equals to 3*width*height - 3 bytes per pixel uint32_t width; uint32_t height; h3pcx_color_bgr bitmap[width*height]; };
The actual image type can be determined easily by checking if width*height or 3*width*height is equal to the bitmap_size field. This might even serve as a file integrity check, if desired.
Indexed PCX images are also used in the DEF files (see HoMM3 DEF animations), but their structure is somewhat different in such case, with a shared palette external to the bitmaps themselves. The meaning of their contents, however, remains the same.