-- PDInterpReader.mesa
-- Copyright (C) 1983, 1986 Xerox Corporation.  All rights reserved.
-- Michael Plass, September 4, 1984 9:51:32 am PDT
-- Last Edited by: Pier, November 22, 1983 2:44 pm
-- Tim Diebert, 25-Apr-86 13:18:12

DIRECTORY PDInterpBasic, PDFileFormat, PDInterpBitmap, Stream;
  
PDInterpReader: DEFINITIONS = BEGIN
-- Handle definition
  Handle: TYPE = LONG POINTER TO Rep;
  Rep: TYPE = RECORD [
    stream: Stream.Handle,
    herald: PDFileFormat.Herald,
    image: PDFileFormat.StartImage,
    bandNumber: CARDINAL,
    sMinBand: CARDINAL,
    sSizeBand: CARDINAL,
    colorType: ColorType,
    colorTileLoadAddress: INT,
    priority: INT,
    loadWords: INT,
    private: LONG POINTER TO PrivateRep,
    index: INT,
    page: INT,
    pass: INT,
    status: PDInterpBasic.Status,
    warningCount: INT
    ];
    
    ColorType: TYPE = {none, clear, ink, opaqueTile, transparentTile};
    PrivateRep: TYPE;
  
-- Color Tile access:
  ColorTileFromLoad: PROC [handle: Handle, colorTileLoadAddress: INT,
    scratchPointer: LONG POINTER ← NIL, scratchWords: INT ← 0]
    RETURNS [PDInterpBitmap.Tile];
  
-- Errors and Signals
  Error: ERROR [handle: Handle, code: PDInterpBasic.PDErrorCode,
    wordIndex, wordCount: INT];
  Warning: SIGNAL [handle: Handle, code: PDInterpBasic.PDWarningCode,
    wordIndex, wordCount: INT];
  
-- File control
  Open: PROC [stream: Stream.Handle] RETURNS [Handle];
    -- May raise PDFileReader.Error or PDFileReader.Warning
    -- Assumes the stream is positioned at the start of a PD file.
  Close: PROC [handle: Handle] RETURNS [stream: Stream.Handle];
    -- Doesa NOT close the stream.
  
-- Reading operations
  Get: PROC [handle: Handle] RETURNS [CommandBuffer];
    -- May raise PDFileReader.Error or PDFileReader.Warning
  
CommandBuffer: TYPE = RECORD [
  SELECT cmd: * FROM
    maskRectangle => [
      sMin, fMin, sSize, fSize: CARDINAL
      ],
    maskTrapezoid => [
      sMin, fMin, fMinLast, sSize, fSize, fSizeLast: CARDINAL
      ],
    maskRunGroup => [
      sMin, fMin, sSize, fSize: CARDINAL,
      fOffset: CARDINAL, -- add this to fMin of each run
      runCount: INT, -- number of runs
      pointer: LONG POINTER TO PDFileFormat.Run,
      loadAddress: INT -- -1 if not in the load
      ],
    maskSamples => [
      loadAddress: INT, -- -1 if not in the load
      samples: PDInterpBitmap.BitmapDesc
      ],
    colorSamples => [
      samples: PDInterpBitmap.BitmapDesc
      ],
    deviceCommand => [
      deviceCommandPointer: LONG POINTER,
      deviceCommandWords: CARDINAL
      ],
    stateChange => [
      whatChanged: WhatChanged,
      loadChangeStart, loadChangeLength: INT
      ],
    ENDCASE
  ];
  WhatChanged: TYPE = {
    imageStart, imageEnd, priorityChange, colorChange, bandChange,
    loadChange, documentEnd
    };
  
END.