InterpressToPD:
PROC [inputName, outputName:
ROPE] ~ {
interpress: Interpress.Master ~ Interpress.Open[fileName: inputName, log: Log];
size: SF.Vec ~ [s: Real.Round[13.75*400], f: Real.Round[10.24*400]];
bitmap: ImagerSample.RasterSampleMap ~ ImagerSample.ObtainScratchMap[box: [max: size]];
context: Imager.Context ~ ImagerPrintContext.SimpleCreate[deviceSpaceSize: size, scanMode: [slow: down, fast: right], surfaceUnitsPerInch: [400, 400], logicalDevice: 9, pixelsPerHalftoneDot: pixelsPerHalftoneDot, toners: [black: TRUE, cyan: TRUE, magenta: TRUE, yellow: TRUE]];
bandSSize: NAT ← 50;
wordsPerLine: CARDINAL ~ (INT[size.f]+BITS[WORD]-1)/BITS[WORD];
bitsPerLine: NAT ~ wordsPerLine*BITS[WORD];
pdState: PDFileWriter.PDState ~ PDFileWriter.Create[fileName: outputName, deviceCode: VAL[9], sResolution: 400, fResolution: 400, imageSSize: size.s, imageFSize: size.f, bandSSize: bandSSize, copies: 1, leftOverMode: FALSE, maxLoadWords: 0];
pdTonerForPass: ARRAY [0..4) OF PDFileWriter.Toner ~ [yellow, magenta, cyan, black];
tonerForPass: ARRAY [0..4) OF PrintColor.Toner ~ [yellow, magenta, cyan, black];
ropeTonerForPass: ARRAY [0..4) OF Rope.ROPE ~ ["yellow", "magenta", "cyan", "black"];
ImagerPrintContext.SetBitmap[context: context, bitmap: bitmap];
FOR page:
INT
IN [1..interpress.pages]
DO
memory: Imager.Context ~ ImagerMemory.NewMemoryContext[];
Interpress.DoPage[master: interpress, page: page, context: memory, log: Log, copy: 1];
Log[Interpress.classComment, $page, IO.PutFR["page %g", [integer[page]]]];
FOR pass:
NAT
IN [0..4)
DO
tonerSet: PDFileWriter.TonerSet ← ALL[FALSE];
Log[Interpress.classComment, $pass, ropeTonerForPass[pass]];
tonerSet[pdTonerForPass[pass]] ← TRUE;
PDFileWriter.StartImage[pdState: pdState, toners: tonerSet, feed: pass=0, strip: pass=3];
ImagerPrintContext.SetSeparation[context, tonerForPass[pass]];
ImagerSample.Clear[bitmap];
ImagerMemory.Replay[c: memory, into: context];
FOR s:
NAT ← 0, s + bandSSize
UNTIL s >= size.s
DO
sMax: NAT ~ MIN[s+bandSSize, size.s];
sSize: NAT ~ sMax-s;
band: ImagerSample.RasterSampleMap ~ NARROW[ImagerSample.Clip[map: bitmap, box: [min: [s, 0], max: [sMax, size.f]]]];
Deliver:
PROC [doLine: PDFileWriter.CaptureScanLineProc] =
TRUSTED {
p: LONG POINTER ← ImagerSample.GetBase[band].word;
THROUGH [0..sSize)
DO
doLine[p];
p ← p + wordsPerLine;
ENDLOOP;
};
Process.CheckForAbort[];
IF writePD THEN PDFileWriter.MaskSamples[pdState: pdState, sMin: s, fMin: 0, sSize: sSize, fSize: size.f, deliverProc: Deliver];
TRUSTED { ImagerSample.ReleaseDescriptor[band] };
ENDLOOP;
PDFileWriter.EndPage[pdState];
ENDLOOP;
ENDLOOP;
PDFileWriter.Close[pdState: pdState];
ImagerSample.ReleaseScratchMap[bitmap];
};