Skip to content

TEX Format

Niema Moshiri edited this page Jul 8, 2019 · 17 revisions

TEX is a texture format and is used throughout Final Fantasy VII. The TEX format consists of a header, an optional palette, and bitmap data. Usually, data are stored as a palletized picture, with bitmap pixels referencing the palette. The color #000000 is often used to denote transparency (but not always; it depends on the color key status; more info later). The TEX format is very flexible and can take almost any non-paletted format as long as it is described properly in the header. This wiki might be a useful reference.

Section 1: File Header

A TEX file's header gives general information about the TEX file.

4 bytes: Version

  • This is an unsigned integer and must always equal 1 for Final Fantasy VII to load

4 bytes: Unknown 1

  • These 4 bytes have unknown function

4 bytes: Color Key Flag

  • This is an unsigned integer
  • According to this, this must be 1 (i.e., 00000001) to enable transparent color
    • All the **ac files have it as 1

4 bytes: Unknown 2

  • These 4 bytes have unknown function

4 bytes: Unknown 3

  • These 4 bytes have unknown function

4 bytes: Minimum Number of Bits per Color

  • This is an unsigned integer
  • The D3D driver uses this to determine which texture format to convert to on load

4 bytes: Maximum Number of Bits per Color

  • This is an unsigned integer

4 bytes: Minimum Number of Alpha Bits

  • This is an unsigned integer

4 bytes: Maximum Number of Alpha Bits

  • This is an unsigned integer

4 bytes: Minimum Number of Bits per Pixel

  • This is an unsigned integer

4 bytes: Maximum Number of Bits per Pixel

  • This is an unsigned integer

4 bytes: Unknown 4

  • These 4 bytes have unknown function

4 bytes: Number of Palettes

  • This is an unsigned integer

4 bytes: Number of Colors per Palette

  • This is an unsigned integer

4 bytes: Bit Depth

  • This is an unsigned integer

4 bytes: Image Width

  • This is an unsigned integer

4 bytes: Image Height

  • This is an unsigned integer

4 bytes: Number of Bytes per Row

  • This is an unsigned integer
  • This is usually ignored and assumed to be width * bytes-per-pixel
  • All the **ac files have 0 for this

4 bytes: Unknown 5

  • These 4 bytes have unknown function

4 bytes: Palette Flag

  • This is an unsigned integer
  • 1 indicates the presence of a palette, otherwise 0

4 bytes: Number of Bits per Index

  • This is an unsigned integer
  • This is always 8 for non-paletted images

4 bytes: Indexed-to-8bit Flag

  • This is an unsigned integer
  • This is never used in Final Fantasy VII
  • All the **ac files have 0 for this

4 bytes: Palette Size

  • This is an unsigned integer
  • This wiki, says it's always number of palettes * colors per palette
    • However, when I tested it, it was always equal to number of colors per palette (not the product)

4 bytes: Number of Colors per Palette (duplicate)

  • This is an unsigned integer
  • The first instance will be used anyways

4 bytes: Runtime Data 1

  • This is ignored on load

4 bytes: Bits per Pixel

  • This is an unsigned integer
  • All the **ac files have 8 for this

4 bytes: Bytes per Pixel

  • This is an unsigned integer
  • Always use this to determine how much data to read, regardless of the bit depth
    • For example, if this is 1, you read 1 byte per pixel
  • All the **ac files have 1 for this

Section 2: Pixel Format

This section has information about the pixel format. It seems as though color values are computed by (((value & mask) >> shift) * 255) / max

4 bytes: Number of Red Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Number of Green Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Number of Blue Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Number of Alpha Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Red Bitmask

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Green Bitmask

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Blue Bitmask

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Alpha Bitmask

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Red Shift

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Green Shift

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Blue Shift

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Alpha Shift

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: 8 - Number of Red Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: 8 - Number of Green Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: 8 - Number of Blue Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: 8 - Number of Alpha Bits

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Red Max

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Green Max

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Blue Max

  • This is an unsigned integer
  • All the **ac files have 0 for this

4 bytes: Alpha Max

  • This is an unsigned integer
  • All the **ac files have 0 for this

Section 3: File Header 2

This is some more header information.

4 bytes: Color Key Array Flag

  • This indicates the presence of a color key array

4 bytes: Runtime Data 2

  • I don't know what this does

4 bytes: Reference Alpha

  • This is an unsigned integer

4 bytes: Runtime Data 3

  • I don't know what this does

4 bytes: Unknown 6

  • These 4 bytes have unknown function

4 bytes: Palette Index (Runtime Data)

  • This is an unsigned integer

8 bytes: Runtime Data 4

  • I don't know what this does

16 bytes: Unknown 7

  • These 16 bytes have unknown function

Section 4: Palette Data

This section holds the palette data. Each palette entry is 4 bytes, and there are "palette size" entries. Note that palette size can be 0 (in which case this section does not exist). Each palette entry is a 32-bit BGRA format color.

Summary

  • File Header
    • 4 bytes (Version)
    • 4 bytes (Unknown 1)
    • 4 bytes (Color Key Flag)
    • 4 bytes (Unknown 2)
    • 4 bytes (Unknown 3)
    • 4 bytes (Minimum Number of Bits per Color)
    • 4 bytes (Maximum Number of Bits per Color)
    • 4 bytes (Minimum Number of Alpha Bits)
    • 4 bytes (Maximum Number of Alpha Bits)
    • 4 bytes (Minimum Number of Bits per Pixel)
    • 4 bytes (Maximum Number of Bits per Pixel)
    • 4 bytes (Unknown 4)
    • 4 bytes (Number of Palettes)
    • 4 bytes (Number of Colors per Palette)
    • 4 bytes (Bit Depth)
    • 4 bytes (Image Width)
    • 4 bytes (Image Height)
    • 4 bytes (Number of Bytes per Row)
    • 4 bytes (Unknown 5)
    • 4 bytes (Palette Flag)
    • 4 bytes (Number of Bits per Index)
    • 4 bytes (Indexed-to-8bit Flag)
    • 4 bytes (Palette Size)
    • 4 bytes (Number of Colors per Palette, duplicate)
    • 4 bytes (Runtime Data 1)
    • 4 bytes (Bits per Pixel)
    • 4 bytes (Bytes per Pixel)
  • Pixel Format
    • 4 bytes (Number of Red Bits)
    • 4 bytes (Number of Green Bits)
    • 4 bytes (Number of Blue Bits)
    • 4 bytes (Number of Alpha Bits)
    • 4 bytes (Number of Red Bitmask)
    • 4 bytes (Number of Green Bitmask)
    • 4 bytes (Number of Blue Bitmask)
    • 4 bytes (Number of Alpha Bitmask)
    • 4 bytes (Number of Red Shift)
    • 4 bytes (Number of Green Shift)
    • 4 bytes (Number of Blue Shift)
    • 4 bytes (Number of Alpha Shift)
    • 4 bytes (8 - Number of Red Bits)
    • 4 bytes (8 - Number of Green Bits)
    • 4 bytes (8 - Number of Blue Bits)
    • 4 bytes (8 - Number of Alpha Bits)
    • 4 bytes (Number of Red Max)
    • 4 bytes (Number of Green Max)
    • 4 bytes (Number of Blue Max)
    • 4 bytes (Number of Alpha Max)
  • File Header 2
    • 4 bytes (Color Key Array Flag)
    • 4 bytes (Runtime Data 2)
    • 4 bytes (Reference Alpha)
    • 4 bytes (Runtime Data 3)
    • 4 bytes (Unknown 6)
    • 4 bytes (Palette Index)
    • 8 bytes (Runtime Data 4)
    • 16 bytes (Unknown 7)
  • Palette Data
    • "Palette Size" Entries
      • Entry 1
        • 1 byte (Blue)
        • 1 byte (Green)
        • 1 byte (Red)
        • 1 byte (Alpha)
      • ...
        • Entry "Palette Size"*
          • ...
  • Pixel Data
    • "Height" Rows
      • "Width" Columns
        • "bytes-per-pixel" bytes (Index in Palette for Pixel Color)
Clone this wiki locally