{$G+,R-,S-,I-,Q-,N-,E-}
uses
   Objects,
   GRect,
   Scale, Data;

var
   R, C            :TGRect;
   Size            :TGPoint;

   LTimer, Time    :LongInt;
   Timer           :LongInt absolute 0:$46C;

const
   Pixels          :LongInt= 0;
   Frames          :Word =   0;

procedure CalcPixels;
begin
   Inc(Frames);
   Inc(Pixels, LongMul(R.SizeX, R.SizeY));
end;

begin
   Write(#13#10+
      'Bitmap Scaling Routine Demo  Copyright (c) 1995 by Solar Designer \ BPC'#13#10+
      'Press any key to continue...');

   asm
      xor  ax,ax
      int  16h

      mov  ax,13h
      int  10h

      xor  bx,bx
      mov  cx,256
      push seg Palette
      pop  es
      mov  dx,offset Palette
      mov  ax,1012h
      int  10h
   end;

   LTimer:=Timer;

   C.Assign(160, 100, 160, 100);
   repeat
      for Size.Y:=1 to 100 do
      begin
         Size.X:=LongDiv(LongMul(Size.Y, 320), 200);
         R:=C; R.Grow(Size.X, Size.Y);
         DrawScaledImage(@Picture, R);

         CalcPixels;
      end;

      for Size.Y:=99 downto 1 do
      begin
         Size.X:=LongDiv(LongMul(Size.Y, 320), 200);
         R:=C; R.Grow(Size.X, Size.Y);
         DrawScaledImage(@Picture, R);

         CalcPixels;
      end;
   until MemW[0:$41A]<>MemW[0:$41C];
   MemW[0:$41A]:=MemW[0:$41C];

   Time:=Timer-LTimer;

   asm
      mov  ax,3
      int  10h
   end;

   Pixels:=Pixels*18 div Time;
   WriteLn(#13+
      'Total time:'#9#9#9, LongDiv(Time, 18), ' seconds'#13#10+
      'Total frames:'#9#9#9, Frames, #13#10+
      'Pixels per second:'#9#9, Pixels, #13#10+
      'Frames per second:'#9#9, LongDiv(Frames*18, Time), #13#10+
      'Full screens per second:'#9, Pixels div (320*200));
end.
