This is a summary as to how the various image formats in X-Com games work. As UFO/TFTD are palette based games, a common factor is that each image file can be decoded to a set of indexes into those.
(Page contents mostly stolen from Daishiva's site).
This format primarily does service storing multiple 32x40 sprites for use in the BattleScape, however it's occasionally used to store single and/or larger images as well. PCK files pair with TAB files like bread and butter. It's possible to have one without the other, but only in special cases.
The TAB file is a list of file offsets saying where each image begins in the related PCK archive.
NOTE: Some offsets are encoded in 2 bytes while others are encoded in 4. It depends on how many images are in the PCK archive. For TFTD, terrain tab files are 2-byte offsets while all the units are 4-byte; For UFO, every tab file uses 2-byte offsets. (Apocalypse uses TFTD's 4-byte TAB's but a version of PCK images currently not documented here).
Typically images are stored sequentially in their archives, so once you know the offset to an image and the image after that you can then read out "x" number of bytes starting at TAB[i] (where "x" is TAB[i+1]-TAB[i] and "i" is the index of the image you wish to view). UFO will read PCK files even if the TAB indexes are not sequential, though writing them in this manner is not advised as most viewers depend upon this basic rule.
PCK files use RLE encoding to store the images as most of each sprite is (usually) transparent. To decompress, read the first byte and skip down that many rows, then the following algorithm applies: If the byte is 254/xFE, the byte following is the number of transparent pixels. Any other byte is a color index (with the exception of 255/FF which signals the end of that sprite's data).
SCR & DAT
These ones are easy, every byte is an uncompressed index into the game's palette. Typically SCR files are used for 320x200 background images (and often stored in greyscale so they can be re-colored on the fly). DAT files that contain images use the same format, though the line width tends to vary depending on the specific use to which they are to be put.
Another 320x200 image format but using compression, primarily used by UFO for background images (eg inventory screens).
Read a 16-bit unsigned integer, call it "a".
- If "a" is 0xFFFF (65535) then you must read another 16-bit integer, and skip that number*2 pixels.
- If "a" is 0xFFFE (65534) then the next 16-bit integer*2 specifies the number of pixels you are going to draw. Read that number of bytes from the file and draw their indexed color.
- If "a" is 0xFFFD (65533) then you are done. This is always the last code in the file.
Rinse and repeat until EOF.
A TFTD only format which essentially replaced SPK files.
To decompress, read a byte and call it "a".
If "a" is 129 or greater, then draw 257-a pixels of the next byte; otherwise, read "a" bytes from the file and draw those colors sequentially.
Rinse and repeat until EOF.
When encoding each scanline must be represented on it's own and in it's entirety. If a single "a" code directs the decoder to output color values past the end of the current row they'll be discarded (unlike the other formats where it'll automatically jump down to the beginning of the next row and continue to draw).
Screenshots captured using the F12 key are stored in TGA format. Truevision TGA, better known as TARGA format, is a raster graphics file format developed in 1984, enhanced in 1989 (when it was "state of the art", but still in widespread use over 20 years later.