BTI

From CloudModding TWW Wiki
Jump to: navigation, search

BTI is a format used for storing image data. It can be found alone as a .bti file, or as an embedded image in the TEX1 chunk of the BMD/BDL model format.

The format is simply a header followed by the image data. The image data can be encoded in several different ways, and the header specifies which format the image data is in.

Header

// 0x20/32 bytes long
/*0x00*/ byte FormatID; // Image data format. See "Texture Formats" below
/*0x01*/ bool AlphaEnabled;
/*0x02*/ short Width; //Width of texture
/*0x04*/ short Height; //Height of texture
/*0x06*/ byte WrapS; //0 = clamp to edge, 1 = repeat, 2 = mirror
/*0x07*/ byte WrapT; //Above
/*0x08*/ byte Unknown1;
/*0x09*/ byte PaletteFormat; // Palette data format. See "Palette Formats" below
/*0x0A*/ short PaletteEntryCount; //Number of Palettes
/*0x0C*/ int PaletteOffset; //Offsets relative to start of BTITextureHeader
/*0x10*/ Color BorderColor;
/*0x14*/ byte MinFilter; //Probably two U8s, first is 5 or 1, second 1 most of the time
/*0x15*/ byte MagFilter;
/*0x16*/ short Unknown2; //0 most of the time, sometimes 0x10, 0x18, 0x20, 0x28
/*0x18*/ byte MipmapCount; //How many mipmaps
/*0x19*/ byte Unknown3;
/*0x1A*/ short LodBias;
/*0x1C*/ int DataOffset //Relative to the start of the header, points to Image Data
//Some of the unknown data may be related to render state (lod bias, min/mag filter, etc.?)

As Embedded Image

The BTI format can be stored in models and particle banks as an embedded image. When this is the case, the headers for each embedded image are stored together, one after another. After the last header is the image data corresponding to each header in an uninterrupted stream.

This is where the "DataOffset" variable in the header is useful. This offset specifies where the image data starts in relation to the start of the image data's header. In other words, to find the image data for a given header, you go to the start of the header and move forward the number of bytes given by DataOffset.

Texture Formats

This is the list of formats that the image data can be encoded in.

ID Format Bits per Pixel Block Width Block Height Block Size Type/Description
0x00 I4 4 8 8 32 Gray
0x01 I8 8 8 8 32 Gray
0x02 IA4 8 8 4 32 Gray + Alpha
0x03 IA8 16 4 4 32 Gray + Alpha
0x04 RGB565 16 4 4 32 Color
0x05 RGB5A3 16 4 4 32 Color + Alpha
0x06 RGBA32 32 4 4 64 Color + Alpha
0x08 C4 4 8 8 32 Palette
0x09 C8 8 8 4 32 Palette
0x0A C14X2 16 (14 used) 4 4 32 Palette
0x0E CMPR 4 8 8 32 Mini palettes in each block, RGB565, or transparent.

Palette Formats

The C4, C8, C14X2, and CMPR image formats all use palettes to store color data. For C4, C8, and C14X2, the palette format will be specified in the PaletteFormat variable in the image's header. CMPR stores palettes within the compressed blocks of image data. Below is a table containing the 3 possible palette formats.

ID Format Bits per Pixel Block Width Block Height Block Size Type/Description
0x00 IA8 16 4 4 32 Gray + Alpha
0x01 RGB565 16 4 4 32 Color
0x02 RGB5A3 16 4 4 32 Color + Alpha