Tes2Mod:Image formats/IMG

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   to compress the actual pixel data, decoding the described image can require additional work for some IMG files.  

ImgHeader


Compression Enumeration


Reading Image Data
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.  

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

RleCompressed
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   encoded as  (   + 127 ) , which places a maximum   of compressed runs at 128.  Uncompressed runs have their   encoded as  (   - 1 ) , and since they must be distinguishable from compressed runs, this places a maximum   of uncompressed runs also at 128 bytes because any value greater than 127 would be interpreted as a compressed run.  These facts imply any   value of 255 (0xff) is an invalid   value.  

The algorithm employed by Daggerfall then simply becomes a matter of reading a   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 (   - 127 ) times; otherwise the next (   + 1 ) bytes are to be copied to the output buffer.  This is to continue until   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 files
There are a number of exceptions to the IMG format.  

Empty IMG files
;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 files
;FRAM00I0.IMG
;TALK00I0.IMG
: These 2 files each report an undefined (0x0800) Compression value.  These files are decoded as if they were Uncompressed.  

RCI files
;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 files
;CHGN00I0.IMG
;DIE_00I0.IMG
;PICK02I0.IMG
;PICK03I0.IMG
;PRIS00I0.IMG
;TITL00I0.IMG
: These are actually Palettized RCI Files, containing one image each.