ImagerTerminalImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, May 30, 1985 11:29:28 pm PDT
Michael Plass, July 22, 1985 11:33:48 am PDT
DIRECTORY
Imager USING [Context],
ImagerCache USING [GetNamedCache, Ref],
ImagerColorMap USING [SetStandardColorMap],
ImagerDevice USING [Device, DeviceBox],
ImagerDitheredDevice USING [ContextFromColorTerminal],
ImagerFastShow USING [Create],
ImagerPixelMap USING [PixelMap, PixelMapRep],
ImagerRaster USING [AmbushDevice, Ambusher, AmbusherRep, Create, NewBitmapDevice, NewColor24Device],
ImagerTerminal USING [],
Terminal;
ImagerTerminalImpl: CEDAR PROGRAM
IMPORTS ImagerCache, ImagerColorMap, ImagerDitheredDevice, ImagerFastShow, ImagerRaster, Terminal
EXPORTS ImagerTerminal
~ BEGIN
Context: TYPE ~ Imager.Context;
Lg: PROC [n: NAT] RETURNS [NAT] ~ {
RETURN[SELECT n FROM 1 => 0, 2 => 1, 4 => 2, 8 => 3, 16 => 4, ENDCASE => ERROR]
};
PixelMapFromFrameBuffer: PROC [frameBuffer: Terminal.FrameBuffer]
RETURNS
[ImagerPixelMap.PixelMap] ~ {
refRep: REF ImagerPixelMap.PixelMapRep ~ NEW[ImagerPixelMap.PixelMapRep ← [
ref: frameBuffer,
pointer: frameBuffer.base,
words: INT[frameBuffer.wordsPerLine]*INT[frameBuffer.height],
lgBitsPerPixel: Lg[frameBuffer.bitsPerPixel],
rast: frameBuffer.wordsPerLine,
lines: frameBuffer.height
]];
frame: ImagerPixelMap.PixelMap ~ [
sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0,
sSize: frameBuffer.height, fSize: frameBuffer.width, refRep: refRep
];
RETURN[frame];
};
bitmapCacheID: ATOM ~ $Bitmap;
bitmapCacheSize: NAT ~ 4000;
bitmapRastWeight: REAL ~ 2.0;
BWContext: PUBLIC PROC [vt: Terminal.Virtual, pixelUnits: BOOL] RETURNS [Context] ~ {
frameBuffer: Terminal.FrameBuffer ~ Terminal.GetBWFrameBuffer[vt];
RETURN[ImagerFastShow.Create[pm: PixelMapFromFrameBuffer[frameBuffer], pixelsPerInch: vt.bwPixelsPerInch, pixelUnits: pixelUnits, fontTuner: NIL]];
};
colorCacheID: ATOM ~ $ColorDisplay;
colorCacheSize: NAT ~ 4000;
colorRastWeight: REAL ~ 0.0;
OneBitPerPixelMasker: PROC [self: ImagerRaster.Ambusher, box: ImagerDevice.DeviceBox, action: PROC] ~ {
vt: Terminal.Virtual ~ NARROW[self.data];
Terminal.ModifyColorFrame[vt: vt, action: action, xmin: box.fmin, ymin: box.smin, xmax: box.fmax, ymax: box.smax];
};
ColorContext: PUBLIC PROC [vt: Terminal.Virtual, pixelUnits: BOOL] RETURNS [Context] ~ {
mode: Terminal.ColorMode ~ Terminal.GetColorMode[vt];
IF Terminal.GetColorBitmapState[vt]=none THEN RETURN[NIL];
IF mode.full THEN {
device: ImagerDevice.Device ~ ImagerRaster.NewColor24Device[vt];
colorFontCache: ImagerCache.Ref ~ ImagerCache.GetNamedCache[
atom: colorCacheID, createSize: colorCacheSize];
[] ← Terminal.SetColorCursorPresentation[vt, onesAreBlack];
RETURN[ImagerRaster.Create[device: device, pixelUnits: pixelUnits,
fontCache: colorFontCache, rastWeight: colorRastWeight]];
}
ELSE {
frameBuffer: Terminal.FrameBuffer ~ Terminal.GetColorFrameBufferA[vt];
IF mode.bitsPerPixelChannelA = 1 THEN {
frame: ImagerPixelMap.PixelMap ~ PixelMapFromFrameBuffer[frameBuffer];
ambusher: ImagerRaster.Ambusher ~ NEW[ImagerRaster.AmbusherRep ← [
maskProc: OneBitPerPixelMasker,
device: ImagerRaster.NewBitmapDevice[
frame: frame, pixelsPerInch: vt.colorPixelsPerInch],
data: vt
]];
device: ImagerDevice.Device ~ ImagerRaster.AmbushDevice[ambusher];
bitmapFontCache: ImagerCache.Ref ~ ImagerCache.GetNamedCache[
atom: bitmapCacheID, createSize: bitmapCacheSize];
[] ← Terminal.SetColorCursorPresentation[vt, onesAreWhite];
They are really black because we have an unconventional frame buffer.
RETURN[ImagerRaster.Create[device: device, pixelUnits: pixelUnits,
fontCache: bitmapFontCache, rastWeight: bitmapRastWeight]];
};
RETURN[ImagerDitheredDevice.ContextFromColorTerminal[vt, pixelUnits]];
};
};
SetStandardColorMap: PUBLIC PROC [vt: Terminal.Virtual] ~ {
ImagerColorMap.SetStandardColorMap[vt];
};
END.