IF Rope.Match["-*", arg]
THEN {
Switch processing
SELECT
TRUE
FROM
Rope.Match["-debug", arg, FALSE] => debugging ¬ TRUE;
Rope.Match["-times", arg, FALSE] => showTimes ¬ TRUE;
Rope.Match["-notimes", arg, FALSE] => showTimes ¬ FALSE;
Rope.Match["-ps", arg, FALSE] => forceKind ¬ postscript;
Rope.Match["-ip", arg, FALSE] => forceKind ¬ interpress;
Rope.Match["-genoa", arg, FALSE] => forceKind ¬ genoa;
Rope.Match["-auto", arg, FALSE] => forceKind ¬ unknown;
Rope.Match["-portrait", arg, FALSE] => portrait ¬ TRUE;
Rope.Match["-monitor", arg, FALSE] => useMonitor ¬ TRUE;
Rope.Match["-Hb", arg,
FALSE] =>
highlight ¬ ImagerColor.ColorFromRGB[ [R: 0, G: 0, B: 1] ];
Rope.Match["-Hg", arg,
FALSE] =>
highlight ¬ ImagerColor.ColorFromRGB[ [R: 0, G: 1, B: 0] ];
Rope.Match["-Hr", arg,
FALSE] =>
highlight ¬ ImagerColor.ColorFromRGB[ [R: 1, G: 0, B: 0] ];
Rope.Match["-table", arg,
FALSE] =>
TRUSTED {
name: ROPE ~ argv[1];
stream: IO.STREAM = ImagerSys.OpenInputFile[name ! ImagerSys.FileError => CommanderOps.Failed[explanation]];
IF stream =
NIL
THEN CommanderOps.Failed[Rope.Concat[name, " file missing"]]
ELSE {
t: REF ImagerHighlightContextBackdoor.ColorLookupArray ~ NEW[ImagerHighlightContextBackdoor.ColorLookupArray]; -- should use the right zone for this.
nBytes: NAT = BYTES[ImagerHighlightContextBackdoor.ColorLookupArray];
bytesRead: INT ~ IO.UnsafeGetBlock[stream, [base: LOOPHOLE[t], startIndex: 0, count: nBytes]];
IF bytesRead #
BYTES[ImagerHighlightContextBackdoor.ColorLookupArray]
THEN { CommanderOps.Failed[Rope.Concat[name, ": table file is too short"]];
};
colorLookupTable ¬
NEW[ImagerHighlightContextBackdoor.ColorLookupTableRep ¬ [
toner: Atom.MakeAtom[name],
tablePointer: LOOPHOLE[t],
ref: t
]];
IO.Close[stream];
ShiftArgs[];
};
};
Rope.Match["-combined", arg, FALSE] => combined ¬ TRUE;
Rope.Match["-separate", arg, FALSE] => combined ¬ FALSE;
Rope.Match["-switch", arg, FALSE] => switch ¬ TRUE;
Rope.Match["-out", arg,
FALSE] =>
IF argMax >= 1
THEN {
name: ROPE ¬ argv[1];
ShiftArgs[];
IF ipOut # NIL THEN {ImagerInterpress.Close[ipOut]; ipOut ¬ NIL};
ipOut ¬ ImagerInterpress.Create[name !
ImagerSys.FileError => {msg ¬ explanation; GO TO failed};
Imager.Error => {msg ¬ error.explanation; GO TO failed};
];
};
Rope.Match["-height", arg,
FALSE] => {
heightInches ¬ Convert.RealFromRope[CommanderOps.NextArgument[cmd]];
};
Rope.Match["-width", arg,
FALSE] => {
widthInches ¬ Convert.RealFromRope[CommanderOps.NextArgument[cmd]];
};
Rope.Match["-copies", arg,
FALSE] => {
syntax: BOOL ¬ FALSE;
copies ¬ 0;
IF argMax >= 1
THEN
copies ¬ Convert.CardFromRope[argv[1]
! Convert.Error => {syntax ¬ TRUE; CONTINUE}];
IF copies
NOT
IN [1..maxCopies]
THEN {
IF syntax
THEN IO.PutRope[cmd.out, "Can't parse nCopies number, 1 used\n"]
ELSE IO.PutF1[cmd.out, "Unacceptable nCopies (%g), 1 used\n", [integer[copies]] ];
copies ¬ 1;
};
ShiftArgs[];
allowCopiesToChange ¬ FALSE;
};
Rope.Match["-spi", arg,
FALSE] => {
syntax: BOOL ¬ FALSE;
spi ¬ 0;
IF argMax >= 1
THEN
spi ¬ Convert.CardFromRope[argv[1]
! Convert.Error => {syntax ¬ TRUE; CONTINUE}];
IF spi < 1
OR spi > 1200
THEN {
IF syntax
THEN IO.PutRope[cmd.out, "Can't parse spi number, 300 used\n"]
ELSE IO.PutF1[cmd.out, "Unacceptable spi (%g), 300 used\n", [integer[spi]] ];
spi ¬ 300;
};
ShiftArgs[];
};
Rope.Match["-iot", arg,
FALSE] => {
syntax: BOOL ¬ FALSE;
iotparam ¬ NIL;
IF argMax >= 1 THEN iotparam ¬ argv[1] ELSE syntax ¬ TRUE;
ShiftArgs[];
};
Rope.Match["-pph", arg,
FALSE] => {
syntax: BOOL ¬ FALSE;
pph ¬ 0.0;
IF argMax >= 1
THEN
pph ¬ Convert.RealFromRope[argv[1]
! Convert.Error => {syntax ¬ TRUE; CONTINUE}];
IF syntax
OR pph < 0.1
OR pph > 1000.0
THEN {
IF syntax
THEN IO.PutRope[cmd.out, "Can't parse pph number, 10.0 used\n"]
ELSE IO.PutF1[cmd.out, "Unacceptable pph (%g), 10.0 used\n", [real[spi]] ];
pph ¬ 10.0;
};
ShiftArgs[];
};
ENDCASE => CommanderOps.Failed[cmd.procData.doc];
LOOP;
};
{
ENABLE ImagerSys.FileError => {msg ¬ explanation; GO TO oops};
fInches: REAL = IF portrait THEN widthInches ELSE heightInches;
sInches: REAL = IF portrait THEN heightInches ELSE widthInches;
wordsWide: NAT = (Real.Ceiling[spi*fInches]+BITS[WORD]-1) / BITS[WORD];
fSizeBuffer: NAT = wordsWide*BITS[WORD]; -- for single bit per pixel
scanLines: NAT = Real.Ceiling[spi*sInches];
words: INT ~ wordsWide*scanLines; -- for single bit per pixel
handle1: CountedVM.Handle ¬ outerHandle1 ¬ AllocBuffer[2*words];
handle2: CountedVM.Handle ¬ outerHandle2 ¬ AllocBuffer[words];
out: STREAM = cmd.out;
fileName: Rope.ROPE ¬ arg;
map: RasterSampleMap
¬ MakeSampleMap[handle1, scanLines, fSizeBuffer, 2];
dMap: RasterSampleMap
¬ MakeSampleMap[handle2, scanLines, fSizeBuffer, 1];
scanMode: Imager.ScanMode = IF portrait THEN [slow: down, fast: right] ELSE [slow: right, fast: up];
context: Context ¬ HighlightContextFromSampleMap[map, spi, pph, highlight, colorLookupTable, iotparam, scanMode];
fileStream: IO.STREAM ¬ NIL;
fileKind: FileKind ¬ unknown;
pixelsToMeters: ImagerTransformation.Transformation = ImagerBackdoor.GetTransformation[context: context, from: device, to: client];
DoSeparations:
PROC = {
PageAction1:
PROC [context: Imager.Context] ~ {
Imager.ConcatT[context, pixelsToMeters];
Imager.SetGray[context, 1];
ImageSeparation[context, TRUE, map, dMap];
Imager.SetColor[context, highlight];
ImageSeparation[context, FALSE, map, dMap];
};
IF switch THEN SwitchColors[map];
SELECT
TRUE
FROM
ipOut =
NIL => {};
Just for timing
combined =>
For shipping to a Siena as a combined map
ImagerInterpress.DoPage[ipOut, PageAction1, 1];
ENDCASE => {
PageAction2:
PROC [context: Imager.Context] ~ {
Imager.ConcatT[context, pixelsToMeters];
Imager.SetPriorityImportant[context, FALSE];
ImageSeparation[context, isBlack, map, dMap];
};
isBlack: BOOL ¬ TRUE;
For shipping to IP printers as separations
ImagerInterpress.DoPage[ipOut, PageAction2, 1];
isBlack ¬ FALSE;
ImagerInterpress.DoPage[ipOut, PageAction2, 1];
};
};
Require:
PROC [rope:
ROPE] ~ {
[] ¬ CommanderOps.DoCommand[Rope.Cat["Require Cedar ", rope, " ", rope], cmd];
};
instanceData: DecomposerRegistry.InstanceData ¬ NIL;
best: DecomposerRegistry.DecomposerData ¬ NIL;
prob: REAL ¬ 0.0;
sequencerProcs:
REF DecomposerRegistry.SequencerProcs ~
NEW[DecomposerRegistry.SequencerProcs ¬ [
feedback: NVFeedbackProc,
getAttr: NVGetAttrProc,
setAttr: NVSetAttrProc
]];
streamIn: IO.STREAM = ImagerSys.OpenInputFile[fileName];
seq: DecomposerRegistry.SequencerData ¬
NEW[DecomposerRegistry.SequencerDataRep ¬ [
in: streamIn,
out: cmd.out,
err: cmd.err,
title: fileName,
file: ImagerSys.StreamFileName[streamIn],
procs: sequencerProcs,
private: RefTab.Create[]
]];
IF Rope.Match["*.ip*", fileName, FALSE] THEN Require["IPRegister"];
IF Rope.Match["*.interpress*", fileName, FALSE] THEN Require["IPRegister"];
IF Rope.Match["*.cip*", fileName, FALSE] THEN Require["IPRegister"];
IF Rope.Match["*.ps*", fileName, FALSE] THEN Require["PSRegister"];
FOR tail:
LIST
OF DecomposerRegistry.DecomposerData ¬ DecomposerRegistry.Enumerate[], tail.rest
UNTIL tail =
NIL
DO
d: DecomposerRegistry.DecomposerData ~ tail.first;
p: REAL ~ d.procs.guess[d, seq];
IF p > prob THEN {prob ¬ p; best ¬ d};
ENDLOOP;
IF best =
NIL
THEN {CommanderOps.Failed[Rope.Concat["could not guess file type of ", fileName]]}
ELSE {
instanceData ¬ best.procs.open[best, seq];
IF instanceData = NIL THEN CommanderOps.Failed["Failed to open"];
IF instanceData #
NIL
THEN {
instanceData.copies ¬ 1;
instanceData.copy ¬ 1;
instanceData.pages ¬ -1;
instanceData.procs.attributes[instanceData];
};
};
{
seconds: REAL = BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[] - startPulses];
IO.PutF1[out, "%4.2f elapsed seconds to alloc map and open", [real[seconds]]];
IO.PutF1[out, " %g\n", [rope[fileName]]];
startPulses ¬ BasicTime.GetClockPulses[];
};
SELECT fileKind
FROM
unknown => {
ENABLE {
UNWIND => Bye[];
Imager.Warning => {
IO.PutF[cmd.out, "-- Imager.Warning: %g, %g\n",
[atom[ImagerError.AtomFromErrorCode[error.code]]], [rope[error.explanation]]];
RESUME;
};
Imager.Error => {
IO.PutF[cmd.out, "\n** Imager.Error: %g, %g\n",
[atom[ImagerError.AtomFromErrorCode[error.code]]], [rope[error.explanation]]];
IF NOT debugging THEN GO TO Out;
};
IO.EndOfStream,
IO.Error => {
IO.PutRope[out, "\n** Unknown IO Error\n"];
IF NOT debugging THEN GO TO Out;
};
ImagerSys.FileError => {
IO.PutF[cmd.out, "\n** ImagerSys.FileError inside of master: %g, %g\n",
[atom[code]], [rope[explanation]]];
IF NOT debugging THEN GO TO Out;
};
};
IO.PutF1[out, "file: %g", [rope[fileName]] ];
IO.PutF1[out, ", spi: %g", [cardinal[spi]] ];
IO.PutF1[out, ", copies: %g\n", [cardinal[copies]] ];
FOR j:
INT
IN [1 .. copies]
DO
pageCount: INT ¬ 0;
done: BOOL ¬ FALSE;
IO.PutF1[out, "Copy %g: ", [cardinal[j]] ];
instanceData.copy ¬ j;
FOR i:
INT
IN [1..999999)
UNTIL done
DO
pageFlags: DecomposerRegistry.PageFlags;
pagePulses: BasicTime.Pulses ¬ BasicTime.GetClockPulses[];
Process.CheckForAbort[];
ImagerSample.Clear[map];
instanceData.page ¬ i;
{
P:
PROC ~ {
instanceData.context ¬ context;
pageFlags ¬ instanceData.procs.page[instanceData, instanceData.page, instanceData.copy];
}; Imager.DoSaveAll[context, P] };
IF pageFlags.last THEN done ¬ TRUE;
IF pageFlags.imaged
THEN {
IO.PutF1[out, " [%g", [cardinal[i]] ];
pageCount ¬ pageCount + 1;
DoSeparations[];
IO.PutChar[out, ']];
IF showTimes
THEN {
endPagePulses: BasicTime.Pulses ¬ BasicTime.GetClockPulses[];
seconds: REAL = BasicTime.PulsesToSeconds[endPagePulses-pagePulses];
IO.PutF1[out, " (%4.2f)", [real[seconds]] ];
};
};
ENDLOOP;
IO.PutChar[out, '\n];
{
nextTime: BasicTime.Pulses = BasicTime.GetClockPulses[];
PerfLine[out, nextTime-startPulses, pageCount];
startPulses ¬ nextTime;
};
ENDLOOP;
instanceData.procs.close[instanceData];
GO TO Out;
EXITS Out => Bye[];
};
ENDCASE => {msg ¬ "Unknown page description language"; GO TO oops};
Bye[];
EXITS oops => {Bye[]; GO TO failed};
};