BoBo Fetts 16-bit mat specs.
Mar 10,2002



Known 16-bit mat formats supported by JediKnight: 
565 RGB 
1555 ARGB 


Note: The following code is in Delphi 3 format


The header for a 16-bit mat is:

TMatHeader = record
tag:array[0..3] of char; {'MAT ' - notice space after MAT}
ver:Longint;             {Apparently - version = 0x32 ('2')}
mat_Type:Longint;        {0 = colors(TColorHeader) , 1= ?, 2= texture(TTextureHeader)}
NumOfTextures:Longint;   {number of textures or colors}
NumOfTextures1: Longint; { In color MATs, it's 0, in TX ones, it's equal to numOfTextures }
unk0:Longint;            { = 1 } {unknown use}
bits:LongInt;            { = 16} {bits/pixel}
bluebits:longint;        { = 5 } {blue bits per pixel}   
greenbits:longint;       { = 6 for rgb565 or 5 for argb1555} {green bits per pixel}
redbits:longint;         { = 5 } {red bits per pixel}
shiftR:longint;          { = 11 or 8} {shift left blue}
shiftG:longint;          { = 5 or 4} {shift left green}
shiftB:longint;          { = 0 } {shift left red}
unk1h:longint;           { = 3 } {shift right red}
unk2h:longint;           { = 2 } {shift right green}
unk3h:longint;           { = 3 } {shift right blue}

unk4h:longint;  //=0
unk5h:longint;  //=0
unk6h:longint;  //=0

end;


Texture Type Header:
The texture Type Header is repeated number of Texture times

TTextureHeader = record
textype:longint;         {0 = color, 8= texture}
colornum:longint;        {transparent color RGB}
pads:array[0..2]of Longint;
unk1th:lonint; 
unk2th:longint; //=0
unk3th:longint; //=4
unk4th:longint; //=4
unk5th:longint; //=0
end;


Texture Data header:
Each Texture in the Mat file has this header before it

TTextureData = record
SizeX:Longint;             {horizontal size of first MipMap, must be divisable by 2}
SizeY:Longint;             {Vertical size of first MipMap ,must be divisable by 2}
transparent:Longint        {1=use transparent color, 0=No Transparent color}
Pad:array[0..1]of LongInt; {padding = 0 }
NumMipMaps:LongInt;        {Number of mipmaps in texture largest one first.}
end;



This is the function in Mat16 that reads the mat data and converts it
to a bitmap:


Function Mat16ToBmp(w,h:Integer):TBitmap;
var
      i,j:Integer;
   
begin

result := TBitmap.Create;

    result.Width  := W;
    result.Height := H;
    result.PixelFormat := pf16bit;
      
     FOR i := 0 TO H-1 DO
        BlockRead(f,result.Scanline[i]^,w*2);

end;
