ImagerDisplayLFImpl.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Michael Plass, June 19, 1984 1:19:53 pm PDT
Doug Wyatt, October 6, 1984 4:03:08 pm PDT
DIRECTORY
ImagerColor,
ImagerDisplayPrivate,
ImagerMask,
ImagerPixelMap;
ImagerDisplayLFImpl: CEDAR PROGRAM
IMPORTS ImagerColor, ImagerMask
~ BEGIN
Display: TYPE ~ ImagerDisplayPrivate.Display;
Color: TYPE ~ ImagerColor.Color;
ConstantColor: TYPE ~ ImagerColor.ConstantColor;
SampledColor: TYPE ~ ImagerColor.SampledColor;
Mask: TYPE ~ ImagerMask.Mask;
Data: TYPE ~ REF DataRep;
DataRep:
TYPE ~
RECORD[
value: CARDINAL, -- for ApplyMaskConstant
function: ImagerMask.Function, -- for ApplyMaskConstant or ApplyMaskTile
frame: ImagerPixelMap.PixelMap -- the bitmap
];
Data: TYPE ~ REF DataRep;
DataRep: TYPE ~ RECORD[
value: CARDINAL, -- for ApplyMaskConstant
tile: ImagerPixelMap.Tile, -- for ApplyMaskTile
tileSamples: ImagerColor.SampledColor, -- for ApplyMaskTile
function: ImagerMask.Function, -- for ApplyMaskConstant or ApplyMaskTile
invertOutput, transparent: BOOL, -- for ApplyMaskHalftone
source: PixelArray, -- for ApplyMaskHalftone
transformation: Transformation, -- for ApplyMaskHalftone
deviceBrick: ImagerHalftone.DeviceBrick ← NIL, -- for ApplyMaskHalftone
deviceBrickMaxSampleValue: INT ← -1,
frame: ImagerPixelMap.PixelMap -- the bitmap
];
lfBrick: ImagerHalftone.DeviceBrick ← ImagerHalftone.MakeSquareBrick[4, 3, 2, 1, 1, 255];
IntensityFromColor: PROC[c: ConstantColor] RETURNS[REAL] ~ {
WITH c SELECT FROM
c: REF ImagerColor.ColorRep[constant][gray] => RETURN[c.f];
c: REF ImagerColor.ColorRep[constant][cie] => RETURN[c.Y];
ENDCASE => ERROR;
};
SetTileSamples: PROC [tileSamples: SampledColor, intensity: [0..255]] ~ {
WITH tileSamples.pa.data SELECT FROM
n: REF NAT => n^ ← intensity;
ENDCASE => ERROR;
};
SetColor:
PROC[display: Display, color: Color, vx, vy:
INTEGER] ~ {
data: Data ~ NARROW[display.data];
SELECT color
FROM
ImagerColor.black => {
data.value ← 1; data.function ← [null, null];
display.ApplyMask ← ApplyMaskConstant;
RETURN;
};
ImagerColor.white => {
data.value ← 0; data.function ← [null, null];
display.ApplyMask ← ApplyMaskConstant;
RETURN;
};
ImagerColor.
XOR => {
data.value ← 1; data.function ← [xor, null];
display.ApplyMask ← ApplyMaskConstant;
RETURN;
};
ENDCASE;
ERROR; -- not yet implemented
WITH color SELECT FROM
color: ConstantColor => {
tile: ImagerPixelMap.Tile ~ data.tile;
Runs: PROC[run: PROC[sMin, fMin: INTEGER, fSize: NAT]] ~ {
FOR s: INTEGER IN [tile.sOrigin..tile.sOrigin + tile.sSize) DO
run[s, tile.fOrigin, tile.fSize];
ENDLOOP;
};
SetTileSamples[data.tileSamples, Real.RoundC[IntensityFromColor[color]*255]];
ImagerHalftone.Halftone[
dest: [sOrigin: tile.sOrigin, fOrigin: tile.fOrigin,
sMin: 0, fMin: 0, sSize: tile.sSize, fSize: tile.fSize, refRep: tile.refRep],
runs: Runs,
source: data.tileSamples.pa,
transformation: ImagerTransformation.Rotate[0],
deviceBrick: lfBrick
];
tile.sOrigin ← tile.sOrigin + SurfaceOriginS[data]-vy;
tile.fOrigin ← tile.fOrigin + vx;
data.function ← [null, null];
display.ApplyMask ← ApplyMaskTile;
};
color: SampledColor => {
pa: PixelArray ~ color.pa;
data.source ← pa;
data.transformation^ ← display.surfaceToDevice^;
data.transformation.PreTranslate[vx, vy]; -- view to device
data.transformation.PreMultiply[color.m]; -- color to device
data.transformation.PreMultiply[pa.m]; -- pa to device
IF data.deviceBrickMaxSampleValue#pa.maxSampleValue THEN {
data.deviceBrickMaxSampleValue ← pa.maxSampleValue;
data.deviceBrick ← ImagerHalftone.MakeSquareBrick[4, 3, 2, 1, 1, pa.maxSampleValue];
};
SELECT color.colorOperator FROM
$SampledBlack => data.invertOutput ← TRUE;
$Intensity => data.invertOutput ← FALSE;
ENDCASE => Imager.Error[$UnknownColorModel];
data.transparent ← color.transparent;
display.ApplyMask ← ApplyMaskHalftone;
};
color: SpecialColor => {
WITH color.ref SELECT FROM
stipple: REF CARDINAL => {
data.tile ← ImagerPixelMaps.TileFromStipple[stipple: stipple^, scratch: data.tile.refRep];
data.function ← [null, null];
display.ApplyMask ← ApplyMaskTile;
};
ENDCASE => ERROR Imager.Error[$UnknownSpecialColor];
};
ENDCASE => Imager.Error[$Bug];
};
ApplyMaskConstant:
PROC[display: Display,
mask, clipper: Mask, sTranslate, fTranslate: INTEGER] ~ {
data: Data ~
NARROW[display.data];
USING [frame, value, function]
ImagerMask.ApplyConstant[mask: mask, clipper: clipper, dest: data.frame,
value: data.value, function: data.function, sTranslate: sTranslate, fTranslate: fTranslate];
};
ApplyMaskTile: PROC[display: Display,
mask, clipper: Mask, sTranslate, fTranslate: INTEGER] ~ {
data: Data ~ NARROW[display.data];
USING [frame, tile, function]
ImagerMask.ApplyTile[mask: mask, clipper: clipper, dest: data.frame,
tile: data.tile, function: data.function, sTranslate: sTranslate, fTranslate: fTranslate];
};
ApplyMaskHalftone: PROC[display: Display,
mask, clipper: Mask, sTranslate, fTranslate: INTEGER] ~ {
data: Data ~ NARROW[display.data];
USING [frame, source, transformation, deviceBrick, invertOutput, transparent]
Runs: PROC[run: PROC[sMin, fMin: INTEGER, fSize: NAT]] ~ {
ImagerMask.GenerateRuns[mask, clipper, run, sTranslate, fTranslate];
};
ImagerHalftone.Halftone[dest: data.frame, runs: Runs, source: data.source,
transformation: data.transformation, deviceBrick: data.deviceBrick,
invertOutput: data.invertOutput, transparent: data.transparent];
};
ImagerPrivate.RegisterDevice[LFDisplayClass];
END.