<> <> DIRECTORY Environment, PDFileFormat, PDInterpReader, PDInterpOutput, PDInterpPage, PDInterpBitmap, Space; PDInterpPageImpl: PROGRAM IMPORTS PDInterpReader, PDInterpOutput, PDInterpBitmap, Space EXPORTS PDInterpPage = BEGIN CommandBuffer: TYPE = PDInterpReader.CommandBuffer; bitsPerWord: NAT = Environment.bitsPerWord; InterpretPage: PUBLIC PROC [handle: PDInterpReader.Handle] RETURNS [ok: BOOLEAN] ~ { band: PDInterpBitmap.BitmapDesc; cachedColorTile: PDInterpBitmap.Tile; cachedColorReference: INT _ -1; GetColorTile: PROC ~ { IF handle.colorTileLoadAddress # cachedColorReference THEN { cachedColorTile _ PDInterpReader.ColorTileFromLoad[handle, cachedColorReference _ handle.colorTileLoadAddress, scratchPointer, scratchWords]; }; }; TransferRectangle: PROC [rectangle: PDInterpBitmap.Rectangle] ~ { SELECT handle.colorType FROM none => ERROR; clear => PDInterpBitmap.Fill[band, rectangle, 0]; ink => PDInterpBitmap.Fill[band, rectangle, 1]; opaqueTile => { GetColorTile[]; PDInterpBitmap.TransferTile[band.Clip[rectangle], cachedColorTile]; }; transparentTile => { GetColorTile[]; PDInterpBitmap.TransferTile[band.Clip[rectangle], cachedColorTile, [or, null]]; }; ENDCASE => ERROR; }; TempColor: PROC [rectangle: PDInterpBitmap.Rectangle] ~ { SELECT handle.colorType FROM none => ERROR; clear => PDInterpBitmap.Fill[band, rectangle, 0, [xor, complement]]; ink => NULL; opaqueTile => { GetColorTile[]; PDInterpBitmap.TransferTile[band.Clip[rectangle], cachedColorTile, [xor, complement]]; }; transparentTile => ERROR; <> ENDCASE => ERROR; }; DO commandBuffer: CommandBuffer _ PDInterpReader.Get[handle]; WITH commandBuffer SELECT FROM stateChange: CommandBuffer.stateChange => { SELECT stateChange.whatChanged FROM imageStart => { band _ PDInterpOutput.StartImage[handle.herald, handle.image]; }; imageEnd => { PDInterpOutput.EndImage[]; RETURN [TRUE]; }; priorityChange => { <> }; colorChange => NULL; bandChange => { band _ PDInterpOutput.EndBand[]; }; loadChange => NULL; documentEnd => RETURN [FALSE]; ENDCASE => ERROR; }; maskRectangle: CommandBuffer.maskRectangle => { TransferRectangle[[maskRectangle.sMin, maskRectangle.fMin, maskRectangle.sSize, maskRectangle.fSize]]; }; maskTrapezoid: CommandBuffer.maskTrapezoid => { }; maskRunGroup: CommandBuffer.maskRunGroup => { s: CARDINAL _ maskRunGroup.sMin; sMinBand: CARDINAL _ MIN[band.sOrigin+band.sMin, maskRunGroup.sMin+maskRunGroup.sSize]; sMaxBand: CARDINAL _ MIN[band.sOrigin+band.sMin+band.sSize, maskRunGroup.sMin+maskRunGroup.sSize]; run: LONG POINTER TO PDFileFormat.Run _ maskRunGroup.pointer; TempColor[[maskRunGroup.sMin, maskRunGroup.fMin, maskRunGroup.sSize, maskRunGroup.fSize]]; WHILE s < sMinBand DO IF run.lastRun THEN s _ s + 1; run _ run + SIZE[PDFileFormat.Run]; ENDLOOP; WHILE s < sMaxBand DO PDInterpBitmap.Fill[band, [s, run.fMin+maskRunGroup.fOffset, 1, run.fSize], 1]; IF run.lastRun THEN s _ s + 1; run _ run + SIZE[PDFileFormat.Run]; ENDLOOP; TempColor[[maskRunGroup.sMin, maskRunGroup.fMin, maskRunGroup.sSize, maskRunGroup.fSize]]; }; maskSamples: CommandBuffer.maskSamples => { rectangle: PDInterpBitmap.Rectangle _ PDInterpBitmap.Window[maskSamples.samples]; TempColor[rectangle]; PDInterpBitmap.Transfer[band, maskSamples.samples, [or, null]]; TempColor[rectangle]; }; colorSamples: CommandBuffer.colorSamples => { PDInterpBitmap.Transfer[band, colorSamples.samples]; }; deviceCommand: CommandBuffer.deviceCommand => { }; ENDCASE => NULL; ENDLOOP; }; scratchPointer: LONG POINTER _ NIL; scratchWords: INT _ 0; scratchPages: INT = 4; scratchSpace: Space.Handle _ Space.Create[size: scratchPages, parent: Space.virtualMemory]; Space.Map[scratchSpace]; scratchPointer _ Space.LongPointer[scratchSpace]; scratchWords _ scratchPages*Environment.wordsPerPage; END.