Imager32BitABufferImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Frank Crow, July 30, 1984 5:50:05 pm PDT
DIRECTORY
Imager    USING [Error, Context],
ImagerBasic   USING [DeviceRectangle, Color, ColorRep],
ImagerDisplay  USING [DisplayClass, DisplayClassRep, DisplayData, CreateImagerClass],
ImagerStdColorDisplay USING [MapInitProc, Create, ApplyMask, GetDisplay, PinPixelMap,
          ReleasePixelMap, LoadColorMap, DoUnderLock],
ImagerManhattan USING [Polygon],
ImagerMasks   USING [Mask],
ImagerPrivate  USING [Class, RegisterDevice],
ColorModels   USING [Calibration],
ConstantColors  USING [ColorToRGB, black, white, red, cyan, green, magenta, blue, yellow,
         orange, purple, brown, grey, darkGrey, veryLightGrey, lightGrey,
         veryDarkGrey, NameToColor],
Terminal    USING [ColorMode, Current, GetColorBitmapState, SetColor, Virtual],
Rope     USING [ROPE],
Real     USING [FixC];
Imager32BitABufferImpl: CEDAR MONITOR
IMPORTS Imager, ImagerDisplay, ImagerPrivate, ConstantColors, Terminal, Real,
   ImagerStdColorDisplay
~ BEGIN
This implements an 24-bit-per-pixel color display with an additional 8-bit Alpha buffer for antialiasing.
DisplayClass: TYPE ~ ImagerDisplay.DisplayClass;
DisplayClassRep: TYPE ~ ImagerDisplay.DisplayClassRep;
DisplayData: TYPE ~ ImagerDisplay.DisplayData;
Color: TYPE ~ ImagerBasic.Color;
ColorRep: TYPE ~ ImagerBasic.ColorRep;
ConstantColor: TYPE = REF ColorRep.constant;
Mask: TYPE ~ ImagerMasks.Mask;
on: BOOLEAN ~ TRUE;
off: BOOLEAN ~ FALSE;
lgBitsPerPixel: NAT ~ 5;
vt: Terminal.Virtual;
mode: Terminal.ColorMode ~ [full: TRUE, bitsPerPixelChannelA: 0, bitsPerPixelChannelB: 0];
colorCalibration: ColorModels.Calibration;
alpha32BitDisplayClass: ImagerDisplay.DisplayClass ~ NEW[ImagerDisplay.DisplayClassRep ← [
displayType: $alpha32bpp,
viewUnitsPerPixel: 1,
Create: Create,
ApplyMask: ApplyMask,
DoUnderLock: ImagerStdColorDisplay.DoUnderLock
]];
ColorDisplayError: PUBLIC ERROR [reason: ATOM] ~ CODE;
Create: PROC [displayClass: DisplayClass, creationData: REF]
RETURNS [displayData: DisplayData] ~ {
ImagerStdColorDisplay.GetDisplay[vt, $unchanged, mode, SetUpColorMap];
displayData ← ImagerStdColorDisplay.Create[vt, displayClass, creationData, lgBitsPerPixel];
};
ApplyMask: PROC [displayData: DisplayData, color: Color, mask: Mask,
      sTranslate, fTranslate: INTEGER] ~ {
ImagerStdColorDisplay.ApplyMask[displayData, color, mask, sTranslate, fTranslate, CacheColor];
};
SpecialOp: PROC[context: Imager.Context, op: ATOM, data: REF] RETURNS[REF] ~ {
SELECT op FROM
$DisplayContext => { -- Pin a pixel map to the color display, replace what was there before.
IF vt.GetColorBitmapState # displayed THEN       -- turn on color display
ImagerStdColorDisplay.GetDisplay[vt, $aOn, mode, SetUpColorMap];
MergeRGMaps[NARROW[context.data, ImagerDisplay.DisplayData], data]; --Interleave R&G
ImagerStdColorDisplay.PinPixelMap[vt, NARROW[context.data, ImagerDisplay.DisplayData] ];
};
$UnDisplayContext => ImagerStdColorDisplay.ReleasePixelMap[vt,
            NARROW[context.data, ImagerDisplay.DisplayData]];
$LoadColorMap => ImagerStdColorDisplay.LoadColorMap[vt, data];
$TurnOffRGMerging => MergingOn ← FALSE; -- client merging of Red and Grn pixelmaps
$TurnOnRGMerging => MergingOn ← TRUE; -- auto merging of Red and Grn pixelmaps
$MergeRGMaps => MergeRGMaps[NARROW[context.data, ImagerDisplay.DisplayData], data];
ENDCASE => Imager.Error[$UnimplementedSpecialOp];
RETURN[ NIL ];
};
SetUpColorMap: ImagerStdColorDisplay.MapInitProc ~ {
FOR i: NAT IN [0..256) DO
j: NAT ← Real.FixC[RealFns.Power[i/256.0, .43] * 256.0]; -- Linearize power law display
vt.SetRedMap[i, j];
vt.SetGreenMap[i, j];
vt.SetBlueMap[i, j];
ENDLOOP;
};
Init: PROC[] ~ {
alpha32BitImagerClass: ImagerPrivate.Class ~
  ImagerDisplay.CreateImagerClass[alpha32BitDisplayClass];  -- pick up Imager class record
alpha32BitImagerClass.SpecialOp ← SpecialOp;     -- modify procedure bindings
ImagerPrivate.RegisterDevice[alpha32BitImagerClass];   -- register device class
vt ← Terminal.Current[];
};
Init[];
END.