ImagerFrameBufferImpl.mesa
Michael Plass, March 26, 1984 11:58:53 am PST
Edited by Doug Wyatt, November 22, 1983 11:14 am
Provides descriptions of displays as PixelMaps
DIRECTORY
Basics USING [bitsPerWord],
Convert USING [Error, RealFromRope],
ImagerPixelMaps USING [PixelMap, PixelMapRep],
PrincOps USING [BBTable],
Real USING [RoundLI],
RealFns USING [Power],
Terminal USING [ColorMode, Current, GetBitBltTable, GetColorBitmapState, GetColorMode, LegalColorMode, SetBWBitmapState, SetColor, SetColorBitmapState, Virtual],
UserProfile USING [Token],
ImagerFrameBuffer USING [];
ImagerFrameBufferImpl: PROGRAM
IMPORTS Convert, Real, RealFns, Terminal, UserProfile
EXPORTS ImagerFrameBuffer
~ BEGIN
lfDisplay: ImagerPixelMaps.PixelMap;
LFDisplay: PUBLIC PROC RETURNS [ImagerPixelMaps.PixelMap] ~ {
IF lfDisplay.refRep = NIL THEN {
vt: Terminal.Virtual = Terminal.Current[];
bb: PrincOps.BBTable;
[] ← vt.SetBWBitmapState[$displayed];
bb ← vt.GetBitBltTable;
lfDisplay ← [sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: bb.height,
fSize: bb.width,
refRep: NEW [ImagerPixelMaps.PixelMapRep ← [
pointer: bb.dst.word,
words: LONG[bb.width/Basics.bitsPerWord]*bb.height,
lgBitsPerPixel: 0,
rast: bb.width/Basics.bitsPerWord,
lines: bb.height
]]
];
};
RETURN [lfDisplay];
};
ColorDisplayError: PUBLIC ERROR [reason: ATOM] ~ CODE;
ColorDisplay8: PUBLIC PROC RETURNS [colorDisplay: ImagerPixelMaps.PixelMap] ~ {
vt: Terminal.Virtual = Terminal.Current[];
mode: Terminal.ColorMode = [full: FALSE, bitsPerPixelChannelA: 8, bitsPerPixelChannelB: 0];
IF NOT vt.hasColorDisplay THEN
ERROR ColorDisplayError[$NoColorDisplay];
IF vt.GetColorBitmapState#none AND vt.GetColorMode#mode THEN
ERROR ColorDisplayError[$IncompatibleDisplayMode];
IF NOT vt.LegalColorMode[mode] THEN
ERROR ColorDisplayError[$DisplayModeNotSupported];
[] ← vt.SetColorBitmapState[$displayed, mode, $all];
colorDisplay ← [sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: vt.colorHeight,
fSize: vt.colorWidth,
refRep: NEW [ImagerPixelMaps.PixelMapRep ← [
pointer: vt.colorBitmapA,
words: LONG[vt.colorWordsPerLineA]*vt.colorHeight,
lgBitsPerPixel: 3,
rast: vt.colorWordsPerLineA,
lines: vt.colorHeight
]]
];
FOR i: NAT IN [0..40) DO vt.SetColor[ i + 216, 0, i*6, i*6, i*6] ENDLOOP; -- greyscale
FOR i: NAT IN [0..216) DO          -- 6 x 6 x 6 color cube
vt.SetColor[ i, 0, 36 * (i MOD 6 + 1), 36 * ((i/6) MOD 6 + 1), 36 * (i/36 + 1)];
ENDLOOP;
};
GrayScaleDisplay8: PUBLIC PROC RETURNS [colorDisplay: ImagerPixelMaps.PixelMap] ~ {
vt: Terminal.Virtual = Terminal.Current[];
mode: Terminal.ColorMode = [full: FALSE, bitsPerPixelChannelA: 8, bitsPerPixelChannelB: 0];
gamma: REAL ← 2.2;
IF NOT vt.hasColorDisplay THEN
ERROR ColorDisplayError[$NoColorDisplay];
IF vt.GetColorBitmapState#none AND vt.GetColorMode#mode THEN
ERROR ColorDisplayError[$IncompatibleDisplayMode];
IF NOT vt.LegalColorMode[mode] THEN
ERROR ColorDisplayError[$DisplayModeNotSupported];
[] ← vt.SetColorBitmapState[$displayed, mode, $all];
colorDisplay ← [sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: vt.colorHeight,
fSize: vt.colorWidth,
refRep: NEW [ImagerPixelMaps.PixelMapRep ← [
pointer: vt.colorBitmapA,
words: LONG[vt.colorWordsPerLineA]*vt.colorHeight,
lgBitsPerPixel: 3,
rast: vt.colorWordsPerLineA,
lines: vt.colorHeight
]]
];
gamma ← Convert.RealFromRope[UserProfile.Token["ColorDisplay.Gamma", "2.2"] ! Convert.Error => CONTINUE];
GrayScaleGamma[gamma];
};
GrayScaleGamma: PROC [gamma: REAL] ~ {
vt: Terminal.Virtual = Terminal.Current[];
mode: Terminal.ColorMode = [full: FALSE, bitsPerPixelChannelA: 8, bitsPerPixelChannelB: 0];
inverseGamma: REAL ← 1.0/gamma;
IF NOT vt.hasColorDisplay THEN
ERROR ColorDisplayError[$NoColorDisplay];
IF vt.GetColorBitmapState#none AND vt.GetColorMode#mode THEN
ERROR ColorDisplayError[$IncompatibleDisplayMode];
IF NOT vt.LegalColorMode[mode] THEN
ERROR ColorDisplayError[$DisplayModeNotSupported];
FOR i: NAT IN [0..256) DO
uncorrected: REAL ~ i/255.0;
corrected: REAL ~ RealFns.Power[uncorrected, inverseGamma];
scaled: INT ~ Real.RoundLI[corrected*255.0];
g: NAT ~ MAX[MIN[scaled, 255], 0];
vt.SetColor[i, 0, g, g, g];
ENDLOOP;
};
END.