Westwood CMP Format

From ModdingWiki
Jump to navigation Jump to search
Westwood CMP Format
Westwood CMP Format.png
Format typeImage
HardwareEGA
Colour depth4-bit
Minimum size (pixels)320×200
Maximum size (pixels)320×200
PaletteShared
Plane count1
Transparent pixels?Palette-based
Hitmap pixels?No
Games

The CMP Format is an older version of what would later become the CPS format. It is a 4-bit RLE-compressed file which always contains a 320x200 image. It contains no palette.

Like the CPS format, these files tend to be used both for fullscreen 320x200 images, and for collections of sprites.

Note that the .CMP extension is also used by the Lands of Lore SHP format, but that article was named "SHP Format" because the described format is a sprite format, like all other Westwood SHP formats. Both "CMP" and the later "CPS" extensions probably just refer to the file being "compressed".

File format

Header

The file starts with the following header:

Data type Name Description
UINT16LE FileSize File size. This only counts the bytes behind this value, making it two bytes less than the actual file size.
UINT8 CompressionType Compression type. Either 1 for horizontal compression, or 2 for vertical compression.

This header is immediately followed by the compressed data.

Image data

The image data is compressed with the Westwood RLE compression, using little-endian 16-bit values for its large repeat values. If the CompressionType in the header is set to "2", decompressed bytes should be painted onto the image per column. Do note that the image is 4-bit, so each such column is two pixels wide.

To handle CompressionType 2, the game decompresses the data straight into the screen buffer vertically using a separate decompression function. For modern applications, it is probably simpler to swap the rows and columns as post-processing step, since that means both compression types can use the same decompression code.

The vertical compression is consistently used on images where compressing the bytes per column results in a lower file size.