Westwood CMP Format

From ModdingWiki
Jump to navigation Jump to search
Westwood CMP Format
Westwood CMP Format.png
Format typeImage
HardwareEGA
Colour depth4-bit, 8-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 or 8-bit 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. On type 4, it is three bytes less than the full size.
UINT8 Type File type. Determines the bits per pixel and the compression scheme? See the list below.

For types 3 and 6, this header is followed by another UINT16LE that indicate the length of the uncompressed data. This should always be 64000.

The image data follows immediately after this header.

Image data

The image data can be in different formats, depending on the Type in the header:

Type Colour depth Compression
1 4-bit Westwood RLE (horizontal). Reads the extended 16-bit integer repeat values as little-endian.
2 4-bit Westwood RLE (vertical). Reads the extended 16-bit integer repeat values as little-endian.
3 8-bit Westwood LZW-12
4 8-bit Westwood RLE (horizontal). Reads the extended 16-bit integer repeat values as big-endian.
5 - Unknown, probably unused. (In DragonStrike, any value besides 3, 4 and 6 seems to default to loading as type 4)
6 8-bit Westwood LZW-14

If the type is "2", the decompressed bytes should be painted onto the image per column. Do note that that type denotes a 4-bit image, so each such column is two pixels wide.

To handle this type, 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.