- TRGBA = packed record
- r: byte;
- g: byte;
- b: byte;
- a: byte; // align rgb for windows bitmaps
- end;
- PRGBA = ^TRGBA;
- TRGBAs = array[0..4096*4096] of TRGBA; // reserve enough space
- PRGBAs = ^TRGBAs;
- TRGBAImage = record
- width: integer;
- height : integer;
- data : PRGBAs;
- end;
- PRGBAImage = ^TRGBAImage;
- TTGAHeader = packed record
- idlength : byte;
- colourmaptype : byte;
- datatypecode : byte;
- colourmaporigin : smallint;
- colourmaplength : smallint;
- colourmapdepth : byte;
- x_origin : smallint;
- y_origin : smallint;
- width : smallint;
- height : smallint;
- bitsperpixel : byte;
- imagedescriptor : byte;
- end;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // 32 bit TGA image loader
- //
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function LoadTGAImage(FileName : String) : PRGBAImage;
- var
- Header : TTGAHeader;
- F : File;
- img : PRGBAImage;
- l : integer;
- h : byte;
- begin
- img := NIL;
- if IOResult<>0 then ; // clear IOResult
- Assign(F, FileName);
- Reset(F, 1);
- if IOResult=0 then begin
- BlockRead(F, Header, SizeOf(Header));
- with Header do
- if (datatypecode=2) and (bitsperpixel=32) then begin
- Seek(F, SizeOf(Header) + idlength + colourmaptype * colourmaplength);
- New(img);
- img.width := width;
- img.height := height;
- l := img.width * img.height;
- GetMem(img.data, l * 4);
- BlockRead(F, img.data^, l * 4);
- repeat
- dec(l);
- with img.data^[l] do begin h:=r; r:=b; b:=h; end;
- until l=0;
- end;
- Close(F);
- end
- else begin
- New(img);
- img.width := 16;
- img.height := 16;
- GetMem(img.data, 1024);
- FillChar(img.data^, 1024, $FF);
- end;
- result := img;
- end;