ImagerColor.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, May 12, 1985 3:55:28 pm PDT
DIRECTORY
ImagerColorDefs USING [Color, ColorOperator, ConstantColor, SampledColor],
ImagerPixelArrayDefs USING [PixelArray],
ImagerTransformation USING [Transformation],
Rope USING [ROPE];
ImagerColor: CEDAR DEFINITIONS
~ BEGIN
Color: TYPE ~ ImagerColorDefs.Color;
ConstantColor: TYPE ~ ImagerColorDefs.ConstantColor;
SampledColor: TYPE ~ ImagerColorDefs.SampledColor;
ColorOperator: TYPE ~ ImagerColorDefs.ColorOperator;
PixelArray: TYPE ~ ImagerPixelArrayDefs.PixelArray;
Transformation: TYPE ~ ImagerTransformation.Transformation;
ROPE: TYPE ~ Rope.ROPE;
Color Models
CIE: 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)
CIEChromaticity: 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: CIEChromaticity ~ [x: 0.310, y: 0.317];
Chromaticity of CIE standard illuminant C (daylight).
ChromaticityFromCIE: PROC [CIE] RETURNS [CIEChromaticity];
Derives [x, y] from [X, Y, Z].
CIEFromChromaticity: PROC [c: CIEChromaticity, Y: REAL] RETURNS [CIE];
Derives [X, Y, Z] from [x, y, Y].
RGBCalibration: TYPE ~ REF RGBCalibrationRep;
RGBCalibrationRep: TYPE ~ RECORD [
type: ATOM, -- identifying name
red: CIEChromaticity, -- CIE chromaticity of red phosphor
green: CIEChromaticity, -- CIE chromaticity of green phosphor
blue: CIEChromaticity, -- CIE chromaticity of blue phosphor
white: CIEChromaticity, -- 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: CIEChromaticity,
white: CIEChromaticity, 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.
CIEFromRGB: PROC [rgb: RGB, calibration: RGBCalibration ← NIL] RETURNS [CIE];
Converts RGB to CIE; if calibration=NIL, uses the default calibration.
RGBFromCIE: PROC [cie: CIE, calibration: RGBCalibration ← NIL] RETURNS [RGB];
Converts CIE 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: CIEChromaticity, 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 CIE.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.
Constant Colors
Find: PROC [name: ROPE] RETURNS [ConstantColor];
Finds the color with the given hierarchical name (for Interpress).
ColorFromAtom: PROC [atom: ATOM] RETURNS [ConstantColor];
Returns a well-known color identified by the atom; if atom is unknown, returns NIL.
Among the currently recognized atoms are:
$White $Gray $Black $Invert $Clear
$Red $Green $Blue $Cyan $Magenta $Yellow
$Pink $Orange $Brown $Olive $YellowGreen $Purple
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.
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.
ColorFromCIE: PROC [cie: CIE] RETURNS [ConstantColor];
CIE tristimulus values, X, Y, Z, in the range 0 to approximately 100.
GrayFromColor: PROC [color: ConstantColor] RETURNS [REAL];
Returns Interpress-style gray, a fraction of absorptance from 0 (background) to 1 (black).
AtomFromColor: PROC [color: ConstantColor] RETURNS [ATOM];
If color came from ColorFromAtom, returns the atom; otherwise returns NIL.
Sampled Colors
MakeSampledBlack: PROC [pa: PixelArray, um: Transformation, clear: BOOLFALSE]
RETURNS
[SampledColor];
MakeSampledColor: PROC [pa: PixelArray, um: Transformation, colorOperator: ColorOperator]
RETURNS
[SampledColor];
END.