Twilight Princess
Remastered version of the GameCube game
Loading...
Searching...
No Matches
BinaryTextureImage Class Reference

The BinaryTextureImage (or BTI) format is used by Wind Waker (and several other Nintendo games) to store texture images. There are a variety of encoding methods, some of which are supported right now for decoding. This does not currently support encoding BTI files but will at some point in time. It does not load mipmaps from the file currently. More...

+ Collaboration diagram for BinaryTextureImage:

Classes

class  Palette
 The Palette simply stores the color data as loaded from the file. It does not convert the files based on the Palette type to RGBA8. More...
 

Public Types

enum  TextureFormats {
  I4 = 0x00 , I8 = 0x01 , IA4 = 0x02 , IA8 = 0x03 ,
  RGB565 = 0x04 , RGB5A3 = 0x05 , RGBA32 = 0x06 , C4 = 0x08 ,
  C8 = 0x09 , C14X2 = 0x0a , CMPR = 0x0e
}
 ImageFormat specifies how the data within the image is encoded. Included is a chart of how many bits per pixel there are, the width/height of each block, how many bytes long the actual block is, and a description of the type of data stored. More...
 
enum  WrapModes { ClampToEdge = 0 , Repeat = 1 , MirroredRepeat = 2 }
 Defines how textures handle going out of [0..1] range for texcoords. More...
 
enum  PaletteFormats { IA8 = 0x00 , RGB565 = 0x01 , RGB5A3 = 0x02 }
 PaletteFormat specifies how the data within the palette is stored. An image uses a single palette (except CMPR which defines its own mini-palettes within the Image data). Only C4, C8, and C14X2 use palettes. For all other formats the type and count is zero. More...
 
enum  FilterMode {
  Nearest = 0x0 , Linear = 0x1 , NearestMipmapNearest = 0x2 , NearestMipmapLinear = 0x3 ,
  LinearMipmapNearest = 0x4 , LinearMipmapLinear = 0x5
}
 FilterMode specifies what type of filtering the file should use for min/mag. More...
 

Public Member Functions

 BinaryTextureImage ()
 
 BinaryTextureImage (string name)
 
void Load (EndianBinaryReader stream, long headerStart, int imageIndex=0)
 Load a BinaryTextureImage from a stream.
 
void ReplaceHeaderInfo (BinaryTextureImage other)
 
void DetectAndSetFittingFormat ()
 
void SaveImageToDisk (string outputFile)
 
Texture2D SkiaToTexture ()
 
void WriteHeader (EndianBinaryWriter writer)
 Loads image data from disk into a byte array.
 

Static Public Member Functions

static byte[] DecodeData (EndianBinaryReader stream, uint width, uint height, TextureFormats format)
 

Public Attributes

short unknown2 = 0
 
byte unknown3 = 0
 

Properties

string Name [get, set]
 
TextureFormats Format [get, set]
 
byte AlphaSetting [get, set]
 
ushort Width [get, private set]
 
ushort Height [get, private set]
 
WrapModes WrapS [get, set]
 
WrapModes WrapT [get, set]
 
bool PalettesEnabled [get, set]
 
PaletteFormats PaletteFormat [get, set]
 
ushort PaletteCount [get, set]
 
int EmbeddedPaletteOffset [get, private set]
 
FilterMode MinFilter [get, set]
 
FilterMode MagFilter [get, set]
 
sbyte MinLOD [get, set]
 
sbyte MagLOD [get, set]
 
byte MipMapCount [get, private set]
 
short LodBias [get, set]
 
byte[] RGBAImageData [get, set]
 

Private Member Functions

Tuple< byte[], ushort[]> EncodeC4 ()
 
Tuple< byte[], ushort[]> EncodeC8 ()
 
void EncodeColor (Color32 col, List< ushort > rawColorData, Dictionary< Color32, byte > pixelColorIndexes)
 

Static Private Member Functions

static byte[] DecodeData (EndianBinaryReader stream, uint width, uint height, TextureFormats format, Palette imagePalette, PaletteFormats paletteFormat)
 
static byte[] DecodeRgba32 (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeC4 (EndianBinaryReader stream, uint width, uint height, Palette imagePalette, PaletteFormats paletteFormat)
 
static byte[] DecodeC8 (EndianBinaryReader stream, uint width, uint height, Palette imagePalette, PaletteFormats paletteFormat)
 
static byte[] DecodeRgb565 (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeCmpr (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeCmprSubBlock (EndianBinaryReader stream)
 
static void Swap (ref byte b1, ref byte b2)
 
static ushort Read16Swap (byte[] data, uint offset)
 
static uint Read32Swap (byte[] data, uint offset)
 
static byte S3TC1ReverseByte (byte b)
 
static byte[] DecodeIA8 (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeIA4 (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeI4 (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeI8 (EndianBinaryReader stream, uint width, uint height)
 
static byte[] DecodeRgb5A3 (EndianBinaryReader stream, uint width, uint height)
 
static void UnpackPixelFromPalette (int paletteIndex, ref byte[] dest, int offset, byte[] paletteData, PaletteFormats format)
 
static void RGB565ToRGBA8 (ushort sourcePixel, ref byte[] dest, int destOffset)
 Convert a RGB565 encoded pixel (two bytes in length) to a RGBA (4 byte in length) pixel.
 
static void RGB5A3ToRGBA8 (ushort sourcePixel, ref byte[] dest, int destOffset)
 Convert a RGB5A3 encoded pixel (two bytes in length) to an RGBA (4 byte in length) pixel.
 

Private Attributes

Palette m_imagePalette
 
byte[] m_rgbaImageData
 

Detailed Description

The BinaryTextureImage (or BTI) format is used by Wind Waker (and several other Nintendo games) to store texture images. There are a variety of encoding methods, some of which are supported right now for decoding. This does not currently support encoding BTI files but will at some point in time. It does not load mipmaps from the file currently.

Image data can be retrieved by calling GetData() which will return an ARGB array of bytes containing the information. For files without alpha data their values will be set to 0xFF.

BTI files are stored both individually on disk and embedded within other file formats.

Member Enumeration Documentation

◆ FilterMode

FilterMode specifies what type of filtering the file should use for min/mag.

Enumerator
Nearest 
Linear 
NearestMipmapNearest 
NearestMipmapLinear 
LinearMipmapNearest 
LinearMipmapLinear 

◆ PaletteFormats

PaletteFormat specifies how the data within the palette is stored. An image uses a single palette (except CMPR which defines its own mini-palettes within the Image data). Only C4, C8, and C14X2 use palettes. For all other formats the type and count is zero.

Enumerator
IA8 
RGB565 
RGB5A3 

◆ TextureFormats

ImageFormat specifies how the data within the image is encoded. Included is a chart of how many bits per pixel there are, the width/height of each block, how many bytes long the actual block is, and a description of the type of data stored.

Enumerator
I4 
I8 
IA4 
IA8 
RGB565 
RGB5A3 
RGBA32 
C4 
C8 
C14X2 
CMPR 

◆ WrapModes

Defines how textures handle going out of [0..1] range for texcoords.

Enumerator
ClampToEdge 
Repeat 
MirroredRepeat 

Constructor & Destructor Documentation

◆ BinaryTextureImage() [1/2]

BinaryTextureImage.BinaryTextureImage ( )

◆ BinaryTextureImage() [2/2]

BinaryTextureImage.BinaryTextureImage ( string name)

Member Function Documentation

◆ DecodeC4()

static byte[] BinaryTextureImage.DecodeC4 ( EndianBinaryReader stream,
uint width,
uint height,
Palette imagePalette,
PaletteFormats paletteFormat )
staticprivate

◆ DecodeC8()

static byte[] BinaryTextureImage.DecodeC8 ( EndianBinaryReader stream,
uint width,
uint height,
Palette imagePalette,
PaletteFormats paletteFormat )
staticprivate

◆ DecodeCmpr()

static byte[] BinaryTextureImage.DecodeCmpr ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeCmprSubBlock()

static byte[] BinaryTextureImage.DecodeCmprSubBlock ( EndianBinaryReader stream)
staticprivate

◆ DecodeData() [1/2]

static byte[] BinaryTextureImage.DecodeData ( EndianBinaryReader stream,
uint width,
uint height,
TextureFormats format )
static

◆ DecodeData() [2/2]

static byte[] BinaryTextureImage.DecodeData ( EndianBinaryReader stream,
uint width,
uint height,
TextureFormats format,
Palette imagePalette,
PaletteFormats paletteFormat )
staticprivate

◆ DecodeI4()

static byte[] BinaryTextureImage.DecodeI4 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeI8()

static byte[] BinaryTextureImage.DecodeI8 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeIA4()

static byte[] BinaryTextureImage.DecodeIA4 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeIA8()

static byte[] BinaryTextureImage.DecodeIA8 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeRgb565()

static byte[] BinaryTextureImage.DecodeRgb565 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeRgb5A3()

static byte[] BinaryTextureImage.DecodeRgb5A3 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DecodeRgba32()

static byte[] BinaryTextureImage.DecodeRgba32 ( EndianBinaryReader stream,
uint width,
uint height )
staticprivate

◆ DetectAndSetFittingFormat()

void BinaryTextureImage.DetectAndSetFittingFormat ( )

◆ EncodeC4()

Tuple< byte[], ushort[]> BinaryTextureImage.EncodeC4 ( )
private

◆ EncodeC8()

Tuple< byte[], ushort[]> BinaryTextureImage.EncodeC8 ( )
private

◆ EncodeColor()

void BinaryTextureImage.EncodeColor ( Color32 col,
List< ushort > rawColorData,
Dictionary< Color32, byte > pixelColorIndexes )
private

◆ Load()

void BinaryTextureImage.Load ( EndianBinaryReader stream,
long headerStart,
int imageIndex = 0 )

Load a BinaryTextureImage from a stream.

Parameters
stream
headerStart
imageIndexOptional additional offset used by J3D models. Multiplied by 0x20.

◆ Read16Swap()

static ushort BinaryTextureImage.Read16Swap ( byte[] data,
uint offset )
staticprivate

◆ Read32Swap()

static uint BinaryTextureImage.Read32Swap ( byte[] data,
uint offset )
staticprivate

◆ ReplaceHeaderInfo()

void BinaryTextureImage.ReplaceHeaderInfo ( BinaryTextureImage other)

◆ RGB565ToRGBA8()

static void BinaryTextureImage.RGB565ToRGBA8 ( ushort sourcePixel,
ref byte[] dest,
int destOffset )
staticprivate

Convert a RGB565 encoded pixel (two bytes in length) to a RGBA (4 byte in length) pixel.

Parameters
sourcePixelRGB565 encoded pixel.
destDestination array for RGBA pixel.
destOffsetOffset into destination array to write RGBA pixel.

◆ RGB5A3ToRGBA8()

static void BinaryTextureImage.RGB5A3ToRGBA8 ( ushort sourcePixel,
ref byte[] dest,
int destOffset )
staticprivate

Convert a RGB5A3 encoded pixel (two bytes in length) to an RGBA (4 byte in length) pixel.

Parameters
sourcePixelRGB5A3 encoded pixel.
destDestination array for RGBA pixel.
destOffsetOffset into destination array to write RGBA pixel.

◆ S3TC1ReverseByte()

static byte BinaryTextureImage.S3TC1ReverseByte ( byte b)
staticprivate

◆ SaveImageToDisk()

void BinaryTextureImage.SaveImageToDisk ( string outputFile)

◆ SkiaToTexture()

Texture2D BinaryTextureImage.SkiaToTexture ( )

◆ Swap()

static void BinaryTextureImage.Swap ( ref byte b1,
ref byte b2 )
staticprivate

◆ UnpackPixelFromPalette()

static void BinaryTextureImage.UnpackPixelFromPalette ( int paletteIndex,
ref byte[] dest,
int offset,
byte[] paletteData,
PaletteFormats format )
staticprivate

◆ WriteHeader()

void BinaryTextureImage.WriteHeader ( EndianBinaryWriter writer)

Loads image data from disk into a byte array.

Member Data Documentation

◆ m_imagePalette

Palette BinaryTextureImage.m_imagePalette
private

◆ m_rgbaImageData

byte [] BinaryTextureImage.m_rgbaImageData
private

◆ unknown2

short BinaryTextureImage.unknown2 = 0

◆ unknown3

byte BinaryTextureImage.unknown3 = 0

Property Documentation

◆ AlphaSetting

byte BinaryTextureImage.AlphaSetting
getset

◆ EmbeddedPaletteOffset

int BinaryTextureImage.EmbeddedPaletteOffset
getprivate set

◆ Format

TextureFormats BinaryTextureImage.Format
getset

◆ Height

ushort BinaryTextureImage.Height
getprivate set

◆ LodBias

short BinaryTextureImage.LodBias
getset

◆ MagFilter

FilterMode BinaryTextureImage.MagFilter
getset

◆ MagLOD

sbyte BinaryTextureImage.MagLOD
getset

◆ MinFilter

FilterMode BinaryTextureImage.MinFilter
getset

◆ MinLOD

sbyte BinaryTextureImage.MinLOD
getset

◆ MipMapCount

byte BinaryTextureImage.MipMapCount
getprivate set

◆ Name

string BinaryTextureImage.Name
getset

◆ PaletteCount

ushort BinaryTextureImage.PaletteCount
getset

◆ PaletteFormat

PaletteFormats BinaryTextureImage.PaletteFormat
getset

◆ PalettesEnabled

bool BinaryTextureImage.PalettesEnabled
getset

◆ RGBAImageData

byte [] BinaryTextureImage.RGBAImageData
getset

◆ Width

ushort BinaryTextureImage.Width
getprivate set

◆ WrapS

WrapModes BinaryTextureImage.WrapS
getset

◆ WrapT

WrapModes BinaryTextureImage.WrapT
getset

The documentation for this class was generated from the following file: