ImagerColor.mesa
Copyright Ó 1985, 1986, 1987, 1991, 1992 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 6, 1986 9:59:30 pm PST
Michael Plass, October 25, 1991 10:24 pm PDT
Stone, October 17, 1991 5:16 pm PDT
DIRECTORY
ImagerPixelArray USING [PixelArray],
ImagerTransformation USING [Transformation],
Rope USING [ROPE];
ImagerColor: CEDAR DEFINITIONS
~ BEGIN
SampleValue: TYPE ~ REAL;
ROPE: TYPE ~ Rope.ROPE;
The Color type
Color: TYPE ~ REF ColorRep;
ColorRep: TYPE ~ RECORD [
SELECT tag: * FROM
constant => [
SELECT tag: * FROM
op => [
colorOperator: ColorOperator,
pixel: SEQUENCE size: NAT OF SampleValue
],
special => [ -- XOR, stipples, named colors, and the like
type: ATOM, -- identifies the kind of special color this is
name: ROPE, -- hierarchical name
data: REF, -- implementation-specific data
substitute: ConstantColor -- use this if you don't recognize type
],
ENDCASE
],
sampled => [ -- the result of MakeSampledColor
pa: ImagerPixelArray.PixelArray, -- the array of pixels
um: ImagerTransformation.Transformation, -- transforms from color to device coordinates
colorOperator: ColorOperator -- maps pixels into constant colors
],
sampledBlack => [ -- the result of MakeSampledBlack
pa: ImagerPixelArray.PixelArray, -- the array of pixels (must be 1 bit per pixel)
um: ImagerTransformation.Transformation, -- transforms from color to device coordinates
clear: BOOL -- are zero bits transparent?
],
ENDCASE
];
ConstantColor: TYPE ~ REF ColorRep.constant;
OpConstantColor: TYPE ~ REF ColorRep.constant.op;
SpecialColor: TYPE ~ REF ColorRep.constant.special;
SampledColor: TYPE ~ REF ColorRep.sampled;
SampledBlack: TYPE ~ REF ColorRep.sampledBlack;
The Structure type
This type provides a method of representing data that can be externalized and internalized easily; it corresponds fairly closely with an Interpress Vector. The concrete class representation and the operations are in another interface, ImagerColorPrivate, to avoid undesirable interface dependencies.
Structure: TYPE ~ REF StructureRep;
StructureRep: TYPE ~ RECORD [class: StructureClass, data: REF];
StructureClass: TYPE ~ REF StructureClassRep;
StructureClassRep: TYPE;
The ColorOperator type
A color operator specifies how to interpret pixel values as constant colors.
ColorOperator: TYPE ~ REF ColorOperatorRep;
ColorOperatorRep: TYPE ~ RECORD [
chromatic: BOOL, -- If FALSE, everything is gray.
samplesPerPixelIn: NAT, -- Number of samples per pixel expected.
class: REF ColorOperatorClassRep, -- Contains the name of the Interpress color model operator and the operations that the ColorOperator needs to perform.
data: REF, -- Contains the data specific to the ColorOperator; corresponds to the parameters needed by the color model operator
appearanceHints: Structure -- Hints to the implementation about the desired appearance
];
ColorOperatorClassRep: TYPE;
Constant colors
Find: PROC [name: ROPE] RETURNS [ConstantColor];
Finds the color with the given hierarchical name (color names, etc.).
ColorFromPixel: PROC [colorOperator: ColorOperator, pixel: PROC [sampleIndex: NAT] RETURNS [REAL]]
RETURNS [ConstantColor];
Creates a constant color by applying a color operator to a single pixel.
NarrowToOpConstantColor: PROC [color: ConstantColor] RETURNS [OpConstantColor];
Dereferences any chain of special colors
Sampled colors
MakeSampledBlack: PROC [pa: ImagerPixelArray.PixelArray, um: ImagerTransformation.Transformation, clear: BOOL ¬ FALSE] RETURNS [SampledBlack];
MakeSampledColor: PROC [pa: ImagerPixelArray.PixelArray, um: ImagerTransformation.Transformation, colorOperator: ColorOperator] RETURNS [SampledColor];
Monochrome Color Operators
ColorFromGray: PROC [f: REAL] RETURNS [OpConstantColor];
Constant gray; f is the fraction of absorptance, from 0 (background) to 1 (black).
Imager.MakeGray is identical; see MAKEGRAY in the Interpress standard, section 4.7.1.
SampleTableProc: TYPE ~ PROC [NAT] RETURNS [REAL];
NewColorOperatorGrayLinear: PROC [sWhite, sBlack: REAL, sampleTableSize: NAT ¬ 0, sampleTableProc: SampleTableProc ¬ NIL] RETURNS [ColorOperator];
... colorModelOperators/Xerox/GrayLinear, as specified in the Color Encoding Standard.
The resulting ColorOperator maps a single sample s0 into MakeGray[f], where:
s ¬ IF sampleTableSize=0 THEN s0 ELSE sampleMap[s0];
f ¬ MIN[MAX[(s-sWhite)/(sBlack-sWhite), 0.0], 1.0];
NewColorOperatorGrayDensity: PROC [sWhite, sBlack, dBlack: REAL, sampleTableSize: NAT ¬ 0, sampleTableProc: SampleTableProc ¬ NIL] RETURNS [ColorOperator];
... colorModelOperators/Xerox/GrayDensity, as specified in the Color Encoding Standard.
The resulting ColorOperator maps a single sample s0 into MakeGray[f], where:
s ¬ IF sampleTableSize=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
NewColorOperatorGrayVisual: PUBLIC PROC [sWhite, sBlack: REAL, sampleTableSize: NAT ¬ 0, sampleTableProc: SampleTableProc ¬ NIL] RETURNS [ColorOperator];
... colorModelOperators/Xerox/GrayVisual, as specified in the Color Encoding Standard.
The resulting ColorOperator maps a single sample s0 into MakeGray[f], where:
s ¬ IF sampleTableSize=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;
f ¬ MIN[MAX[1-0.01*Y, 0.0], 1.0];
Map Color Operators
NewColorOperatorMap: PROC [maxSampleValue: NAT, map: PROC [NAT] RETURNS [ConstantColor]] RETURNS [ColorOperator];
... colorModelOperators/Xerox/Map, as specified in the Color Encoding Standard.
The resulting ColorOperator maps a single sample s0 into the ConstantColor map[s0].
NewColorOperatorBuildMap: PROC [colorOperator: ColorOperator, maxSampleValue: NAT, map: SampleTableProc] RETURNS [ColorOperator];
... colorModelOperators/Xerox/BuildMap, as specified in the Color Encoding Standard.
The resulting ColorOperator maps a single sample s0 into the ConstantColor obtained by applying colorOperator to map[s0]
PixelEncoding
The PixelEncoding type corresponds with the Interpress vector of vectors of numbers that the Color Encoding Standard refers to as a pixelmap. We use a different name here because the Imager has a different meaning for the term pixelMap.
PixelEncoding: TYPE ~ REF PixelEncodingRep;
PixelEncodingRep: TYPE ~ RECORD [SEQUENCE samplesPerPixel: NAT OF SampleEncoding];
SampleEncoding: TYPE ~ REF SampleEncodingRep;
SampleEncodingRep: TYPE ~ RECORD [SEQUENCE size: NAT OF REAL];
RGBLinear
... Xerox/RGBLinear (Color Encoding Standard)
RGB: TYPE ~ RECORD [R, G, B: REAL];
Red, green, and blue, as for a color monitor or scanner; R, G, and B range from 0 to 1.
ColorFromRGB: PROC [rgb: RGB] RETURNS [OpConstantColor];
RGBFromColor: PROC [c: OpConstantColor] RETURNS [RGB];
NewColorOperatorRGB: PROC [sWhite: REAL, sBlack: REAL ¬ 0, map: PixelEncoding ¬ NIL, appearanceHints: Structure ¬ NIL] RETURNS [ColorOperator];
sWhite is the sample value to be mapped to R=G=B=1 and sBlack is the sample value to be mapped to R=G=B=0, where the R, G and B are the color coordinates of the Xerox/RGBLinear color model.
HSV
... convenience procedures; really produce an RGBLinear color.
ColorFromHSV: PROC [H, S, V: REAL] RETURNS [OpConstantColor];
HSVFromColor: PROC [c: OpConstantColor] RETURNS [H, S, V: REAL];
Hue, Saturation, Value; H, S, and V range from 0 to 1.
If V=0 (black), H and S are irrelevant. If S=0 (achromatic), H is irrelevant.
The HSV space is a hexcone; see Foley and van Dam, section 17.4.4.
YESLinear
... Xerox/YESLinear (Color Encoding Standard)
YES: TYPE ~ RECORD [Y, E, S: REAL];
ColorFromYES: PROC [yes: YES] RETURNS [OpConstantColor];
YESFromColor: PROC [c: OpConstantColor] RETURNS [yes: YES];
NewColorOperatorYES: PROC [sWhite, sBlack, sneutral, srange: REAL, map: PixelEncoding ¬ NIL, appearanceHints: Structure ¬ NIL] RETURNS [ColorOperator];
CIELAB
... Xerox/CIELAB (Color Encoding Standard)
CIELAB: TYPE ~ RECORD [lStar, aStar, bStar: REAL];
ColorFromCIELAB: PROC [cielab: CIELAB] RETURNS [OpConstantColor];
CIELABFromColor: PROC [c: OpConstantColor] RETURNS [CIELAB];
NewColorOperatorCIELAB: PROC [sWhite, sBlack, sneutral, srange: REAL, map: PixelEncoding ¬ NIL, appearanceHints: Structure ¬ NIL] RETURNS [ColorOperator];
Highlight
... Xerox/HighlightLinear (Color Encoding Standard)
Highlight: TYPE ~ RECORD [b, h: REAL];
ColorFromHighlight: PROC [highlight: Highlight] RETURNS [OpConstantColor];
HighlightFromColor: PROC [c: OpConstantColor] RETURNS [Highlight];
NewColorOperatorHighlight: PROC [sWhite, sBlack: REAL, map: PixelEncoding ¬ NIL, baseColor, highlightColor: OpConstantColor, appearanceHints: Structure ¬ NIL] RETURNS [ColorOperator];
Process, CMYK
... Xerox/Process (Color Encoding Standard)
MaxSampleProc: TYPE ~ PROC [pixelIndex: NAT] RETURNS [NAT];
SignalType: TYPE ~ MACHINE DEPENDENT { dotPercent, reflectance, transmittance, density, (CARD32.LAST) };
SignalTypeFromSignalTypeName: PROC [ROPE] RETURNS [SignalType];
SignalTypeNameFromSignalType: PROC [SignalType] RETURNS [ROPE];
NewColorOperatorProcess: PROC [su, sz: REAL, signals: NAT, map: PixelEncoding ¬ NIL, signalType: SignalType, signalNames: PROC [signal: NAT] RETURNS [ConstantColor], deviceProps: Structure ¬ NIL] RETURNS [ColorOperator];
... CMYK is a useful special case.
CMYK: TYPE ~ RECORD [C, M, Y, K: REAL];
Cyan, Magenta, Yellow, Black, for a color printer. C, M, Y, K range from 0 to 1
ColorFromCMYK: PROC [cmyk: CMYK] RETURNS [OpConstantColor];
Cyan, Magenta, Yellow, Black, in the range 0 to 1.
NewColorOperatorCMYK: PROC [maxIn: NAT] RETURNS [ColorOperator];
... a convenience color model for cyan, magenta, yellow, black separations; expects samplesPerPixel=4. For each separation, 0 ~ no ink, maxIn ~ full ink coverage. Really turns into a process ColorOperator.
END.