Difference between revisions of "Image Formats"

From UFOpaedia
Jump to: navigation, search
(PCK)
m (See Also)
 
(5 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
==PCK==
 
==PCK==
  
This format stores archives of 32x40 sprites for use in the BattleScape (32x48 in [[BIGOBS.PCK]]). PCK files pair with TAB files like bread and butter. It's possible to have one without the other, but the only case where this is done is with the one-image-per-file BIGOBS entries in the [[UFOGRAPH]] folder (all other PCK files without an accompanying TAB file ''aren't actually using the PCK format at all'').<br><br>
+
This format stores archives of 32x40 sprites for use in the BattleScape or 32x48 sprites in [[BIGOBS.PCK]].
 +
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/xFF which signals the end of that sprite's data).<br><br>
  
The TAB file is a list of file offsets saying where each image begins in the related PCK archive.
+
PCK files pair with TAB files like bread and butter. It's possible to have one without the other, but the only case where this is done is with the one-image-per-file BIGOBS entries in the [[UFOGRAPH]] folder (all other PCK files without an accompanying TAB file ''aren't actually using the PCK format at all'').<br><br>
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. <i>(Apocalypse uses TFTD's 4-byte TAB's but a version of PCK images currently not documented here).</i><br><br>
 
  
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.<br><br>
+
The TAB file is a list of file offsets saying where each image begins in the related PCK archive. 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. <i>(Apocalypse uses TFTD's 4-byte TAB's, but a [[Image_Formats_(Apocalypse)#PCK|different version]] of the PCK images documented here).</i><br><br>
  
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).
+
When rendering the BattleScape the engine gets the [[MCD]] index from the [[MAP.DAT]] data, in the [[MCD]] data it looks up the TAB index + current animation cycle(0-8), in the TAB data it looks up the offset where to start reading PCK data, it reads PCK data sequentially drawing the pixels on a buffer until it reads the 255/xFF.<br><br>
  
 
==SCR & DAT==
 
==SCR & DAT==
Line 38: Line 38:
 
To decompress, read a byte and call it "a".<br><br>
 
To decompress, read a byte and call it "a".<br><br>
  
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.<br><br>
+
If "a" is 129 or greater, then draw 257-a pixels of the next byte; otherwise, read a+1 bytes from the file and draw those colors sequentially.<br><br>
  
 
Rinse and repeat until EOF.<br><br>
 
Rinse and repeat until EOF.<br><br>
Line 52: Line 52:
 
==See Also==
 
==See Also==
 
*[[PALETTES.DAT]]
 
*[[PALETTES.DAT]]
 +
*[[Image Formats (Apocalypse)]]
  
 
[[Category:Game Files]]
 
[[Category:Game Files]]
 +
[[Category:Enemy Unknown/UFO Defense]]
 +
[[Category:TFTD]]

Latest revision as of 06:43, 23 July 2013

Introduction

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).

PCK

This format stores archives of 32x40 sprites for use in the BattleScape or 32x48 sprites in BIGOBS.PCK. 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/xFF which signals the end of that sprite's data).

PCK files pair with TAB files like bread and butter. It's possible to have one without the other, but the only case where this is done is with the one-image-per-file BIGOBS entries in the UFOGRAPH folder (all other PCK files without an accompanying TAB file aren't actually using the PCK format at all).

The TAB file is a list of file offsets saying where each image begins in the related PCK archive. 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 different version of the PCK images documented here).

When rendering the BattleScape the engine gets the MCD index from the MAP.DAT data, in the MCD data it looks up the TAB index + current animation cycle(0-8), in the TAB data it looks up the offset where to start reading PCK data, it reads PCK data sequentially drawing the pixels on a buffer until it reads the 255/xFF.

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.

SPK

Another 320(pixels wide) x 200(pixels high) 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.

BDY

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+1 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).

TGA

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.

http://en.wikipedia.org/wiki/Truevision_TGA

See Also