ImagerColorPrivate.mesa
Copyright Ó 1984, 1985, 1986, 1987, 1991, 1992 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 6, 1986 10:04:46 pm PST
Michael Plass, November 14, 1991 11:01 am PST
DIRECTORY
ImagerColor USING [Color, ColorOperator, ConstantColor, OpConstantColor, PixelEncoding, SampleEncoding, SampleTableProc, SpecialColor, Structure],
ImagerPixel USING [PixelBuffer, PixelMap, PixelProc],
ImagerPixelArray USING [PixelArray],
ImagerSample USING [Function],
Rope USING [ROPE],
SymTab USING [Ref];
ImagerColorPrivate: CEDAR DEFINITIONS
~ BEGIN
Color: TYPE ~ ImagerColor.Color;
ColorOperator: TYPE ~ ImagerColor.ColorOperator;
ConstantColor: TYPE ~ ImagerColor.ConstantColor;
OpConstantColor: TYPE ~ ImagerColor.OpConstantColor;
PixelBuffer: TYPE ~ ImagerPixel.PixelBuffer;
PixelArray: TYPE ~ ImagerPixelArray.PixelArray;
PixelMap: TYPE ~ ImagerPixel.PixelMap;
PixelProc: TYPE ~ ImagerPixel.PixelProc;
ROPE: TYPE ~ Rope.ROPE;
The Structure type
Structure: TYPE ~ ImagerColor.Structure;
Element: TYPE ~ RECORD [
SELECT tag: * FROM
atom => [atom: ATOM],
structure => [structure: Structure],
real => [real: REAL],
int => [int: INT],
color => [color: Color],
colorOperator => [colorOperator: ColorOperator],
ENDCASE
];
StructureClass: TYPE ~ REF StructureClassRep;
StructureClassRep: TYPE ~ RECORD [
size: PROC [structure: Structure] RETURNS [INT],
get: PROC [structure: Structure, i: INT] RETURNS [Element]
];
MakeStructure: PROC [class: StructureClass, data: REF] RETURNS [Structure];
SSize: PROC [structure: Structure] RETURNS [INT];
SCheckSize: PROC [structure: Structure, size: INT] RETURNS [INT];
Checks that Size[structure] = size, raising Imager.Error if not. Returns size.
SGet: PROC [structure: Structure, i: INT] RETURNS [Element];
The following procedures do a Get and then narrow to a particular type, raising Imager.Error if the types do not match.
SGetAtom: PROC [structure: Structure, i: INT] RETURNS [ATOM];
SGetReal: PROC [structure: Structure, i: INT] RETURNS [REAL];
SGetInt: PROC [structure: Structure, i: INT] RETURNS [INT];
SGetStructure: PROC [structure: Structure, i: INT] RETURNS [Structure];
SGetOptionalStructure: PROC [structure: Structure, i: INT, wantSize: INT ¬ -1] RETURNS [Structure];
Returns a structure, or NIL if the element was really 0.
SGetColor: PROC [structure: Structure, i: INT] RETURNS [Color];
SGetColorOperator: PROC [structure: Structure, i: INT] RETURNS [ColorOperator];
SGetProp: PROC [structure: Structure, key: ATOM] RETURNS [Element];
Get[structure, 2*i] is the key, Get[structure, 2*i+1] is the corresponding value
SMergeProp: PROC [s, t: Structure] RETURNS [Structure];
ElementAction: TYPE ~ PROC [element: Element];
ElementGenerator: TYPE ~ PROC [elementAction: ElementAction];
StructureFromElementGenerator: PROC [elementGenerator: ElementGenerator] RETURNS [Structure];
Makes a flat structure representation; note that the implementation may choose to call the ElementGenerator twice.
StructureFromList: PROC [list: LIST OF Element] RETURNS [Structure];
A convenience for clients; clients may also use their own representations.
StructureEqual: PROC [s, t: Structure] RETURNS [BOOL];
Does an element-by-element comparison.
ColorEqual: PROC [a, b: Color] RETURNS [BOOL];
In complicated cases, this may return FALSE when the colors are really equivalent.
SampleEncoding
PixelEncoding: TYPE ~ ImagerColor.PixelEncoding;
ApplyPixelEncoding: PROC [pm: PixelEncoding, i: NAT, value: REAL] RETURNS [REAL];
PixelEncodingEqual: PROC [a, b: PixelEncoding] RETURNS [BOOL];
PixelEncodingFromStructure: PROC [structure: Structure] RETURNS [PixelEncoding];
StructureFromPixelEncoding: PROC [map: PixelEncoding] RETURNS [Structure];
SampleEncoding: TYPE ~ ImagerColor.SampleEncoding;
MakeSampleEncoding: PROC [size: NAT ¬ 0, sampleTableProc: ImagerColor.SampleTableProc ¬ NIL] RETURNS [SampleEncoding];
SampleEncodingEqual: PROC [a, b: SampleEncoding] RETURNS [BOOL];
SampleEncodingFromStructure: PROC [structure: Structure] RETURNS [SampleEncoding];
StructureFromSampleEncoding: PROC [e: SampleEncoding] RETURNS [Structure];
Utilities
ConstantColorsEqual: PROC [a, b: ConstantColor] RETURNS [BOOL];
GrayFromColor: PROC [color: ConstantColor] RETURNS [REAL];
Returns Interpress-style gray, a fraction of absorptance from 0 (background) to 1 (black).
IntensityFromColor: PROC [color: ConstantColor] RETURNS [REAL];
Returns intensity, IN [0.0..1.0]
ApplyToList: PROC [colorOperator: ColorOperator, colorSpace: ColorSpace, pixel: LIST OF REAL] RETURNS [LIST OF REAL];
This is primarily for debugging color operators
Named Color Registry
namedColorTable: SymTab.Ref;
This is exported just in case clients need to examine it; normally clients should use the RegisterNamedColor and ImagerColor.Find procedures.
RegisterNamedColor: PROC [color: ImagerColor.SpecialColor];
Registers a name for ImagerColor.Find
The special color must have a non-NIL name.
May replace a previous entry with the same name, but this should not be the normal case.
ColorOutput
Signal: TYPE ~ REAL;
ColorPoint: TYPE ~ REF ColorPointRep;
ColorPointRep: TYPE ~ RECORD [
Represents a point in a device-specific color representation.
outOfGamut: BOOL ¬ FALSE,
s: SEQUENCE dim: NAT OF Signal
];
MakeColorPoint: PROC [dim: NAT, s: REAL ¬ 0.0] RETURNS [ColorPoint];
DestroyColorPoint: PROC [ColorPoint] RETURNS [ColorPoint ¬ NIL]; -- to scratch pool
ColorSpace: TYPE ~ MACHINE DEPENDENT { Y, RGB, CIELAB, YES, Highlight, firstProcess, (CARD.LAST) };
DefineProcessSpace: PROC [colorOperator: ColorOperator, val: ColorSpace[Y..firstProcess] ¬ firstProcess] RETURNS [ColorSpace];
Makes a color space that will match up with a particular color operator, usually a Process color operator. The val operand is for initializing the table, and should normally be defaulted.
ColorOperatorFromColorSpace: PROC [colorSpace: ColorSpace] RETURNS [ColorOperator];
Makes a color operator that describes the color space using the standard scaling; mostly interesting for things defined with DefineProcessSpace. Returns NIL if colorSpace is undefined.
ColorSpaceDimension: PROC [ColorSpace] RETURNS [NAT];
The dimensionality of the color space, e.g., 1 for Y, 3 for RGB, CIELAB, YES, etc.
GetPixelEncoding: PROC [colorOperator: ColorOperator] RETURNS [PixelEncoding];
Gets the colorOperator's pixelEncoding; a NIL pixelEncoding represents the identity function.
TransformConstantColor: PROC [color: OpConstantColor, colorSpace: ColorSpace] RETURNS [ColorPoint];
colorSpace must be one of the supported outputs of the colorOperator.
Color Space to Device Color Conversion
ColorTransform: TYPE ~ REF ColorTransformRep;
ColorTransformRep: TYPE ~ RECORD [
domain: ColorSpace,
rangeMax: ColorPoint, -- the maximum coordinate values
proc: PROC [self: ColorTransform, in: ColorPoint, out: ColorPoint],
proc fills in the ColorPoint "out". For out, the signals should be scaled such that is is reasonable to round them to a small, non-negative integer.
data: REF
];
ColorTransformGenerator: TYPE ~ REF ColorTransformGeneratorRep;
Note: The use of a ColorTransformGenerator is not required by this interface, but clients (typically device implementations) may find it to be a convenient way to have the functionality packaged.
ColorTransformGeneratorRep: TYPE ~ RECORD [
spaces: LIST OF ColorSpace,
The inputs list indicates preferred types of inputs (ie $RGB, $CIELAB); it is in order of preference. Normally the first of these will be constructed via DefineProcessSpace, so that the matching Process color operator will work without translation.
proc: PROC [self: ColorTransformGenerator, input: ColorSpace, appearanceHints: Structure] RETURNS [ColorTransform],
data: REF
];
ChooseColorSpace: PROC [colorOperator: ColorOperator, spaces: LIST OF ColorSpace] RETURNS [ColorSpace];
Selects from among the color spaces (listed in order of consumer preference) a color space that the color operator is willing to produce.
ColorPointFromColor: PROC [color: OpConstantColor, transform: ColorTransform] RETURNS [ColorPoint];
For constant colors. Clients should try to call DestroyColorPoint on the result when possible.
TranslateProc: TYPE ~ PROC [pixelsIn: PixelBuffer, pixelsOut: PixelBuffer];
A TranslateProc translates a sequence of pixels into the corresponding output pixels.
TranslatePixels: PROC [colorOperator: ColorOperator, transform: ColorTransform, maxIn: PixelProc, translateAction: PROC [translate: TranslateProc]];
Translate: PROC [colorOperator: ColorOperator, transform: ColorTransform, pa: PixelArray] RETURNS [PixelMap];
ColorOperatorClass
ColorOperatorClass: TYPE ~ REF ColorOperatorClassRep;
ColorOperatorClassRep: TYPE ~ RECORD [
name: ROPE, -- hierarchical name of Interpress color model operator
createColorOperator: ColorOperatorCreateProc, -- makes a new ColorOperator for this class
getCreateData: GetCreateDataProc, -- gets back the parameters to the color model operator
getPixelEncoding: GetPixelEncodingProc, -- tables for decoding sample values prior to calling apply
apply: ApplyProc, -- converts a single pixel
dataEqual: DataEqualProc, -- tests for equality of data
supportedOutputs: LIST OF ColorSpace
];
ColorOperatorCreateProc: TYPE ~ PROC [class: ColorOperatorClass, structure: Structure] RETURNS [ColorOperator];
GetCreateDataProc: TYPE ~ PROC [colorOperator: ColorOperator] RETURNS [Structure];
ApplyProc: TYPE ~ PROC [colorOperator: ColorOperator, pixelIn: TupleProc, colorSpace: ColorSpace, out: ColorPoint];
Applys the color operator to the tuple provided by pixelIn.
The colorOperator's pixelEncoding has already been applied to the input pixel.
Fills in out.
The colorSpace must be one of the supported outputs of the colorOperator.
The function computed by an ApplyProc should be fairly well behaved, so that interpolation may reasonably be used to evaluate it; this restriction is lifted if the input to the colorOperator is one-dimensional.
GetPixelEncodingProc: TYPE ~ PROC [colorOperator: ColorOperator] RETURNS [PixelEncoding];
TupleProc: TYPE ~ PROC [i: NAT] RETURNS [REAL];
DataEqualProc: TYPE ~ PROC [selfData, otherData: REF] RETURNS [BOOL];
colorOperatorClassTable: SymTab.Ref;
This is exported just in case clients need to examine it; normally clients should use the FindColorOperatorClass and NewColorOperatorClass procedures.
FindColorOperatorClass: PROC [name: ROPE] RETURNS [ColorOperatorClass];
Useful for Interpress, so it can call the class's CreateColorOperator proc. Other clients can just call the procedures provided in ImagerColor or ImagerColorFns, etc., to obtain a specific ColorOperator. In this capacity, a ColorOperatorClass is very closely related to an Interpress Color Model Operator, and this operation is needed by the Interpress FINDCOLORMODELOPERATOR operation.
NewColorOperatorClass: PROC [name: ROPE, createColorOperator: ColorOperatorCreateProc, getCreateData: GetCreateDataProc, getPixelEncoding: GetPixelEncodingProc, apply: ApplyProc, dataEqual: DataEqualProc, supportedOutputs: LIST OF ColorSpace] RETURNS [ColorOperatorClass];
This creates a ColorOperatorClass, and also registers it so that FindColorOperatorClass can find it.
NewColorOperator: PROC [chromatic: BOOL, samplesPerPixelIn: NAT, class: ColorOperatorClass, data: REF, appearanceHints: Structure] RETURNS [ColorOperator];
This allocates the color operator record, and canonicalizes the color operator; thus if the same operator is created twice with equivalent data fields, the results are ref equal
Stipple
Function: TYPE ~ ImagerSample.Function;
StippleData: TYPE ~ REF StippleDataRep;
StippleDataRep: TYPE ~ RECORD [word: WORD, function: Function];
IntensityFromStipple: PROC [word: WORD] RETURNS [REAL];
ColorFromStipple: PROC [word: WORD, function: Function] RETURNS [ImagerColor.SpecialColor];
END.