CtMap.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 3, 1992 1:28 pm PDT
Heckbert, June 13, 1988 7:16:18 pm PDT
Glassner, November 8, 1990 2:53 pm PST
Procedures for accessing or modifying the color display color map.
DIRECTORY CtBasic, Imager, ImagerColor, IO, Rope;
CtMap: CEDAR DEFINITIONS
~ BEGIN
Imported Types
ColorValue: TYPE ~ BYTE;
RGB:   TYPE ~ CtBasic.RGB;
Context:  TYPE ~ Imager.Context;
ROPE:   TYPE ~ Rope.ROPE;
Local Types
Gun:   TYPE ~ {r, g, b};
Comp:   TYPE ~ REF CompRep;
CompRep:  TYPE ~ ARRAY [0 .. 256) OF NAT;
Cmap:   TYPE ~ REF CmapRep;
CmapRep:  TYPE ~ ARRAY [0..3) OF Comp;
Table:   TYPE ~ REF TableRep;
TableRep:  TYPE ~ ARRAY [0..256) OF NAT;
Storage/Retrieval/Allocation Operations
NewCmap: PROC RETURNS [Cmap];
Return newly allocated Cmap and its Comps.
Write: PROC [map: Cmap];
Set the color map of the color display to the input color map.
WriteEntry: PROC [i: NAT, rgb: RGB, cmap: Cmap ¬ NIL];
Change the color display color map's entry i. If cmap non-NIL, update it.
WriteEntry24: PROC [ir, ig, ib: NAT, rgb: RGB, cmap: Cmap ¬ NIL];
Change the color display color maps: red[ir] ← r, etc. If cmap non-NIL, update it.
JustWritten: PROC;
Inform waiting clients that color map is just written.
WaitTilNew: PROC;
Waits until the map is just written.
Read: PROC [out: Cmap ¬ NIL] RETURNS [Cmap];
Read the color map of the color display and return; use out if non-nil.
ReadEntry: PROC [i: NAT] RETURNS [rgb: RGB];
Return the color display color map's entry i.
ReadEntry24: PROC [ir, ig, ib: NAT] RETURNS [rgb: RGB];
Return the color display color maps' entries: [red[ir], grn[ig], blu[ib]].
Save: PROC [in: Cmap, name: ROPE];
Save the color map in the specified file.
Load: PROC [name: ROPE, out: Cmap ¬ NIL] RETURNS [BOOL];
Read a color map from the specified file; return true iff successful.
If out is non-nil, load it with the color map, else write the map directly to the color display.
In the file text may precede the color map entries.
Each entry must consist of an index (ABS[index] < 256) and values for red, green and blue.
Each value must be in [0..255].
StreamLoad: PROC [s: IO.STREAM, out: Cmap ¬ NIL] RETURNS [BOOL];
As Load except a stream, rather than filename, is provided for input.
Copy: PROC [in: Cmap, out: Cmap ¬ NIL] RETURNS [Cmap];
Return a copy of the input color map; use out if provided, else allocate a new map.
CopyEntry: PROC [src: Cmap, isrc: NAT, dst: Cmap, idst: NAT];
Copy entry isrc from src to entry idst of dst.
SetEntry: PROC [in: Cmap, i: NAT, rgb: RGB];
Set the specified color map entry to be [r ,g, b].
SetEntry24: PROC [in: Cmap, ir, ig, ib: NAT, rgb: RGB];
Set the specified color map entries: red[ir] ← r, etc.
GetEntry: PROC [in: Cmap, i: NAT] RETURNS [rgb: RGB];
Return the specified color map entry.
GetEntry24: PROC [in: Cmap, ir, ig, ib: NAT] RETURNS [rgb: RGB];
Return the specified color map entries: [red[ir], grn[ig], blu[ib]].
Table Operations
GetTable: PROC [cmap: Cmap ¬ NIL, index: NAT, out: Table ¬ NIL] RETURNS [Table];
Return a table consisting of the indexed component of the color map; use out if non-NIL.
If cmap is NIL, read it from the color display.
GetLuminanceTable: PROC [cmap: Cmap ¬ NIL, out: Table ¬ NIL] RETURNS [Table];
Return a table consisting of the luminances of the input color map; use out if non-NIL.
If cmap is NIL, read it from the color display.
GetGammaTable: PROC [gamma: REAL, out: Table ¬ NIL] RETURNS [Table];
Return a table consisting of gamma adjusted entries; use out if non-NIL.
Creation Operations
Note: For all these procedures, the function is applied to out, if non-NIL; otherwise it is applied directly to the color display's color map, if the color display is on.
Function: PROC [rFunc, gFunc, bFunc: PROC [i: NAT] RETURNS [NAT], out: Cmap ¬ NIL];
Apply the three functions.
Mono: PROC [out: Cmap ¬ NIL];
Apply linear ramp from 0 through 255.
Gamma: PROC [gamma: REAL ¬ 2.2, out: Cmap ¬ NIL];
Apply gamma corrected grayscale.
DeGamma: PROC [gamma: REAL ¬ 2.2, out: Cmap ¬ NIL];
Transform color map by inverse of gamma.
Dither: PROC [out: Cmap ¬ NIL];
Create a color map that spans rgb space in 6 x 7 x 6 partitioning.
Ramp: PROC [i0, i1: NAT, rgb0, rgb1: RGB, out: Cmap ¬ NIL];
Apply ramp from i0 through i1 according to rgb0 and rgb1.
ClearColorMap: PROC [out: Cmap ¬ NIL];
Set all color map entries to zero.
FloodPrimary: PROC [gun: Gun, out: Cmap ¬ NIL];
Set all entries of the specified component to full on, all other components fully off.
PrimaryOnly: PROC [gun: Gun, out: Cmap ¬ NIL];
Set the specified component to a normal grayscale, all other components fully off.
Tents: PROC [nTents: REAL, out: Cmap ¬ NIL];
Apply nTents cycles of linear ramps to out if non-nil, else directly to the display.
nTents=.5 gives one ramp, ntents=1 gives one tent, ntents=128 gives alternating black&white.
Square: PROC [nCycles: REAL, out: Cmap ¬ NIL];
Apply nCycles square wave oscillations.
Sin: PROC [nRCycles, nGCycles, nBCycles: REAL ¬ 1.0, out: Cmap ¬ NIL];
Apply nCycles sine oscillations.
Gauss: PROC [out: Cmap ¬ NIL];
Apply nCycles gaussian oscillations.
Scramble: PROC [in: Cmap, out: Cmap ¬ NIL];
Scramble map's entries.
Rand: PROC [out: Cmap ¬ NIL];
Put arbitrary values.
Arithmetic Operations
Note: For all these procedures, the function is applied to out, if non-NIL; otherwise it is applied directly to the color display's color map, if the color display is on.
Scale: PROC [in: Cmap, s: REAL, out: Cmap ¬ NIL];
Apply s*in.
TriScale: PROC [in: Cmap, r, g, b: REAL, out: Cmap ¬ NIL];
Scale the three channels.
Add: PROC [in: Cmap, a: INTEGER, out: Cmap ¬ NIL];
Apply in+a.
CmScale: PROC [in1, in2: Cmap, out: Cmap ¬ NIL];
Apply in1*in2.
CmAdd: PROC [in1, in2: Cmap, out: Cmap ¬ NIL];
Apply in1+in2.
Compose: PROC [in1, in2: Cmap, out: Cmap ¬ NIL];
Apply in2[in1].
Interp: PROC [t: REAL, in1, in2: Cmap, out: Cmap ¬ NIL];
Apply (1.0-t)*in1+t*in2.
TriColors: PROC [
foreGrnd1, foreGrnd2, backgrnd: ImagerColor.RGB,
gamma: REAL ¬ 2.2,
out: Cmap ¬ NIL];
Set up color map for smooth, colored line drawing.
If the color display is cleared to 0.5 (pVal: 127), subsequent lines drawn with intensity
0 or with intensity 1 will be properly anti-aliased will appear with the desired colors.
Modification Operations
NBits: PROC [in: Cmap, nBits: NAT, out: Cmap ¬ NIL];
Simulate nBits number of bits [0..8] to the input color map;
write to out if non-nil, else directly to the display.
Cycle: PROC [map: Cmap, nCycle: INTEGER, red, grn, blu: BOOL ¬ TRUE] RETURNS [Cmap];
Cycle the colormap by the specified number of entries. Return the input map.
Miscellaneous Operations
WriteAndRelease: PROC [cm: Cmap];
Write the scratch color map to the display and release it.
ObtainCmap: PROC RETURNS [Cmap];
Obtain a scratch color map.
ReleaseCmap: PROC [cmap: Cmap];
Release the scratch color map.
ApplyGamma: PROC [v: REAL, gamma: REAL] RETURNS [ColorValue];
Return a color map entry for v in [0..1] for the given gamma.
ApplyGammaInverse: PROC [colorValue: ColorValue, gamma: REAL]
RETURNS [REAL];
Inverse of ApplyGamma.
Display Operations
Show: PROC [context: Context, cm: Cmap, x, y: INT ¬ 0, w, h: INT, label, border: BOOL ¬ TRUE];
Display the color map as three curves within the given context.
ShowComp: PROC [
context: Context, c: Comp, x, y, w, h: INT, border: BOOL ¬ TRUE, label: ROPE ¬ NIL];
Display a single color map component.
END.