ColorTrixExtraCommandsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, January 15, 1987 5:46:17 pm PST
DIRECTORY Args, ColorTrixBasics, ColorTrixMap, ColorTrixMod, Commander, FileNames, ImagerPixelMap, IO, PixelMapOps, Real, RealFns, Rope;
ColorTrixExtraCommandsImpl: CEDAR PROGRAM
IMPORTS Args, ColorTrixBasics, ColorTrixMap, ColorTrixMod, Commander, FileNames, ImagerPixelMap, IO, PixelMapOps, Real, RealFns, Rope
~ BEGIN
Commands Not Yet In ColorTrixDispatch:
CtPseudoToRGB: PUBLIC Commander.CommandProc ~ {
name: Rope.ROPE ~ Args.GetRope[cmd];
IF name = NIL
THEN RETURN[$Failure, "Usage: CtPsuedoToRGB <base name>"]
ELSE {
pm: ColorTrixBasics.PixelMapMisc ← ColorTrixBasics.GetColorDisplayPmMisc[];
IF pm.bpp # 8
THEN RETURN[$Failure, "Color display should be in 8bpp"]
ELSE {
cmap: ColorTrixMap.Cmap ← ColorTrixMap.Read[];
base: Rope.ROPE ~ FileNames.ResolveRelativePath[name];
table: ColorTrixMod.Table ← NEW[ColorTrixMod.TableRep];
temp: ImagerPixelMap.PixelMap ←
ImagerPixelMap.Create[3, ImagerPixelMap.Window[pm.bw]];
SaveOneFile: PROC [color: Rope.ROPE, i: NAT] ~ {
IO.PutF[cmd.out, "%g . . . ", IO.rope[color]];
ImagerPixelMap.Transfer[temp, pm.bw];
FOR n: NAT IN [0..255) DO table[n] ← cmap[i][n]; ENDLOOP;
ColorTrixMod.Indirect[temp, table];
PixelMapOps.StoreAIS[Rope.Cat[base, "-", color, ".ais"], [temp, FALSE, NIL]];
};
IO.PutRope[cmd.out, "writing "];
SaveOneFile["red", 0];
SaveOneFile["grn", 1];
SaveOneFile["blu", 2];
IO.PutRope[cmd.out, "done!\n"];
};
};
};
CmContours: PUBLIC Commander.CommandProc ~ {
ok: BOOL;
nCyclesArg, powerArg: Args.Arg;
twoPI: REAL ~ 2.0*3.1415926535;
halfPI: REAL ~ 0.5*3.1415926535;
[ok, nCyclesArg, powerArg] ← Args.ArgsGet[cmd, "-power%r-ncycles%r"];
IF ok THEN {
nCycles: REAL ~ IF nCyclesArg.ok THEN nCyclesArg.real ELSE 4.0;
power: REAL ~ 1.0/(IF powerArg.ok THEN powerArg.real ELSE 6.0);
FOR n: NAT IN [0..255] DO
cmapValue: INT;
t: REAL ~ REAL[n]/255.0;
intensity: REAL ← 0.5+0.5*RealFns.Sin[(nCycles*twoPI+halfPI)*RealFns.Power[t, power]];
intensity ← t+(1.0-t)*intensity;
cmapValue ← Real.RoundI[intensity*255.0];
ColorTrixMap.WriteEntry[n, cmapValue, cmapValue, cmapValue];
ENDLOOP;
ColorTrixMap.JustWritten[];
};
};
CmToOthers: PUBLIC Commander.CommandProc ~ {
source: Rope.ROPE ~ Args.GetRope[cmd];
i0dst, i1dst, isrc: INT ← -1;
SELECT TRUE FROM
Rope.Equal[source, "red", FALSE] => {isrc ← 0; i0dst ← 1; i1dst ← 2};
Rope.Equal[source, "grn", FALSE] => {isrc ← 1; i0dst ← 0; i1dst ← 2};
Rope.Equal[source, "blu", FALSE] => {isrc ← 2; i0dst ← 0; i1dst ← 1};
ENDCASE;
IF isrc # -1 THEN {
cmap: ColorTrixMap.Cmap ← ColorTrixMap.Read[];
FOR n: NAT IN [0..255] DO
cmap[i0dst][n] ← cmap[i1dst][n] ← cmap[isrc][n];
ENDLOOP;
ColorTrixMap.Write[cmap];
ColorTrixMap.JustWritten[];
};
};
Commander.Register[
"///Commands/CmContours",
CmContours,
"\nCmContours [-power <real>] [-ncycles <real>] make a color map to exhibit contours."];
Commander.Register[
"///Commands/CmToOthers",
CmToOthers,
"\nCmToOthers <red | grn | blu> copy one component to other two."];
Commander.Register[
"///Commands/CtPseudoToRGB",
CtPseudoToRGB,
"\nCtPseudoToRGB <name: creates name-red, -grn, -blu.ais from pseudo color image."];
END.