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 CtPseudoToRGB: PUBLIC Commander.CommandProc ~ { name: Rope.ROPE ~ Args.GetRope[cmd]; IF name = NIL THEN RETURN[$Failure, "Usage: CtPsuedoToRGB "] 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 ] [-ncycles ] make a color map to exhibit contours."]; Commander.Register[ "///Commands/CmToOthers", CmToOthers, "\nCmToOthers copy one component to other two."]; Commander.Register[ "///Commands/CtPseudoToRGB", CtPseudoToRGB, "\nCtPseudoToRGB