DunnCommandsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Plass and Bloomenthal, January 30, 1987 11:50:10 pm PST
DIRECTORY Args, CedarProcess, ColorTrixBasics, ColorTrixFile, ColorTrixMap, Commander, Dunn, Imager, ImagerColorMap, ImagerSmooth, InterminalBackdoor, Interpress, IO, MessageWindow, Process, Rope, Terminal;
DunnCommandsImpl: CEDAR PROGRAM
IMPORTS Args, CedarProcess, ColorTrixBasics, ColorTrixFile, ColorTrixMap, Commander, Dunn, Imager, ImagerSmooth, InterminalBackdoor, Interpress, MessageWindow, Process, Rope, Terminal
~ BEGIN
ROPE:      TYPE ~ Rope.ROPE;
Context:     TYPE ~ Imager.Context;
Handle:     TYPE ~ Dunn.Handle;
screenPixelsPerMeter: REAL ← 72/0.0254;
Snapping Procedures:
colorAtom: ARRAY ImagerColorMap.Gun OF ATOM ~ [$Red, $Green, $Blue];
SnapIpFile: PROC [h: Handle, name: ROPE, page, npages: INT ← -1] RETURNS [BOOL] ~ {
p0, p1: INT;
cm: ColorTrixMap.Cmap ← NIL;
vt: Terminal.Virtual ← InterminalBackdoor.terminal;
cmSave: ColorTrixMap.Cmap ← ColorTrixMap.Read[];
cd: Imager.Context ~ ColorTrixBasics.InitCd[smooth, FALSE, FALSE, FALSE];
master: Interpress.Master ~ ColorTrixFile.OpenInterpress[name];
IF master = NIL THEN RETURN[FALSE];
p0 ← MAX[1, MIN[page, master.pages]];
p1 ← IF npages >= 0 AND npages <= master.pages THEN p0+npages-1 ELSE master.pages;
FOR p: INT IN [p0..p1] DO
FOR gun: ImagerColorMap.Gun IN ImagerColorMap.Gun DO
ENABLE UNWIND => {[] ← Dunn.Composite[h]; [] ← Dunn.Expose[h]};
Action: PROC ~ {Interpress.DoPage[master, p, cd, ]};
ImagerSmooth.SetComponent[cd, colorAtom[gun]];
Process.CheckForAbort[];
ColorTrixMap.PrimaryOnly[gun, cm ← ColorTrixMap.Copy[cmSave, cm]];
ColorTrixMap.Write[cm];
IF gun = red THEN Terminal.TurnOnColorDisplay[vt];
Imager.DoSaveAll[cd, Action];
IF NOT Dunn.Expose[h] THEN RETURN[FALSE];
ENDLOOP;
ENDLOOP;
ColorTrixMap.Write[cmSave];
RETURN[TRUE];
};
SnapColorFiles: PROC [h: Handle, red, grn, blu: ROPE] RETURNS [BOOL] ~ {
cm: ColorTrixMap.Cmap ← NIL;
cmSave: ColorTrixMap.Cmap ← ColorTrixMap.Read[];
vt: Terminal.Virtual ← InterminalBackdoor.terminal;
cd: Imager.Context ← ColorTrixBasics.InitCd[gray, TRUE, TRUE, FALSE];
FOR gun: ImagerColorMap.Gun IN ImagerColorMap.Gun DO
ENABLE UNWIND => {[] ← Dunn.Composite[h]; [] ← Dunn.Expose[h]};
name: ROPESELECT gun FROM red => red, green => grn, blue => blu, ENDCASE => NIL;
ColorTrixMap.PrimaryOnly[gun, cm ← ColorTrixMap.Copy[cmSave, cm]];
ColorTrixMap.Write[cm];
IF gun = red THEN Terminal.TurnOnColorDisplay[vt];
IF NOT SnapGrayFile[h, name, cd] THEN RETURN[FALSE];
ENDLOOP;
ColorTrixMap.Write[cmSave];
RETURN[TRUE];
};
SnapGrayFile: PROC [h: Handle, name: ROPE, cd: Context ← NIL] RETURNS [BOOL] ~ {
RETURN[ColorTrixFile.ViewGrayFile[name, cd, FALSE, FALSE] = NIL AND Dunn.Expose[h]];
};
Commander Procedures:
snapUsage: ROPE
"DunnSnap <color-ais-root-name | full-ais-name | interpress name> [-option]
 Display image on the color display; expose with Dunn camera.
 Images are un-scaled, those larger than 1024 by 768 are clipped.
 options:
  -cmap <colormap>
  -display <Dorado name -- defaults to Reprisal>
  -gamma <value>
  -page <interpress page number to start>
  -npages <interpress number of pages>";
DunnSnap: Commander.CommandProc ~ {
ok: BOOLTRUE;
page, npages: INT ← -1;
handle: Handle ← NIL;
type: ColorTrixFile.FileType;
err, name1, name2, name3: ROPE ← NIL;
nameArg, pageArg, npagesArg, cmapArg, gammaArg, displayArg: Args.Arg;
[ok, nameArg, pageArg, npagesArg, cmapArg, gammaArg, displayArg] ←
Args.ArgsGet[cmd, "%s-page%i-npages%i-cmap%s-gamma%r-display%s"];
IF NOT ok THEN RETURN[$Failure, snapUsage];
[type, name1, name2, name3] ← ColorTrixFile.Parse[nameArg.rope];
IF type = bad THEN RETURN[$Failure, Rope.Concat["Bad name: ", nameArg.rope]];
{ -- this scoping to service user abort
ENABLE UNWIND => {Dunn.Close[handle]};
handle ← Dunn.Open[NIL, IF displayArg.ok THEN displayArg.rope ELSE NIL];
IF cmapArg.ok AND NOT ColorTrixMap.Load[cmapArg.rope]
THEN RETURN[$Failure, Rope.Concat["Bad colormap: ", cmapArg.rope]];
IF gammaArg.ok THEN ColorTrixMap.Gamma[gammaArg.real];
IF NOT cmapArg.ok AND NOT gammaArg.ok THEN ColorTrixMap.Gamma[2.2];
IF pageArg.ok THEN page ← pageArg.int;
IF npagesArg.ok THEN npages ← npagesArg.int;
IF type = ip OR type = color
THEN {ok ← Dunn.Separate[handle] AND Dunn.Color[handle]}
ELSE {ok ← Dunn.Composite[handle] AND Dunn.BW[handle]};
IF NOT ok THEN RETURN[$Failure, "Dunn fails to initialize properly"];
CedarProcess.SetPriority[background];
SELECT type FROM
ip   => ok ← SnapIpFile[handle, name1, page, npages];
bw   => ok ← SnapGrayFile[handle, name1];
color   => ok ← SnapColorFiles[handle, name1, name2, name3];
ENDCASE;
Dunn.Close[handle];
};
MessageWindow.Clear[];
IF NOT ok THEN RETURN[$Failure, "Error in snapping file."];
};
Commander.Register["///Commands/DunnSnap", DunnSnap, Rope.Cat["\n", snapUsage]];
END.