JaMIColorImpl.mesa
last edited by Maureen Stone December 9, 1983 2:15 pm
DIRECTORY
Imager,
JaMIPrivate,
JaMImager USING [Painter],
JaMInternal USING [Frame],
JaMOps USING [PopInteger, PopReal, RegisterExplicit, PopBoolean, defaultFrame, PushReal],
ColorDisplay USING [SetCursorMode,curmode],
ImagerColor,
ColorMap,
JaMImagerContexts USING [GProc],
WindowManager USING[StartColorViewers, StopColorViewers, ScreenPos];
JaMIColorImpl: MONITOR
IMPORTS Imager, JaMOps, ColorDisplay, ImagerColor, ColorMap, WindowManager, JaMIPrivate, JaMImager = {
OPEN J: JaMOps, JaMInternal, P: JaMIPrivate, TDC: JaMImagerContexts;
Painter: PROC[proc: TDC.GProc, frame: Frame ← NIL] = INLINE {
JaMImager.Painter[proc,frame]};
maxIndex: INTEGER ← MaxIndex[];
TurnOnColor: PROC[frame: Frame] = {
nbits: INTEGERJ.PopInteger[frame.opstk];
SELECT nbits FROM
0 => WindowManager.StopColorViewers[];
1 => WindowManager.StartColorViewers[screenpos,1];
2 => WindowManager.StartColorViewers[screenpos,2];
4 => WindowManager.StartColorViewers[screenpos,4];
8 => WindowManager.StartColorViewers[screenpos,8];
24 => WindowManager.StartColorViewers[screenpos,24];
ENDCASE;
maxIndex ← MaxIndex[];
};
MaxIndex: PROC RETURNS[max: CARDINAL] = {
max ← (SELECT ColorDisplay.curmode.bitsPerPixelA FROM
1 => 1, 2 => 3, 4 => 15, 8 => 255, ENDCASE => 0);
};
TurnOffColor: PROC [frame: Frame] = {WindowManager.StopColorViewers[]};
screenpos: WindowManager.ScreenPos ← left;
OnLeft: PROC [frame: Frame] = {
onLeft: BOOLEANJ.PopBoolean[frame.opstk];
IF onLeft THEN screenpos ← left ELSE screenpos ← right;
};
Rainbow: PROCEDURE [frame: Frame] = {
fully saturated rainbow in the even values. grays in the odd values
i: NAT ← 2;
scaler: REAL ← 1.0/maxIndex;
ColorMap.StandardMap[]; --odd values are gray
UNTIL i>maxIndex DO
ColorMap.SetHSVColor[i,i*scaler,1,1];
i ← i+2;
ENDLOOP;
};
GrayMap: PROCEDURE [frame: Frame] = {ColorMap.GrayMap[]};
StandardMap: PROCEDURE [frame: Frame] = {ColorMap.StandardMap[]};
SetGamma: PROC [frame: Frame] = {ColorMap.SetGamma[J.PopReal[frame.opstk]]};
GetGamma: PROC [frame: Frame] = {J.PushReal[frame.opstk, ColorMap.GetGamma[]]};
SetRGBColorMap: PROC [frame: Frame] = {
b: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
g: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
r: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
index: INTEGERJ.PopInteger[frame.opstk];
index ← MAX[MIN[maxIndex,index],0];
[] ← ColorMap.SetRGBColor[index,r,g,b];
};
SetHSVColorMap: PROC [frame: Frame] = {
v: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
s: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
h: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
index: INTEGERJ.PopInteger[frame.opstk];
index ← MAX[MIN[maxIndex,index],0];
[] ← ColorMap.SetHSVColor[index,h,s,v];
};
GetMapValue: PROC [frame: Frame] = {
index: INTEGERJ.PopInteger[frame.opstk];
r,g,b: REAL;
[r,g,b] ← ColorMap.GetColor[MAX[MIN[maxIndex,index],0]];
J.PushReal[frame.opstk,r/255.0];
J.PushReal[frame.opstk,g/255.0];
J.PushReal[frame.opstk,b/255.0];
};
GetColor: PROC [frame: Frame] = {
info: P.Info ← P.GetInfo[frame];
h,s,v: REAL;
color: Imager.Color;
paint: TDC.GProc = { color ← Imager.GetColor[dc]};
Painter[paint,frame];
[h,s,v] ← ImagerColor.ColorToHSV[color];
J.PushReal[frame.opstk,h];
J.PushReal[frame.opstk,s];
J.PushReal[frame.opstk,v];
};
Red: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.red]}; Painter[paint,frame]};
Green: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.green]}; Painter[paint,frame]};
Blue: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.blue]}; Painter[paint,frame]};
Magenta: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.magenta]}; Painter[paint,frame]};
Cyan: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc, ImagerColor.cyan]}; Painter[paint,frame]};
Yellow: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.yellow]}; Painter[paint,frame]};
Black: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.black]}; Painter[paint,frame]};
White: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.white]}; Painter[paint,frame]};
Gray: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.IntensityToColor[.5]]};
Painter[paint,frame];
};
IColor: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.IntensityToColor[gray]]};
gray: REALJ.PopReal[frame.opstk];
gray ← MIN[MAX[0,gray],1];
Painter[paint,frame];
};
RGBColor: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.RGBToColor[r,g,b]]};
b: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
g: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
r: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
Painter[paint,frame];
};
HSVColor: PROC [frame: Frame] = {
paint: TDC.GProc ={Imager.SetColor[dc,ImagerColor.HSVToColor[h,s,v]]};
v: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
s: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
h: REALMAX[MIN[1,J.PopReal[frame.opstk]],0];
Painter[paint,frame];
};
JSetStipple: PROCEDURE [frame: Frame] = {
paint: TDC.GProc ={Imager.SetStipple[dc, i]};
i: LONG INTEGERJ.PopInteger[frame.opstk];
Painter[paint,frame];
};
BlackCursor: PROC [frame: Frame] = {ColorDisplay.SetCursorMode[zeros]};
WhiteCursor: PROC [frame: Frame] = {ColorDisplay.SetCursorMode[ones]};
Initialization starts here
frame: Frame ← JaMOps.defaultFrame;
J.RegisterExplicit[frame,".turnoncolor"L,TurnOnColor];
J.RegisterExplicit[frame,".turnoffcolor"L,TurnOffColor];
J.RegisterExplicit[frame,".onleft"L,OnLeft];
J.RegisterExplicit[frame,".rainbow"L,Rainbow];
J.RegisterExplicit[frame,".graymap"L,GrayMap];
J.RegisterExplicit[frame,".standardmap"L,StandardMap];
J.RegisterExplicit[frame,".setgamma"L,SetGamma];
J.RegisterExplicit[frame,".getgamma"L,GetGamma];
J.RegisterExplicit[frame,".setrgbmap"L,SetRGBColorMap];
J.RegisterExplicit[frame,".sethsvmap", SetHSVColorMap];
J.RegisterExplicit[frame,".getmapvalue", GetMapValue];
J.RegisterExplicit[frame,".red", Red];
J.RegisterExplicit[frame,".green", Green];
J.RegisterExplicit[frame,".blue", Blue];
J.RegisterExplicit[frame,".magenta", Magenta];
J.RegisterExplicit[frame,".cyan", Cyan];
J.RegisterExplicit[frame,".yellow", Yellow];
J.RegisterExplicit[frame,".black", Black];
J.RegisterExplicit[frame,".white", White];
J.RegisterExplicit[frame,".gray", Gray];
J.RegisterExplicit[frame,".icolor", IColor];
J.RegisterExplicit[frame,".rgbcolor", RGBColor];
J.RegisterExplicit[frame,".hsvcolor", HSVColor];
J.RegisterExplicit[frame,".blackcursor", BlackCursor];
J.RegisterExplicit[frame,".whitecursor", WhiteCursor];
J.RegisterExplicit[frame,".getcolor", GetColor];
J.RegisterExplicit[frame,".stipple"L,JSetStipple];
}.