ColorTrixCommandsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, May 12, 1986 1:33:59 pm PDT
DIRECTORY Args, ColorTrixBasics, ColorTrixMod, ColorTrixPalette, ColorTrixPix, Commander, ImagerPixelMap, Interminal, IO, Rope, Terminal, ViewerClasses;
ColorTrixCommandsImpl: CEDAR PROGRAM
IMPORTS Args, ColorTrixBasics, ColorTrixMod, ColorTrixPalette, ColorTrixPix, Commander, ImagerPixelMap, IO, Rope
~ {
PixelMap: TYPE ~ ImagerPixelMap.PixelMap;
palOn: BOOLFALSE;
initialW: ImagerPixelMap.DeviceRectangle ← ImagerPixelMap.Window[ColorTrixBasics.GetPm[]];
globalW: ImagerPixelMap.DeviceRectangle ← initialW;
ArgWindow: PROC [x, y, w, h: Args.Arg] RETURNS [ImagerPixelMap.DeviceRectangle] ~ {
RETURN[ImagerPixelMap.Intersect[initialW, [y.int, x.int, h.int, w.int]]];
};
GetWindowedPm: PROC [cmd: Commander.Handle] RETURNS [PixelMap] ~ {
x, y, w, h: Args.Arg;
window: ImagerPixelMap.DeviceRectangle ← globalW;
FOR n: NAT ← 0, n+1 WHILE n < Args.NArgs[cmd] DO
IF NOT Args.GetRope[cmd, n].Equal["-w"] THEN LOOP;
x ← Args.ArgInt[cmd, n+1];
y ← Args.ArgInt[cmd, n+2];
w ← Args.ArgInt[cmd, n+3];
h ← Args.ArgInt[cmd, n+4];
EXIT;
ENDLOOP;
IF x.ok AND y.ok AND w.ok AND h.ok THEN window ← ArgWindow[x, y, w, h];
RETURN[ImagerPixelMap.SetWindow[ColorTrixBasics.GetPm[], window]];
};
ResetWindow: Commander.CommandProc ~ {
globalW ← initialW;
};
SetWindow: Commander.CommandProc ~ {
ok: BOOL;
x, y, w, h: Args.Arg;
[ok, x, y, w, h] ← Args.ArgsGet[cmd, "%iiii"];
IF NOT ok THEN RETURN[$Failure, "Bad argument(s)."];
globalW ← ImagerPixelMap.Intersect[ArgWindow[x, y, w, h], initialW];
};
PrintWindow: Commander.CommandProc ~ {
cmd.out.PutF["global window is (x, y, w, h): [%g, %g, %g, %g].\n", IO.int[globalW.fMin], IO.int[globalW.sMin], IO.int[globalW.fSize], IO.int[globalW.sSize]];
};
Pal: Commander.CommandProc ~ {
ok: BOOL;
n, smooth, unpal: Args.Arg;
pm: PixelMap ← ColorTrixBasics.GetPm[];
[ok, n, smooth, unpal] ← Args.ArgsGet[cmd, "[i-s%b-u%b"];
IF NOT ok THEN RETURN[$Failure, "Bad argument(s)."];
IF unpal.bool THEN ColorTrixPalette.UnPal[ColorTrixBasics.GetPm[]];
ColorTrixPalette.Pal[pm, IF n.ok THEN n.int ELSE 5, smooth.ok AND smooth.bool];
palOn ← TRUE;
};
UnPal: Commander.CommandProc ~ {
IF palOn THEN ColorTrixPalette.UnPal[ColorTrixBasics.GetPm[]];
palOn ← FALSE;
};
GammaTest: Commander.CommandProc ~ {
FillChex: PROC [p: PixelMap, val: NAT] RETURNS [PixelMap] ~ {
w: ImagerPixelMap.DeviceRectangle ~ ImagerPixelMap.Window[p];
spacer, spacing: NAT ← 1;
ImagerPixelMap.Fill[p, w, IF val < 255 THEN 0 ELSE 255];
IF val = 0 OR val = 255 THEN RETURN[p];
spacing ← 256/val;
FOR y: NAT IN[w.sMin..w.sMin+w.sSize) DO
xx: INTEGER ← w.fMin+w.fSize-1;
FOR x: NAT IN [w.fMin..w.fMin+w.fSize) DO
IF (spacer ← spacer+1) = spacing THEN spacer ← 0;
IF spacer=0 THEN ImagerPixelMap.Fill[p, [y, IF y MOD 2 =0 THEN x ELSE xx,1,1],255];
xx ← xx-1;
ENDLOOP;
ENDLOOP;
RETURN[p];
};
pm: PixelMap ~ GetWindowedPm[cmd];
w: ImagerPixelMap.DeviceRectangle ~ ImagerPixelMap.Window[pm];
margin: NAT ~ w.fSize/32;
width: INTEGER ← (w.fSize/9)-margin;
x: NAT ← w.fMin+margin;
val: INTEGER ← 255;
chex: PixelMap ~ ImagerPixelMap.Create[3, [0, 0, 64, 64]];
ImagerPixelMap.Fill[pm, w, 127];
FOR i: NAT IN [0..8) DO
tile: ImagerPixelMap.Tile ← ImagerPixelMap.CreateTile[FillChex[chex, val]];
ImagerPixelMap.Fill[pm, [w.sMin+w.sSize/2, x, w.sSize/2, width], val];
ImagerPixelMap.TransferTile[ImagerPixelMap.Clip[pm, [w.sMin, x, w.sSize/2, width]], tile];
x ← x+width+margin;
IF (val ← val/2) < 3 THEN val ← 0;
ENDLOOP;
};
GammaTest: Commander.CommandProc ~ {
pm: PixelMap ← GetWindowedPm[cmd];
w: ImagerPixelMap.DeviceRectangle ← ImagerPixelMap.Window[pm];
margin: INTEGER ← w.fSize/32;
width: INTEGER ← (w.fSize/9)-margin;
x: INTEGER ← w.fMin+margin;
val: INTEGER ← 255;
checker: PixelMap ← ImagerPixelMap.Create[3, [
ImagerPixelMap.Fill[pm, w, 127];
FOR i: NAT IN [0..8) DO
ImagerPixelMap.Fill[pm, [w.sMin+w.sSize/2, x, w.sSize/2, width], val];
ColorTrixPix.Dither[ImagerPixelMap.SetWindow[pm, [w.sMin, x, w.sSize/2, width]], val];
x ← x+width+margin;
IF (val ← val/2) < 3 THEN val ← 0;
ENDLOOP;
};
Clear: Commander.CommandProc ~ {
ok: BOOL;
pVal, dum: Args.Arg;
pm: PixelMap ← GetWindowedPm[cmd];
w: ImagerPixelMap.DeviceRectangle ← ImagerPixelMap.Window[pm];
[ok, pVal, dum, dum, dum, dum] ← Args.ArgsGet[cmd, "[i-w%iiii"];
IF NOT ok THEN RETURN[$Failure, "Bad argument(s)."];
ImagerPixelMap.Fill[pm, w, MIN[255, MAX[0, INTEGER[IF pVal.ok THEN pVal.int ELSE 0]]]];
};
Lum: Commander.CommandProc ~ {
ColorTrixMod.Lum[GetWindowedPm[cmd]];
};
Ramp: Commander.CommandProc ~ {
ok: BOOL;
v, h, dum: Args.Arg;
[ok, v, h, dum, dum, dum, dum] ← Args.ArgsGet[cmd, "-v%b-h%b-w%iiii"];
IF NOT ok THEN RETURN[$Failure, "Bad argument(s)"];
IF h.bool THEN ColorTrixPix.RampH[GetWindowedPm[cmd]]
ELSE ColorTrixPix.RampV[GetWindowedPm[cmd]];
};
Pie: Commander.CommandProc ~ {
ColorTrixPix.Pie[GetWindowedPm[cmd]];
};
Up: Commander.CommandProc ~ {
arg: Args.Arg ← Args.ArgIntDef[cmd, 0, 0];
IF NOT arg.ok THEN RETURN[$Failure, "Bad argument."];
ColorTrixMod.Up[GetWindowedPm[cmd], arg.int];
};
Left: Commander.CommandProc ~ {
arg: Args.Arg ← Args.ArgIntDef[cmd, 0, 0];
IF NOT arg.ok THEN RETURN[$Failure, "Bad argument."];
ColorTrixMod.Left[GetWindowedPm[cmd], arg.int];
};
Negate: Commander.CommandProc ~ {
ColorTrixMod.Negate[GetWindowedPm[cmd]];
};
Reflect: Commander.CommandProc ~ {
ok: BOOL;
v, h, dum: Args.Arg;
[ok, v, h, dum, dum, dum, dum] ← Args.ArgsGet[cmd, "-v%b-h%b-w%iiii"];
IF NOT ok THEN RETURN[$Failure, "Bad argument(s)"];
IF h.bool THEN ColorTrixMod.ReflectH[GetWindowedPm[cmd]]
ELSE ColorTrixMod.ReflectV[GetWindowedPm[cmd]];
};
Mirror: Commander.CommandProc ~ {
pm: PixelMap ← GetWindowedPm[cmd];
ok: BOOL;
l, r, t, b, d: Args.Arg;
[ok, l, r, t, b, d, d, d, d] ← Args.ArgsGet[cmd, "-l%b-r%b-t%b-b%b-w%iiii"];
IF NOT ok THEN RETURN[$Failure, "Bad argument(s)"];
SELECT TRUE FROM
l.bool => ColorTrixMod.MirrorV[pm, TRUE];
r.bool => ColorTrixMod.MirrorV[pm, FALSE];
t.bool => ColorTrixMod.MirrorH[pm, TRUE];
b.bool => ColorTrixMod.MirrorH[pm, FALSE];
ENDCASE => ColorTrixMod.MirrorH[pm, FALSE];
};
PVal: Commander.CommandProc ~ {
List: TYPE ~ RECORD[first: NAT, rest: REF List];
n: NAT ← 0;
new, old: Args.Arg;
list: REF List ← NIL;
nArgs: NAT ← Args.NArgs[cmd];
WHILE n < nArgs DO
IF Args.GetRope[cmd, n].Equal["-w"] THEN {n ← n+5; LOOP};
IF new.ok THEN {
IF NOT (old ← Args.ArgInt[cmd, n]).ok THEN RETURN[$Failure, "Bad old value."];
list ← NEW[List ← [old.int, list]];
}
ELSE IF NOT (new ← Args.ArgInt[cmd, n]).ok THEN RETURN[$Failure, "Bad new value."];
n ← n+1;
ENDLOOP;
IF list # NIL THEN ColorTrixMod.PVal[GetWindowedPm[cmd], new.int, list];
};
Grid: Commander.CommandProc ~ {
ok: BOOL;
pval, spacing, lineWidth: Args.Arg;
pm: PixelMap ← GetWindowedPm[cmd];
pvalInt, spacingInt, lineWidthInt: INT;
[ok, pval, spacing, lineWidth] ← Args.ArgsGet[cmd, "-pVal%i-spacing%i-lineWidth%i"];
pvalInt ← IF ok AND pval.ok THEN pval.int ELSE 255;
spacingInt ← IF ok AND spacing.ok THEN spacing.int ELSE 40;
lineWidthInt ← IF ok AND lineWidth.ok THEN lineWidth.int ELSE 1;
FOR i: NAT ← 0, i+spacingInt WHILE i < pm.fSize DO
FOR j: NAT ← 0, j+1 WHILE j < pm.sSize DO
ImagerPixelMap.Fill[pm, [j, i, lineWidthInt, lineWidthInt], pvalInt];
ENDLOOP;
ENDLOOP;
FOR j: NAT ← 0, j+spacingInt WHILE j < pm.sSize DO
FOR i: NAT ← 0, i+1 WHILE i < pm.fSize DO
ImagerPixelMap.Fill[pm, [j, i, lineWidthInt, lineWidthInt], pvalInt];
ENDLOOP;
ENDLOOP;
};
Commander.Register["SetWindow", SetWindow, "\nSetWindow <x0 x1 y0 y1>."];
Commander.Register["ResetWindow", ResetWindow, "\nReset the window."];
Commander.Register["PrintWindow", PrintWindow, "\nPrint the window."];
Commander.Register["Pal", Pal, "\nDisplay palette (-s for smooth) (-u unpal)."];
Commander.Register["UnPal", UnPal, "\nRemove palette."];
Commander.Register["Negate", Negate, "\nNegate the image."];
Commander.Register["Reflect", Reflect, "\nReflect <h|v>."];
Commander.Register["Mirror", Mirror, "\nMirror <l|r|t|b>."];
Commander.Register["Left", Left, "\nLeft <val: integer pixels> Move image."];
Commander.Register["Up", Up, "\nUp <val: integer pixels> Move image."];
Commander.Register["Clear", Clear, "\nClear <val: INT>; clear the color display."];
Commander.Register["Lum", Lum, "\nConvert pseudo-colors to luminance."];
Commander.Register["Ramp", Ramp, "\nDisplay ramp (-h: horiz, -v: vertical)."];
Commander.Register["Grid", Grid, "\n[-pVal <INT>] [-spacing <INT>] [-lineWidth <INT>]."];
Commander.Register["Pie", Pie, "\n < Make a circular ramp (pie)."];
Commander.Register["PVal", PVal, "\nPVal <newVal> <oldVal> [oldVal] . . ."];
Commander.Register["GammaTest", GammaTest, "\nIf the monitor is properly gamma corrected, the dithered rectangles should appear to be as bright as their grayscale counterparts"];
}.