Electronic Arts TQI

From MultimediaWiki
Revision as of 22:12, 5 February 2009 by Multimedia Mike (talk | contribs) (→‎Macroblock Coding: properly wikify scan table image)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Texture Quantized Image (TQI) is a video codec used by some Electronic Arts games for the PC. The format is an evolution of the TGQ codec, and draws heavily from MPEG-1. The TQI acronym is defined within the EA Gimmex decoder library, which is provided with some games.

Chunk Types

The codec payload has been observed in the TGQs and pQGT chunk types. See Electronic Arts Formats for file format description. The ordering of multibyte values varies, but is optimised for the target platform.

Frame Description

Each pIQT chunk represents one video frame, and frame rate is fixed to 15fps. Each frame is divided into 16x16 pixel macroblocks, with each macroblock further divided into with four 8x8 luma and two half-resolution 8x8 chroma blocks. Standard MPEG block ordering is used.

The frame begins with an eight byte header, and is identical to the TGQ header. Immediately following the header is a bitstream containing macroblock data. Symbols within the bitstream are encoded using 32-bit little-endian most-to-least-significant bit packing. <FIXME: explain bit packing>

Offset   Data_type   Name         Description
0x0000   u16         width   	    image width (pixels)
0x0002   u16         height       image height (pixels)
0x0004   u8          quantizer    frame quantizer
0x0005   3 x u8      unknown      always zero
for each vertical macroblock
   for each horizontal macroblock

Macroblock Coding

Macroblocks are encoded using the MPEG-1 DC delta and AC run-length VLC techniques. The RLVLC table uses different run and coefficient values, but retains an identical Huffman tree. Coefficients are ordered using the EA zigzag scan pattern:

Ea tgq zigzag.png

Dequantization is performed by multiplying the coefficients by a dequantization table. This table is calculated for each frame using the frame quantizer.

 A = (107.5 - frame_quant) * 0.625
 dequant_table[0] = base_table[0]*base_table[0]
 for i equals 1 through 63
   dequant_table[i] = (base_table[i]*base_table2[i]*A + 4) / 8
 where base_table is defined in the TGQ description,
 and base_table2[64] = {
    8, 16, 19, 22, 26, 27, 29, 34,
   16, 16, 22, 24, 27, 29, 34, 37,
   19, 22, 26, 27, 29, 34, 34, 38,
   22, 22, 26, 27, 29, 34, 37, 40,
   22, 26, 27, 29, 32, 35, 40, 48,
   26, 27, 29, 32, 35, 40, 48, 58,
   26, 27, 29, 34, 38, 46, 56, 69,
   27, 29, 35, 38, 46, 56, 69, 83,

Inverse DCT and Clipping

An IDCT-based algorithm is applied to each block. <FIXME: hyperlink to implementation>. The resulting values are clipped to 0, 255 to give 8-bit luma and chroma pixel levels.

Games Using TGQ

See Electronic Arts Formats for full listing.