Uses Graph;
const
 table :array [0..15] of byte  = (0,1,2,Yellow,Blue,5,6,7,8,9,10,Yellow,LightBlue,13,14,15);
var
 inp,outp : file;
 p        : pointer;
 Size     : Word;
 i,j      : word;
 x,y      : word;
 val      : byte;
 gD,gM    : Integer;
begin
 gD:=VGA;
 gM:=VGAMed;

 InitGraph(gD,gM,'');

 Assign(outp,'BG2.dat');
 ReWrite(outp,1);

 Assign(inp,'BG.bmp');
 Reset(inp,1);

  Seek(INP,$12);
  BlockRead(inp,x,4);
  BlockRead(inp,y,4);
  Seek(Inp,$76);
  for i := 0 to y-1 do
    for j := 0 to (x-1) shr 1 do
     begin
      BlockRead(INP,val,1);
      PutPixel(j*2+1,479-i, table[val and $F]);
      PutPixel(j*2,479-i,table[(val shr 4) and $F]);
     end;
  Close(INP);

  Size := ImageSize(0,0,(x shr 1),(y shr 1)-1);

  i:=4;
  BlockWrite(OUTP,i,1);
  GetMem(P,Size);
  BlockWrite(OUTP,Size,2);
  i:=0;
  BlockWrite(OUTP,i,2);
  BlockWrite(OUTP,i,2);
  GetImage(0,0,(x shr 1)-1,(y shr 1)-1,P^);
  BlockWrite(OUTP,P^,Size);

  BlockWrite(OUTP,Size,2);
  i:=x shr 1;
  BlockWrite(OUTP,i,2);
  i:=0;
  BlockWrite(OUTP,i,2);
  GetImage(x shr 1,0,x-1,(y shr 1)-1,P^);
  BlockWrite(OUTP,P^,Size);

  BlockWrite(OUTP,Size,2);
  i:=0;
  BlockWrite(OUTP,i,2);
  i:=y shr 1;
  BlockWrite(OUTP,i,2);
  GetImage(0,y shr 1,(x shr 1)-1,y-1,P^);
  BlockWrite(OUTP,P^,Size);

  BlockWrite(OUTP,Size,2);
  i:=x shr 1;
  BlockWrite(OUTP,i,2);
  i:=y shr 1;
  BlockWrite(OUTP,i,2);
  GetImage(x shr 1,y shr 1,x-1,y-1,P^);
  BlockWrite(OUTP,P^,Size);

  FreeMem(P,Size);
  ReadLn;

 CloseGraph;
 Close(OUTP);
end.