ImagerColorOperator.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, May 17, 1985 10:37:55 am PDT
DIRECTORY
ImagerColorDefs USING [ColorOperator, ConstantColor],
ImagerSample USING [Sample, SampleBuffer];
~
BEGIN
ConstantColor: TYPE ~ ImagerColorDefs.ConstantColor;
Sample: TYPE ~ ImagerSample.Sample;
SampleBuffer: TYPE ~ ImagerSample.SampleBuffer;
Basic Operations
ColorOperator: TYPE ~ ImagerColorDefs.ColorOperator;
GetColorOperatorClass:
PROC [ColorOperator]
RETURNS [
ATOM];
Returns an ATOM that identifies the ColorOperator.
PixelProc:
TYPE ~
PROC [i:
NAT]
RETURNS [Sample];
ColorFromPixel:
PROC [op: ColorOperator, pixel: PixelProc]
RETURNS [ConstantColor];
Applies op to [pixel[0], pixel[1], ... , pixel[op.samplesPerPixel-1]].
ColorFromSamples:
PROC [op: ColorOperator, s0, s1, s2, s3: Sample ← 0]
RETURNS [ConstantColor];
Applies op to [s0, s1, ...].
Mapper: TYPE ~ REF MapperRep;
MapperRep:
TYPE ~
RECORD [
op: ColorOperator,
component: ATOM,
maxIn, maxOut: Sample,
MapPixel: PROC [mapper: Mapper, pixel: PixelProc] RETURNS [Sample],
MapPixels: PROC [mapper: Mapper, pixels: SampleBuffer, j: NAT ← 0,
buffer: SampleBuffer, bi, bj: NAT ← 0, count: NAT],
data: REF
];
NewMapper:
PROC [op: ColorOperator, component:
ATOM,
maxIn, maxOut: Sample]
RETURNS [Mapper];
Creates a pixel-to-sample mapper for the named component.
The currently understood names are $Intensity, $Red, $Green, $Blue.
Eventually, we will provide proper facilities for calibration.
MapPixel:
PROC [mapper: Mapper, pixel: PixelProc]
RETURNS [Sample];
Maps a single pixel into a sample value IN[0..mapper.maxSampleValue].
MapSamples:
PROC [mapper: Mapper, s0, s1, s2, s3: Sample ← 0]
RETURNS [Sample];
Like MapPixel, but convenient to call from the interpreter.
MapPixels:
PROC [mapper: Mapper, pixels: SampleBuffer, j:
NAT ← 0,
buffer: SampleBuffer, bi, bj:
NAT ← 0, count:
NAT];
FOR k: NAT IN[0..count) DO
pixel: PROC [i: NAT] RETURNS [Sample] ~ { RETURN[pixels.GetSample[i, j+k]] };
buffer.PutSample[bi, bj+k, MapPixel[mapper, pixel]];
ENDLOOP;
Color Model Operators
BlackColorModel:
PROC [clear:
BOOL]
RETURNS [ColorOperator];
... the color model operator implicitly used by MakeSampledBlack.
The resulting ColorOperator has the following effect for a single sample s0 IN[0..1]:
IF s0=1 THEN RETURN[MakeGray[1]]; -- if s0=1, the result is black
IF NOT clear THEN RETURN[MakeGray[0]]; -- if s0=0 AND NOT clear, the result is white
RETURN[NIL]; -- if s0=0 AND clear, the result is "no color"
GrayLinearColorModel:
PROC [sWhite, sBlack:
REAL,
maxSampleValue: Sample ← 0, sampleMap:
PROC [Sample]
RETURNS [
REAL] ←
NIL
]
RETURNS [ColorOperator];
... colorModelOperators/Xerox/GrayLinear, as specified in the Raster Encoding Standard.
The resulting ColorOperator maps a single sample s0 into MakeGray[f], where:
s ← IF maxSampleValue=0 THEN s0 ELSE sampleMap[s0];
f ← MIN[MAX[(s-sWhite)/(sBlack-sWhite), 0.0], 1.0];
GrayDensityColorModel:
PROC [sWhite, sBlack, dBlack:
REAL,
maxSampleValue: Sample ← 0, sampleMap:
PROC [Sample]
RETURNS [
REAL] ←
NIL
]
RETURNS [ColorOperator];
... colorModelOperators/Xerox/GrayDensity, as specified in the Raster Encoding Standard.
The resulting ColorOperator maps a single sample s0 into MakeGray[f], where:
s ← IF maxSampleValue=0 THEN s0 ELSE sampleMap[s0];
d ← ((s-sWhite)/(sBlack-sWhite))*dBlack;
f ← MIN[MAX[1-10**d, 0.0], 1.0]; -- 10**d means 10 to the power d
GrayVisualColorModel:
PROC [sWhite, sBlack:
REAL,
maxSampleValue: Sample ← 0, sampleMap:
PROC [Sample]
RETURNS [
REAL] ←
NIL
]
RETURNS [ColorOperator];
... colorModelOperators/Xerox/GrayVisual, as specified in the Raster Encoding Standard.
The resulting ColorOperator maps a single sample s0 into MakeGray[f], where:
s ← IF maxSampleValue=0 THEN s0 ELSE sampleMap[s0];
L ← (s-sBlack)/(sWhite-sBlack);
Y ← IF L<=0.09 THEN L/0.09 ELSE ((L+0.16)/0.25)**3; -- x**3 means x cubed
f ← MIN[MAX[1-0.01*Y, 0.0], 1.0];
MapColorModel:
PROC [maxSampleValue: Sample,
map:
PROC [Sample]
RETURNS [ConstantColor]
]
RETURNS [ColorOperator];
... colorModelOperators/Xerox/Map, as specified in the Raster Encoding Standard.
The resulting ColorOperator maps a single sample s0 into the ConstantColor map[s0].
RGBLinearColorModel:
PROC [maxSampleValue: Sample]
RETURNS [ColorOperator];
... a simple color model for red, green, blue separations; expects samplesPerPixel=3.