# MOZ file format specification

This document describes version 0 of the MOZ file format. MOZ is a compressed tiled image format, made to be compatible with the (uncompressed) MOS format used in Baldur's Gate and related games.

## File structure

The file starts with a header, followed by one or more tiles.

Note: all integers are in msb first (Motorola) order.

### Header format

Offset | Size | Data | Description
--- | --- | --- | ---
0 | 4 | "MOZ0" (0x4D 0x4F 0x5a 0x30) | ID. MOZ for compressed MOS, 0 is the file format version.
4 | 2 | 16-bit unsigned integer | Width of image in the file.
6 | 2 | 16-bit unsigned integer | Height of image in the file.

### Tile structure

Tiles are basically 64x64 pixels except for the tiles at the right and bottom border of the image which are appropriately smaller. Tile data is stored using jpeg compression.

Format | ID | Description
--- | --- | ---
2 | "TIL2" (0x54 0x49 0x4c 0x32) | This is a JPEG compressed tile. The image data is compressed with JPEG (lossy).

#### Tile format 2 structure

Offset | Size | Data | Description
--- | --- | --- | ---
0 | 4 | "TIL2" (0x54 0x49 0x4c 0x32) | This identifies the tile as being stored in format 2.
4 | 2 | 16-bit unsigned integer | Length of the tile data.
6 | see previous | Compressed image | The bitmap is compressed as a 24-bit JPEG image.