DunnSnap: Commander.CommandProc ~ {
ok: BOOL ← TRUE;
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]];