ColorMapImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, November 12, 1985 4:34:14 pm PST
ColorMapImpl:
CEDAR
PROGRAM
IMPORTS ImagerColorMap, InterminalBackdoor, Random, Terminal
EXPORTS ColorMap
~ {
ColorDisplayNotReady: PUBLIC ERROR = CODE;
vtSave: Terminal.Virtual ← NIL;
InitVt:
PROC
RETURNS [vt: Terminal.Virtual] ~ {
IF vtSave # NIL THEN RETURN[vtSave];
vt ← InterminalBackdoor.terminal;
IF NOT vt.hasColorDisplay THEN ERROR ColorDisplayNotReady;
IF Terminal.GetColorBitmapState[vt] = none
OR Terminal.GetColorMode[vt].full
THEN
[] ← Terminal.SetColorMode[vt, [FALSE, 8, 0]];
vtSave ← vt;
};
Set:
PUBLIC
PROC [cm: ColorMap.ColorMap]
~ {
vt: Terminal.Virtual ← InitVt[];
FOR i:
INT
IN [0..256)
DO
Terminal.SetColor[vt: vt, aChannelValue: i, red: cm[0][i], green: cm[1][i], blue: cm[2][i]];
ENDLOOP;
};
Get:
PUBLIC
PROC
RETURNS [cm: ColorMap.ColorMap] ~ {
vt: Terminal.Virtual ← InitVt[];
FOR i:
INT
IN [0..256)
DO
[cm[0][i], cm[1][i], cm[2][i]] ← Terminal.GetColor[vt: vt, aChannelValue: i];
ENDLOOP;
};
FloodPrimary:
PUBLIC PROC [gun: ImagerColorMap.Gun] ~ {
vt: Terminal.Virtual ← InitVt[];
v: Terminal.ChannelValue ← ImagerColorMap.ApplyGamma[1., 2.2];
FOR i:
INT
IN [0..256)
DO
SELECT gun
FROM
red => Terminal.SetColor[vt: vt, aChannelValue: i, red: v, green: 0, blue: 0];
green => Terminal.SetColor[vt: vt, aChannelValue: i, red: 0, green: v, blue: 0];
blue => Terminal.SetColor[vt: vt, aChannelValue: i, red: 0, green: 0, blue: v];
ENDCASE;
ENDLOOP;
};
ClearColorMap:
PUBLIC PROC ~ {
vt: Terminal.Virtual ← InitVt[];
FOR i:
INT
IN [0..256)
DO
Terminal.SetColor[vt: vt, aChannelValue: i, red: 0, green: 0, blue: 0];
ENDLOOP;
};
PrimaryOnly:
PUBLIC PROC [gun: ImagerColorMap.Gun] ~ {
vt: Terminal.Virtual ← InitVt[];
r, g, b, v: Terminal.ChannelValue;
FOR i:
INT
IN [0..256)
DO
v ← ImagerColorMap.ApplyGamma[i/255., 2.2];
SELECT gun
FROM
red => { r ← v; g ← b ← 0; };
green => { g ← v; r ← b ← 0; };
blue => { b ← v; r ← g ← 0; };
ENDCASE;
Terminal.SetColor[vt: vt, aChannelValue: i, red: r, green: g, blue: b];
ENDLOOP;
};
Flash:
PUBLIC PROC ~ {
vt: Terminal.Virtual ← InitVt[];
FOR i:
INT
IN (0..256)
DO
Terminal.SetColor[vt: vt, aChannelValue: i, red: Random.ChooseInt[max: 255], green: Random.ChooseInt[max: 255], blue: Random.ChooseInt[max: 255]];
ENDLOOP;
};
Mono:
PUBLIC PROC ~ {
vt: Terminal.Virtual ← InitVt[];
FOR i:
INT
IN (0..256)
DO
Terminal.SetColor[vt: vt, aChannelValue: i, red: i, green: i, blue: i];
ENDLOOP;
};
Gamma:
PUBLIC
PROC [gamma:
REAL ← 2.2] ~ {
out: Terminal.ColorValue;
vt: Terminal.Virtual ← InitVt[];
FOR i:
INT
IN (0..256)
DO
out ← ImagerColorMap.ApplyGamma[i*(1./256.), gamma];
Terminal.SetColor[vt: vt, aChannelValue: i, red: out, green: out, blue: out];
ENDLOOP;
};
Cycle:
PUBLIC
PROC [n:
INT]~ {
ii: INT;
modulo: INT ~ 255;
cm, cmnew: ColorMap.ColorMap;
n ← ((n-1)MOD(modulo-1))+(IF n < 0 THEN -1 ELSE 1);
IF n = 0 THEN RETURN;
cm ← Get[];
FOR i:
INT
IN [1..modulo]
DO
ii ← ((i-1)+n) MOD modulo;
IF ii < 0 THEN ii ← modulo+ii;
ii ← ii+1;
cmnew[0][ii] ← cm[0][i];
cmnew[1][ii] ← cm[1][i];
cmnew[2][ii] ← cm[2][i];
ENDLOOP;
cmnew[0][0] ← cm[0][0];
cmnew[1][0] ← cm[1][0];
cmnew[2][0] ← cm[2][0];
Set[cmnew];
};
}.