ImagerBridgeImpl.mesa
Michael Plass, April 9, 1984 4:19:25 pm PST
Last Edited by: Stone, August 16, 1984 2:57:23 pm PDT
DIRECTORY Atom, CGContext, Imager, ImagerBridge, ImagerBridgeExtras, ImagerDisplay, ImagerPrivate, Graphics, GraphicsOps, Real, Terminal;
ImagerBridgeImpl: CEDAR PROGRAM
IMPORTS Atom, Imager, Graphics, GraphicsOps, Real, Terminal
EXPORTS ImagerBridge, ImagerBridgeExtras
~ BEGIN
deviceTable: ARRAY ImagerBridgeExtras.DisplayAtom OF ATOM ← [
lf: $LFDisplay,
bits2: $Std2bpp,
bits4:$Std4bpp,
bits8: $Gray8bpp,
bits24:$Std24bpp
];
controls the choice of device for the different displays
$Gray8bpp, $SmoothGray, $Std2bpp, $Std4bpp, $Std8bpp, $Std24bpp.
colorDisplayHeight: REAL ← 11.0;
SetDisplayScale: PUBLIC PROC [height: REAL ← 11] = { --11 inch "page" fits on display
colorDisplayHeight ← height};
SetDisplayAtom: PUBLIC PROC [type: ImagerBridgeExtras.DisplayAtom, atom: ATOM] = {
deviceTable[type] ← atom;
};
lfGraphicsData: CGContext.Ref ~ NARROW[Graphics.NewContext[].data];
OnLFDisplay: PROC [graphics: Graphics.Context] RETURNS [BOOLEAN] ~ {
data: CGContext.Ref ~ NARROW[graphics.data];
RETURN [data.device.Show = lfGraphicsData.device.Show]
};
ColorDisplayProps: PROC RETURNS [props: Atom.PropList ← NIL] ~ {
vt: Terminal.Virtual ← Terminal.Current[];
colorHeight: NAT ← vt.colorHeight;
IF colorHeight > 25 THEN {
props ← Atom.PutPropOnList[props, $pixelsPerInch, NEW[REAL ← (colorHeight-14)/colorDisplayHeight]];
};
};
SetViewFromGraphicsContext: PUBLIC PROC [imager: Imager.Context, graphics: Graphics.Context] ~ {
x, y, w, h: REAL;
IF NARROW[imager.class, ImagerPrivate.Class].deviceType = $PD THEN Imager.Error[$CannotUseAHardcopyContextOnADisplay];
[x, y] ← GraphicsOps.UserToDevice[graphics,0,0];
IF GraphicsOps.UserToDevice[graphics,0,1].ty > y THEN Imager.Error[$YFlipNotSupported];
[[xmax: w, ymax: h]] ← Graphics.GetBounds[graphics];
IF OnLFDisplay[graphics] THEN {
IF NARROW[imager.class, ImagerPrivate.Class].deviceType # deviceTable[lf] THEN {
temp: Imager.Context ← Imager.Create[deviceTable[lf]];
imager.class ← temp.class;
imager.data ← temp.data;
};
}
ELSE {
Must be on Color Display
displayData: ImagerDisplay.DisplayData;
type: ImagerBridgeExtras.DisplayAtom;
mode: Terminal.ColorMode ← Terminal.GetColorMode[Terminal.Current[]];
type ← IF mode.full THEN bits24 ELSE SELECT mode.bitsPerPixelChannelA FROM
2 => bits2, 4 => bits4, 8 => bits8, ENDCASE => ERROR;
IF NARROW[imager.class, ImagerPrivate.Class].deviceType # deviceTable[type] THEN {
temp: Imager.Context ← Imager.Create[deviceTable[type], NIL];
imager.class ← temp.class;
imager.data ← temp.data;
};
displayData ← NARROW[imager.data];
x ← x*displayData.displayClass.viewUnitsPerPixel;
y ← y*displayData.displayClass.viewUnitsPerPixel;
w ← w*displayData.displayClass.viewUnitsPerPixel;
h ← h*displayData.displayClass.viewUnitsPerPixel;
};
imager.SetViewOrigin[[Real.RoundLI[x], imager.GetSurfaceBounds.h-Real.RoundLI[y]]];
imager.SetViewBox[[0, 0, Real.RoundLI[w], Real.RoundLI[h]]];
};
END.