{ bunpack.txt -- Algorithm #11: Unpack 8-bit Windows bitmap by Tom Swan }

const
  ESCAPE = 0;
  ENDOFLINE = 0;
  ENDOFBITMAP = 1;
  DELTA = 2;

procedure UnpackRLE8(var f: FILE);
var
  done: Boolean;
  count: Integer;
  oldCount: Integer;
  byt: Byte;
begin
  while ((not done) and 
    (not eof(f))) do
  begin
    byt := GetByte(f);
    if (byt = ESCAPE) then
    begin { Unpack escape code }
      byt := GetByte(f);
      case byt of
        ENDOFLINE:
          StartNewScanLine;
        ENDOFBITMAP:
          done := True;
        DELTA:
          begin { Not implemented }
            Writeln('Delta escape!');
            Halt
          end;
        else begin
        { Absolute-mode run }
          count := byt;
          oldCount := count;
          while count > 0 do
          begin
            byt := GetByte(f);
            PutByte(byt);
            count := count - 1
          end;
          if Odd(oldCount) { padding }
            then byt := GetByte(f)
        end { else }
      end { case }
    end else
    begin { Unpack RLE unit }
      count := byt;
      byt := GetByte(f);
      while count > 0 do
      begin
        PutByte(byt);
        count := count - 1
      end { while }
    end { else }
  end { while }
end; { UnpackRLE8 }


(*
// --------------------------------------------------------------
// Copyright (c) 1993 by Tom Swan. All rights reserved
// Revision 1.00    Date: 04/27/1993   Time: 08:52 am
*)
