Changes

Jump to navigation Jump to search

PSX/TIM format

2,779 bytes added, 12:44, 4 March 2005
no edit summary
== Introduction ==
A TIM file is a standard image file format for the [[PSX|Sony PlayStation]]. The file structure closely mimics the way textures are managed in the [[PSX/frame buffer|frame buffer]] by the [[PSX/GPU|GPU]]. TIM files are [[little endian]]-based.
 
== File layout ==
A TIM file is made up of three conceptual blocks; the header, the color lookup table (CLUT) and the image data. The CLUT block and the image data block have the same basic layout and are also treated the same way when loading a TIM file into the PlayStation frame buffer. Also, the CLUT block is optional and technically does not need to be present, even when the image data consists of color indices. Such image data is assumed to refer to ''some'' color lookup table, but not necessarily one stored in the same TIM file. In almost all cases though, the CLUT is included in the same TIM file as the image data using it and can thus be assumed to be applicable.
<br/><center>[[Image:PSX_TIM_file_layout.png]]</center><br/>
 
== Header ==
</pre>
The CLP (Color Lookup table Present) flag simply denotes if the CLUT block is present in the TIM file. This flag is typically set when BPP is 00 or 01, and cleared otherwise.
 
== CLUT (color lookup table) ==
<br/><center>[[Image:PSX_TIM_file_clut.png]]</center><br/>
In The length of the CLUT data is always ''width'' &times; ''height'' &times; 2 bytes, precisely the amount of data needed to fill a rectangular area of ''width'' &times; ''height'' pixels in the frame buffer. Also, in the frame buffer CLUTs need to be stored on even multiples of 16 horizontally, but can be stored freely on any row. Typically they are stored directly under the front/back buffers. 
== Image data ==
The image block is structurally identical to the CLUT block and is processed in exactly the same way when loaded into the frame buffer. It starts with a 32-bit word telling the length, in bytes, of the entire image block, then has 4 16-bit values containing the frame buffer positioning information. After that follows the image data, which is always ''width'' &times; ''height'' &times; 2 bytes long. It is important to realize that the image measurements are in 16-bit frame buffer pixels, which does not necessarily correspond to the size of the contained image. It may help to visualize the entire image data as a ''width'' &times; ''height'' array of 16-bit values, which is then interpreted differently depending on color mode (this is exactly how the PlayStation treats it). To calculate the actual image dimensions, it is thus necessary to take into account the current BPP value (bits per pixel).
 
<br/><center>[[Image:PSX_TIM_file_image.png]]</center><br/>
 
The image data, while loaded straight into the frame buffer, is structured differently depending on the bit depth of the image. The most straight-forward variant is for 16-bit images (BPP = <b>10</b>), in which case image data has the same format as the frame buffer pixels themselves:
 
<br/><center>[[Image:PSX_color_formats_16.png]]</center><br/>
 
The PlayStation is also capable of handling data in 24-bit color (BPP = <b>11</b>), in which case the color samples are stored as 3-byte groups. In the event that an image's width is an uneven number of pixels, the last byte is left as padding; the first pixel of a new row is always stored at the corresponding first pixel of the frame buffer row. The color samples are stored in the following order:
 
<br/><center>[[Image:PSX_color_formats_16.png]]</center><br/>
 
Apart from the two "real" color modes, the PlayStation frequently utilizes color indexed images via CLUTs (color lookup tables). Whenever an image with color index data is drawn to the screen, a reference to a CLUT is included and the color indices get replaced with the corresponding value in the table. For 8-bit indexed colors (BPP = <b>01</b>), the image pixels are stored two by two in each 16-bit value as follows:
 
<br/><center>[[Image:PSX_color_formats_8.png]]</center><br/>
 
These images are used in conjuction with a 256-pixel CLUT. For less color-rich images, 4-bit index colors (BPP = <b>00</b>) are also available, for use with a 16-pixel CLUT. These pixels are stored four by four in each 16-bit value:
 
<br/><center>[[Image:PSX_color_formats_4.png]]</center><br/>
Anonymous user

Navigation menu