Open main menu

UESPWiki β

Daggerfall Mod:Image formats/IMG

< Mod / Daggerfall: Daggerfall Mod: File Formats: Image formats

IMG files each contain a single ImgFile structure. An ImgFile structure (defined below) consists of an ImgHeader structure immediately followed by a PixelData structure (an array of UInt8 values). The length of the PixelData is declared by the ImgHeader.PixelDataLength value. Since IMG files make use of an Rle to compress the actual pixel data, decoding the described image can require additional work for some IMG files.

ImgHeaderEdit

ImgHeader Structure
Offset Type Name Description
0-1 Int16 XOffset This is used by the Daggerfall rendering engine to display the image at the appropriate position on the screen.
2-3 Int16 YOffset This is used by the Daggerfall rendering engine to display the image at the appropriate position on the screen.
4-5 Int16 Width The width of the image, in pixels.
6-7 Int16 Height The height of the image, in pixels.
8-9 Compression (UInt16) Compression This field is an enumeration, described below.
10-11 Int16 PixelDataLength This is the number of bytes contained in the PixelData structure immediately following this header. If the Compression flag indicates Uncompressed, then the PixelDataLength must be equal to Width × Height; otherwise the PixelDataLength will be less-than-or-equal-to Width × Height.

Compression EnumerationEdit

Compression Enumeration
Value Name Definition
0x0000 Uncompressed Image is not compressed
0x0002 RleCompressed Image is Rle Compressed
0x0108 ImageRle This is a special type of compression only valid in texture files.
0x1108 RecordRle This is a special type of compression only valid in texture files.

Reading Image DataEdit

In essence, one simply reads a byte array of DataLength long from the file. Decoding the retrieved data is a different matter, dependent on the Compression field's value.

UncompressedEdit

This is performed identically to the procedure used for RCI files.

RleCompressedEdit

Decoding RleCompressed data is slightly more complicated, but quite manageable. The generic Run-Length Encoding algorithm is fully described here. The specific algorithm employed in Daggerfall uses single-byte counting, which places an upper-limit on "run" lengths. Compressed runs have their count encoded as ( count + 127 ), which places a maximum count of compressed runs at 128. Uncompressed runs have their count encoded as ( count - 1 ), and since they must be distinguishable from compressed runs, this places a maximum count of uncompressed runs also at 128 bytes because any value greater than 127 would be interpreted as a compressed run. These facts imply any count value of 255 (0xff) is an invalid count value.

The algorithm employed by Daggerfall then simply becomes a matter of reading a count value and then reading one ore more bytes of data. If the count value is greater than 127 (0x7f), then the next byte is to be repeated in the output buffer ( count - 127 ) times; otherwise the next ( count + 1 ) bytes are to be copied to the output buffer. This is to continue until ( ImgHeader.Width * ImgHeader.Height ) bytes have been copied to the output buffer. At that point the data is fully decompressed, and can be displayed as per RCI files.

Special IMG filesEdit

There are a number of exceptions to the IMG format.

Empty IMG filesEdit

FMAP0I00.IMG
FMAP0I01.IMG
FMAP0I16.IMG
These 12 byte files each contain nothing but an empty (0x00's) ImgHeader structure and no PixelData.

Invalid Compression Value filesEdit

FRAM00I0.IMG
TALK00I0.IMG
These 2 files each report an undefined (0x0800) Compression value. These files are decoded as if they were Uncompressed.

RCI filesEdit

AMAP00I0.IMG
BANK01I1.IMG
BANK01I2.IMG
BIOG00I0.IMG
BOOK00I0.IMG
BUTN01I0.IMG
CHAR00I0.IMG
CHAR01I0.IMG
CHAR02I0.IMG
CHAR03I0.IMG
CHAR04I0.IMG
CHAR05I0.IMG
CNFG00I0.IMG
COMPASS.IMG
CORT01I0.IMG
CUST00I0.IMG
DANK02I0.IMG
DESERT.IMG
GRAD01I0.IMG
ICON00I0.IMG
INFO00I0.IMG
INFO01I0.IMG
INVE00I0.IMG
INVE01I0.IMG
INVE02I0.IMG
INVE04I0.IMG
INVE05I0.IMG
INVE0FI0.IMG
ITEM00I0.IMG
ITEM01I0.IMG
LGBK00I0.IMG
LOAD00I0.IMG
MAP100I0.IMG
MASK00I0.IMG
MASK01I0.IMG
MASK02I0.IMG
MASK04I0.IMG
MASK05I0.IMG
MASK06I0.IMG
NITE00I0.IMG
NITE01I0.IMG
NITE02I0.IMG
NITE03I0.IMG
PICK01I0.IMG
SCRL04I0.IMG
SCRL05I0.IMG
SCRL07I0.IMG
SCRL08I0.IMG
SCRL09I0.IMG
SCRL10I0.IMG
SCRL11I0.IMG
SCRL12I0.IMG
SCRL13I0.IMG
SCRL14I0.IMG
TALK01I0.IMG
TALK02I0.IMG
TALK03I0.IMG
TAMRIEL.IMG
TAMRIEL2.IMG
TMAP00I0.IMG
TRAV01I0.IMG
TRAV01I1.IMG
TRAV0I00.IMG
TRAV0I01.IMG
TRAV0I03.IMG
These are actually RCI Files, containing one image each.

Palettized RCI filesEdit

CHGN00I0.IMG
DIE_00I0.IMG
PICK02I0.IMG
PICK03I0.IMG
PRIS00I0.IMG
TITL00I0.IMG
These are actually Palettized RCI Files, containing one image each.