TesOtherMod:TEXBSI File Format

The TEXBSI files found in Redguard's fxart directory store texture data used for 3d models. There are 415 such files, with extensions ranging from 000 to 500. For example, TEXBSI.412 contains textures related to Cyrus.

This page outlines the format of these files in detail. It is assumed that you are familiar with hex-editing and base-16 numbers.

Format Description
Each TEXBSI file is composed of multiple image structures, one following the other. These images may be animated, and the separate frames can share rows of pixels. The images in a file usually share some common elements; they may all be from the same tile set, or map to the same 3d model. The file containing the most images is TEXBSI.412 with 64, all of them ground textures.

Note that integers and shorts have little-endian byte order unless stated otherwise. Shown below is how the integer 12Ch would appear in each order.
:Little-endian: 2C 01 00 00
:Big-endian: 00 00 01 2C

Image Structure
Image structures begin with a 9 byte name identifier. A null image name (all 0 bytes) indicates the end of the texture file. If the name is non-null, it is followed by an integer representing the image structure's size in bytes. The image size does not include the 13 bytes taken by name and size fields.


The image is then divided into a number of sub-records. All sub-records have a similar beginning format: a 4 byte name followed by a big-endian integer representing the sub-record's size in bytes. As before, this size does not include the first 8 bytes taken up by the name and size fields.


The data that comes after the size field depends on the sub-record. The possible image sub-records are described below, in the order they appear.

;BSIF
:(0 bytes; this or IFHD required)
:The name probably stands for 'Bethesda Softworks Image Format'. Except for the last image in TEXBSI.357, BSIF is the sub-record used for images that are not animated.

;IFHD
:(44 bytes; this or BSIF required)
:This represents an 'Image Format Header', which is always a 1 followed by 43 0s. BSIF and IFHD sub-records cannot exist together.

;BHDR
:(26 bytes; required)
:BHDR contains information about the image, most importantly width, height, and the number of frames. The purpose of much of the other data is unknown.


;CMAP
:(768 bytes; optional)
:A color map, or palette, for defining custom colors for the current image. The data is 256 colors written in RGB triplets.

:Most images do not have a CMAP sub-record, so they rely on an external palette instead. These are found in the fxart directory as files ending in COL. The file format is identical to CMAP except for the first 8 bytes. WORLD.INI defines which color map should be used for each location.

;DATA
:(Variable size; required)
:This sub-record contains all of the image's pixel data. If the image is not animated (number of frames defined in BHDR is 1) then the data is an array of   bytes. Each byte is an index in the current color map.

:If instead the image is animated then there is first a list of   integer offsets. Each group of height offsets points to rows of bytes (width in length) for one frame. An offset with value 0 starts at the beginning of this offset list rather than after it.

;END
:(0 bytes; required)
:Always the last sub-record of an image. Note that there is a space after the 'D'.

Source Libraries
:* Redguard-3dfiletest -- Test project that contains a class for loading and handling TEXBSI files.