PDInterpOutputAISImpl.mesa
Copyright (C) 1984, 1985, Xerox Corporation. All rights reserved.
Implements a Cedar PD output device that makes ais files.
Michael Plass, July 3, 1985 11:12:19 am PDT
Tim Diebert: September 18, 1985 10:01:28 am PDT
Dave Rumph, September 27, 1985 2:55:00 pm PDT
Eric Nickell, August 21, 1986 3:42:19 pm PDT
DIRECTORY
PDInterpOutput,
AIS USING [Buffer, CloseFile, CreateFile, FRef, OpenWindow, RasterPart, UnsafeWriteLine, WRef, WriteComment],
Basics USING [BITSHIFT],
FS USING [ExpandName, ComponentPositions],
ImagerPixelMap USING [Clear, Clip, Create, PixelMap, Reshape, Transfer],
IO USING [PutFR1, rope],
PDFileFormat USING [Herald, StartImage, Toner],
PDInterpBitmap USING [BitmapDesc],
PDQueue USING [LogMessage, Request],
Rope USING [Concat, ROPE, Substr],
ViewerClasses USING [Viewer];
PDInterpOutputAISImpl: PROGRAM
IMPORTS AIS, Basics, ImagerPixelMap, IO, FS, PDQueue, Rope
EXPORTS PDInterpOutput
= BEGIN
viewer: ViewerClasses.Viewer ← NIL;
ROPE: TYPE ~ Rope.ROPE;
Toner: TYPE ~ PDFileFormat.Toner;
pageMap: PUBLIC ImagerPixelMap.PixelMap ← [0, 0, 0, 0, 0, 0, NIL];
currentStartImage: PDFileFormat.StartImage;
currentHerald: PDFileFormat.Herald;
bandNumber: NAT ← 0;
currentToner: PUBLIC Toner ← cyan;
print: BOOLTRUE;
feed, strip: BOOLFALSE;
StartImage: PUBLIC PROC [herald: PDFileFormat.Herald, startImage: PDFileFormat.StartImage, request: PDQueue.Request]
RETURNS [PDInterpBitmap.BitmapDesc] = {
bandMap: ImagerPixelMap.PixelMap;
feed ← startImage.feed;
strip ← startImage.strip;
currentToner ← startImage.toner;
PDQueue.LogMessage[message: IO.PutFR1["Getting storage for %g",
IO.rope[(SELECT startImage.toner FROM
black => "black", cyan => "cyan", magenta => "magenta", yellow => "yellow",
ENDCASE => ERROR)]], userName: request.requestor];
IF (pageMap.sSize # herald.imageSSize) OR (pageMap.fSize # herald.imageFSize) THEN pageMap ← ImagerPixelMap.Reshape[pageMap.refRep, 0, [0, 0, herald.imageSSize, herald.imageFSize]];
ImagerPixelMap.Clear[pageMap];
PDQueue.LogMessage[message: "Making bitmap ... ", userName: request.requestor];
currentStartImage ← startImage;
currentHerald ← herald;
bandNumber ← 0;
bandMap ← ImagerPixelMap.Clip[pageMap, [startImage.passBands*herald.bandSSize, startImage.fMinPage, herald.bandSSize, startImage.fSizePage]];
RETURN [[
sOrigin: bandMap.sOrigin,
fOrigin: bandMap.fOrigin,
sMin: bandMap.sMin,
fMin: bandMap.fMin,
sSize: bandMap.sSize,
fSize: bandMap.fSize,
pointer: bandMap.refRep.pointer,
rast: bandMap.refRep.rast,
lines: bandMap.refRep.lines
]]
};
EndBand: PUBLIC PROC RETURNS [PDInterpBitmap.BitmapDesc] = {
bandMap: ImagerPixelMap.PixelMap;
bandNumber ← bandNumber + 1;
bandMap ← ImagerPixelMap.Clip[pageMap, [(currentStartImage.passBands+bandNumber)*currentHerald.bandSSize, currentStartImage.fMinPage, currentHerald.bandSSize, currentStartImage.fSizePage]];
RETURN [[
sOrigin: bandMap.sOrigin,
fOrigin: bandMap.fOrigin,
sMin: bandMap.sMin,
fMin: bandMap.fMin,
sSize: bandMap.sSize,
fSize: bandMap.fSize,
pointer: bandMap.refRep.pointer,
rast: bandMap.refRep.rast,
lines: bandMap.refRep.lines
]]
};
EndImage: PUBLIC PROC [request: PDQueue.Request] = {
sepName: ROPE ← MakeName[request.fileName, currentToner];
PDQueue.LogMessage[message: IO.PutFR1["Writing %g", IO.rope[sepName]], userName: request.requestor];
StorePixelMap[sepName, pageMap];
PDQueue.LogMessage[message: "Done", userName: request.requestor];
};
MakeName: PROC [file: ROPE, toner: Toner] RETURNS [r: ROPE] = BEGIN
cp: FS.ComponentPositions;
[cp: cp, fullFName: r] ← FS.ExpandName[file];
r ← Rope.Substr[r, 0, cp.ext.start-1];
r ← Rope.Concat[r, (SELECT toner FROM black => "-k.ais", cyan => "-c.ais", magenta => "-m.ais", yellow => "-y.ais", ENDCASE => ERROR)];
END;
ReprintLastPage: PUBLIC PROC [copies: CARDINAL] = {};
StorePixelMap: PROC [aisFileName: ROPE, source: ImagerPixelMap.PixelMap, bitmap: BOOLEANTRUE, comment: ROPENIL] ~ TRUSTED {
output: AIS.FRef ← AIS.CreateFile[name: aisFileName, raster: NEW[AIS.RasterPart ← [
scanCount: source.sSize,
scanLength: source.fSize,
scanMode: IF source.sSize > source.fSize THEN rd ELSE ur,
bitsPerPixel: IF source.refRep.lgBitsPerPixel = 0 AND bitmap THEN 1 ELSE Basics.BITSHIFT[1, source.refRep.lgBitsPerPixel],
linesPerBlock: -1,
paddingPerBlock: 65535
]]];
outputWindow: AIS.WRef ← AIS.OpenWindow[output];
lineMap: ImagerPixelMap.PixelMap ← ImagerPixelMap.Create[source.refRep.lgBitsPerPixel, [source.sOrigin+source.sMin, source.fOrigin+source.fMin, 1, source.fSize]];
lineBufferDesc: AIS.Buffer ← [length: lineMap.refRep.words, addr: lineMap.refRep.pointer];
AIS.WriteComment[output, comment];
FOR i: NAT IN [0..source.sSize) DO
lineMap.Clear;
lineMap.Transfer[source];
lineMap.sOrigin ← lineMap.sOrigin + 1;
AIS.UnsafeWriteLine[outputWindow, lineBufferDesc, i];
ENDLOOP;
AIS.CloseFile[output];
};
currentHerald.password ← 0;
END.