DunnCommandsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Plass and Bloomenthal, May 13, 1986 6:19:39 pm PDT
DIRECTORY Args, ColorTrixBasics, ColorTrixFile, ColorTrixMap, Commander, Dunn, Imager, ImagerColorMap, ImagerSmooth, InterminalBackdoor, Interpress, IO, MessageWindow, Process, PupDefs, Rope, Terminal;
DunnCommandsImpl: CEDAR PROGRAM
IMPORTS Args, ColorTrixBasics, ColorTrixFile, ColorTrixMap, Commander, Dunn, Imager, ImagerSmooth, InterminalBackdoor, Interpress, MessageWindow, Process, PupDefs, Rope, Terminal
~ {
ROPE:      TYPE ~ Rope.ROPE;
Context:     TYPE ~ Imager.Context;
screenPixelsPerMeter: REAL ← 72/0.0254;
Snapping Procedures:
colorAtom: ARRAY ImagerColorMap.Gun OF ATOM ~ [$Red, $Green, $Blue];
GetHandle: PROC RETURNS [err: ROPE ← NIL, handle: Dunn.Handle] ~ {
IF PupDefs.GetMyName[].Equal["Reprisal"] THEN [handle, err] ← Dunn.Reserve[]
ELSE {
MessageWindow.Append["Pretending to snap; use Reprisal to actually snap.", TRUE];
MessageWindow.Blink[];
handle ← Dunn.Pretend[];
};
};
SnapIpFile: PROC [h: Dunn.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.OpenMaster ~ 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: master, page: p, context: cd]};
ImagerSmooth.SetComponent[cd, colorAtom[gun]];
ColorTrixBasics.ClearVt[vt, 255];
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: Dunn.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: Dunn.Handle, name: ROPE, cd: Context ← NIL] RETURNS [BOOL] ~ {
RETURN[ColorTrixFile.ViewGrayFile[name, cd, FALSE] AND Dunn.Expose[h]];
};
Commander Procedures:
viewUsage: ROPE
"DunnView <ais or interpress filename> [-dither]
 Display image on the color display.
 Images are un-scaled, those larger than 1024 by 768 are clipped.
 -dither forces the image to be displayed with a dither map
 Gray ramp used if BW-ais or one component of ais triplet.
 Dither colormap used if interpress or ais triplet.";
snapUsage: ROPE
"DunnSnap <ais or interpress filename> [-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>
  -gamma <value>
  -page <interpress page number to start>
  -npages <interpress number of pages>";
DunnView: Commander.CommandProc ~ {
ok, dither: BOOL;
name1, name2, name3: ROPE;
type: ColorTrixFile.FileType;
nameArg, ditherArg: Args.Arg;
[ok, nameArg, ditherArg] ← Args.ArgsGet[cmd, "%s-dither%b"];
IF NOT ok THEN RETURN[$Failure, viewUsage];
dither ← ditherArg.ok AND ditherArg.bool;
[type, name1, name2, name3] ← ColorTrixFile.Parse[nameArg.rope];
SELECT type FROM
ip   => ok ← ColorTrixFile.ViewIpFile[name1];
bw   => ok ← IF dither
     THEN ColorTrixFile.ViewDitherFile[name1]
     ELSE ColorTrixFile.ViewGrayFile[name1];
color   => ok ← ColorTrixFile.ViewColorFiles[name1, name2, name3];
ENDCASE => RETURN [$Failure, Rope.Cat["Bad name: ", nameArg.rope]];
IF NOT ok THEN RETURN[$Failure, "Error in viewing file."];
};
DunnSnap: Commander.CommandProc ~ {
ok: BOOLTRUE;
page, npages: INT ← -1;
handle: Dunn.Handle ← NIL;
type: ColorTrixFile.FileType;
err, name1, name2, name3: ROPE ← NIL;
nameArg, pageArg, npagesArg, cmapArg, gammaArg: Args.Arg;
[ok, nameArg, pageArg, npagesArg, cmapArg, gammaArg] ←
Args.ArgsGet[cmd, "%s-page%i-npages%i-cmap%s-gamma%r"];
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]};
[err, handle] ← GetHandle[];
IF err # NIL THEN RETURN[$Failure, Rope.Concat[err, "Dunn not reserved."]];
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"];
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/DunnView", DunnView, Rope.Cat["\n", viewUsage]];
Commander.Register["///Commands/DunnSnap", DunnSnap, Rope.Cat["\n", snapUsage]];
}.
..
Cf: /Ark-Royal/Cedar/Users/Lamming.pa/DunnCommsTest.mesa.
SnapIpFile: PROC [h: Dunn.Handle, name: ROPE, s: IO.STREAM] RETURNS [BOOLTRUE] ~ {
master: Interpress.OpenMaster ~ OpenInterpress[name, s];
IF master = NIL THEN RETURN[FALSE];
FOR page: INT IN [1..master.pages] DO -- won't quite work cause need to get handle
action: PROC [context: Imager.Context] ~ {
Interpress.DoPage[master: master, page: page, context: context];
};
Dunn.Snapper[action: action, pixelUnits: FALSE, color: TRUE, smooth: TRUE];
ENDLOOP;
};