ImagerColor.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 6, 1986 9:59:30 pm PST
DIRECTORY
ImagerPixelArray USING [PixelArray],
ImagerSample USING [PixelBuffer, PixelMap, PixelProc, Sample, SampleBuffer, SampleMap],
ImagerTransformation USING [Transformation],
Rope USING [ROPE];
ImagerColor: CEDAR DEFINITIONS
~ BEGIN
Transformation: TYPE ~ ImagerTransformation.Transformation;
Sample: TYPE ~ ImagerSample.Sample;
SampleBuffer: TYPE ~ ImagerSample.SampleBuffer;
SampleMap: TYPE ~ ImagerSample.SampleMap;
PixelProc: TYPE ~ ImagerSample.PixelProc;
PixelBuffer: TYPE ~ ImagerSample.PixelBuffer;
PixelMap: TYPE ~ ImagerSample.PixelMap;
PixelArray: TYPE ~ ImagerPixelArray.PixelArray;
ROPE: TYPE ~ Rope.ROPE;
Color representations
XYZ: TYPE ~ RECORD [X, Y, Z: REAL];
CIE tristimulus values; by convention, X, Y, and Z range from 0 to about 100.
Corresponding chromaticity coordinates are x = X/(X+Y+Z) y = Y/(X+Y+Z) z = Z/(X+Y+Z)
Chromaticity: TYPE ~ RECORD [x, y: REAL];
CIE chromaticity; x and y are IN[0..1]. On the CIE chromaticity diagram, all points that correspond to physically realizable colors lie within the horseshoe-shaped spectrum locus.
illuminantC: Chromaticity ~ [x: 0.310, y: 0.317];
Chromaticity of CIE standard illuminant C (daylight).
ChromaticityFromXYZ: PROC [XYZ] RETURNS [Chromaticity];
Derives [x, y] from [X, Y, Z].
XYZFromChromaticity: PROC [c: Chromaticity, Y: REAL] RETURNS [XYZ];
Derives [X, Y, Z] from [x, y, Y].
RGBCalibration: TYPE ~ REF RGBCalibrationRep;
RGBCalibrationRep: TYPE ~ RECORD [
type: ATOM, -- identifying name
red: Chromaticity, -- CIE chromaticity of red phosphor
green: Chromaticity, -- CIE chromaticity of green phosphor
blue: Chromaticity, -- CIE chromaticity of blue phosphor
white: Chromaticity, -- CIE chromaticity of white (RGB[1, 1, 1])
YMax: REAL, -- maximum luminance, typically 100
impl: REF RGBCalibrationImplRep -- implementation data (matrices relating RGB and XYZ)
];
RGBCalibrationImplRep: TYPE;
An RGBCalibration specifies the relationship between RGB and CIE for a given device.
GetDefaultCalibration: PROC RETURNS [RGBCalibration];
Returns a "reasonable" calibration for a typical color monitor.
CreateCalibration: PROC [type: ATOM, red, green, blue: Chromaticity,
white: Chromaticity, YMax: REAL ← 100] RETURNS [RGBCalibration];
Creates a new RGB calibration.
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.
XYZFromRGB: PROC [rgb: RGB, calibration: RGBCalibration ← NIL] RETURNS [XYZ];
Converts RGB to XYZ; if calibration=NIL, uses the default calibration.
RGBFromXYZ: PROC [xyz: XYZ, calibration: RGBCalibration ← NIL] RETURNS [RGB];
Converts XYZ to RGB; if calibration=NIL, uses the default calibration.
May return values outside [0..1] if the color is outside the device's gamut.
RGBMaxY: PROC [c: Chromaticity, calibration: RGBCalibration ← NIL] RETURNS [Y: REAL];
For the given CIE chromaticity, returns the maximum Y attainable with RGB.
[x, y, Y] is inside the device's gamut iff Y<=RGBMaxY[[x, y], calibration].
YIQ: TYPE ~ RECORD [Y, I, Q: REAL];
YIQ is the scheme used for color television; see Foley and van Dam, section 17.4.3.
Y, I, and Q range from 0 to 1; Y is luminance, roughly corresponding to XYZ.Y/100.
Y = .30*R+.59*G+.11*B I = .60*R-.28*G-.32*B Q = .21*R-.52*G+.31*B
YIQFromRGB: PROC [RGB] RETURNS [YIQ];
RGBFromYIQ: PROC [YIQ] RETURNS [RGB];
Conversion between RGB and YIQ.
HSV: TYPE ~ RECORD [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.
HSVFromRGB: PROC [RGB] RETURNS [HSV];
RGBFromHSV: PROC [HSV] RETURNS [RGB];
Conversion between RGB and HSV.
HSL: TYPE ~ RECORD [H, S, L: REAL];
Hue, Saturation, Lightness; H, S, and L range from 0 to 1.
If L=0 (black) or L=1 (white), H and S are irrelevant. If S=0 (achromatic), H is irrelevant.
The HSL space is a double hexcone; see Foley and van Dam, section 17.4.5 (they call it HLS).
HSLFromRGB: PROC [RGB] RETURNS [HSL];
RGBFromHSL: PROC [HSL] RETURNS [RGB];
Conversion between RGB and HSL.
The Color type
Color: TYPE ~ REF ColorRep;
ColorRep: TYPE ~ RECORD [
SELECT tag: * FROM
constant => [
colorOperator: ColorOperator,
pixel: SEQUENCE size: NAT OF Sample
],
sampled => [ -- the result of MakeSampledColor
pa: PixelArray, -- the array of pixels
um: Transformation, -- transforms from color to device coordinates
colorOperator: ColorOperator -- maps pixels into constant colors
],
sampledBlack => [ -- the result of MakeSampledBlack
pa: PixelArray, -- the array of pixels (must be 1 bit per pixel)
um: Transformation, -- transforms from color to device coordinates
clear: BOOL -- are zero bits transparent?
],
special => [ -- XOR, stipples, and the like
type: ATOM,
data: REF,
substitute: Color -- use this if you don't recognize type
],
ENDCASE
];
ConstantColor: TYPE ~ REF ColorRep.constant;
SampledColor: TYPE ~ REF ColorRep.sampled;
SampledBlack: TYPE ~ REF ColorRep.sampledBlack;
SpecialColor: TYPE ~ REF ColorRep.special;
Color operators
ColorOperator: TYPE ~ REF ColorOperatorRep;
ColorOperatorRep: TYPE ~ RECORD [
chromatic: BOOL,
samplesPerPixelIn: NAT,
class: REF ColorOperatorClassRep,
data: REF
];
ColorOperatorClassRep: TYPE;
ColorOutput: TYPE ~ REF ColorOutputRep;
ColorOutputRep: TYPE ~ RECORD [
type: ATOM,
samplesPerPixelOut: NAT,
impl: REF ColorOutputImplRep
];
ColorOutputImplRep: TYPE;
TupleProc: TYPE ~ PROC [i: NAT] RETURNS [REAL];
TranslateProc: TYPE ~ PROC [pixelsIn: PixelBuffer, pixelsOut: PixelBuffer];
Apply: PROC [self: ColorOperator, pixel: PixelProc] RETURNS [ConstantColor];
Applies a color operator to a single pixel to produce a constant color.
TupleFromPixel: PROC [self: ColorOperator, output: ColorOutput,
pixelIn: PixelProc, tupleAction: PROC [tupleOut: TupleProc]];
PixelFromPixel: PROC [self: ColorOperator, output: ColorOutput,
pixelIn: PixelProc, maxOut: PixelProc, pixelAction: PROC [pixelOut: PixelProc]];
TranslatePixels: PROC [self: ColorOperator, output: ColorOutput,
maxIn: PixelProc, maxOut: PixelProc, translateAction: PROC [translate: TranslateProc]];
Translate: PROC [self: ColorOperator, output: ColorOutput,
pa: PixelArray, maxOut: PixelProc] RETURNS [PixelMap];
Making constant colors
ColorFromGray: PROC [f: REAL] RETURNS [ConstantColor];
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.
ColorFromXYZ: PROC [xyz: XYZ] RETURNS [ConstantColor];
CIE tristimulus values, X, Y, Z, in the range 0 to approximately 100.
ColorFromRGB: PROC [rgb: RGB, calibration: RGBCalibration ← NIL] RETURNS [ConstantColor];
Red, Green, Blue, in the range 0 to 1. If calibration=NIL, the color is uncalibrated.
ColorFromYIQ: PROC [yiq: YIQ, calibration: RGBCalibration ← NIL] RETURNS [ConstantColor];
ColorFromHSV: PROC [hsv: HSV, calibration: RGBCalibration ← NIL] RETURNS [ConstantColor];
ColorFromHSL: PROC [hsl: HSL, calibration: RGBCalibration ← NIL] RETURNS [ConstantColor];
TupleFromColor: PROC [self: ConstantColor, output: ColorOutput,
tupleAction: PROC [tupleOut: TupleProc]];
PixelFromColor: PROC [self: ConstantColor, output: ColorOutput,
maxOut: PixelProc, pixelAction: PROC [pixelOut: PixelProc]];
GrayFromColor: PROC [color: ConstantColor] RETURNS [REAL];
Returns Interpress-style gray, a fraction of absorptance from 0 (background) to 1 (black).
Making sampled colors
MakeSampledBlack: PROC [pa: PixelArray, um: Transformation, clear: BOOLFALSE]
RETURNS
[SampledBlack];
MakeSampledColor: PROC [pa: PixelArray, um: Transformation, colorOperator: ColorOperator]
RETURNS
[SampledColor];
END.