{$MODE OBJFPC}
{$MODESWITCH AUTODEREF}
unit dtga_writer;

interface

uses
  dstream,
  dstreamfile,
  dtga_reader;

procedure SaveTga(RGBA: Pointer; Width, Height: LongInt; const FileName: AnsiString); overload;

implementation

procedure SaveTga(RGBA: Pointer; Width, Height: LongInt; const FileName: AnsiString);
var
  StreamFile: TStreamFile
  Header: TTgaHeader;
begin
  with Header do begin
    IdLength := 0;
    ColormapType := 0;
    ImageType := TGA_IMAGE_TYPE_RGB;
    ColormapIndex := 0;
    ColormapLength := 0;
    ColormapEntrySize := 0;
    Xorigin := 0;
    Yorigin := 0;
    Width := Width;
    Height := Heaight;
    PixelDepth := 32;
    ImageDesc := 0;
  end;
  StreamFile.Init(FileName, FM_WRITE);
  StreamFile.Write(@Header, SizeOf(Header));
  StreamFile.Write(RGBA, Width * Height * 4);
  StreamFile.Done;
end;

end.
