Zone 66 Tileset Format
This file format is used by Zone 66 to store tiles used for drawing maps, among other things.
There is no signature, however careful processing of the header can be used to check whether the file is valid (e.g. no tiles are stored past the end of the file, the first tile's offset is always zero, etc.)
Each tileset begins with the following header.
|UINT32LE||count||Number of images in the file|
|UINT32LE[count]||offsets||Array of file offsets|
|BYTE||data||Start of first tile's image data|
Each offset is relative to the start of the first tile's data, so the first tile will always have an offset of zero even though it starts some distance into the file.
Each tile begins with its dimensions, followed by the pixel data.
|UINT16LE||width||Width of tile, in pixels|
|UINT16LE||height||Height of tile, in pixels|
The image data is encoded in a type of RLE. Each byte read should perform one of the following actions:
|0xFF||End of image data|
|0xFE||Go to the start of the next row|
|0xFD||Read next byte, then move right that many pixels|
Any pixels skipped over by one of the above jumps should be left black (value 0x00). Each line is always terminated by 0xFE (even if the exact number of pixels to fill the whole line has been read), except the last line which is terminated by 0xFF.
If the byte read isn't in the table above, it is a length of data to read. That many bytes should be read in from the file and each byte treated as the value of the next pixel.
Note: Some files (e.g. maingrfx.z66) write pixels beyond the width of the image, and consequently may overrun a buffer if this situation is not catered for.
This file format was reverse engineered by john_doe. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)