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: BOOL ← TRUE;
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]];
}.