Uses Graph;
Procedure EGAVGADriver;external;
var
 inp,outp : file;
 p        : pointer;
 Name     : string;
 Beg	  : string;
 Size     : word;
 k,i,j    : word;
 x,y      : word;
 val      : byte;
 gD,gM    : Integer;
begin
 gD:=Detect;
 {$L EGAVGA.OBJ}
 RegisterBGIDriver(@EGAVGADriver);
 InitGraph(gD,gM,'');
 Assign(outp,'trap.dat');
 ReWrite(outp,1); 
 k:=1;
 BlockWrite(OUTP,k,2);

  OutTextXY(300,200,'trap.tga');
  Assign(inp,'trap.tga');
  Reset(inp,1);
  Seek(INP,12);
  BlockRead(inp,x,2);
  BlockRead(inp,y,2);
  Seek(Inp,$312);
  for i := 1 to y do
    for j := 1 to x do
     begin
      BlockRead(INP,val,1);
      if (val and $F) <> $F  then
        PutPixel(j,y-i+1, 0)
      else
        PutPixel(j,y-i+1,White);
     end;
  Close(INP);
  Size := ImageSize(0,0,x,y);
  BlockWrite(OUTP,Size,2);

  GetMem(P,Size);
  GetImage(1,1,x,y,P^);
  BlockWrite(OUTP,P^,Size);
  FreeMem(P,Size);
  ReadLn;
  ClearDevice;

 CloseGraph;
 Close(OUTP);
end.