Color Approximation Table


Related topics include:

For an overview and a list of lookup tables, see Lookup Tables.

Color approximation lookup tables hold the information necessary to convert PEX colors to X11 colormap pixel values.

----------------------------------------------------------------------------------------------
Table Value                                          Description                Fallback   PEX
Mask
----------------------------------------------------------------------------------------------
PEXLUTVColorApproxMethod                                                                    5.0
                                                     color approximation type   (imp-dep)
PEXLUTVColorApproxModel                                                                     5.0
                                                     color approximation model  (imp-dep)
PEXLUTVColorApproxMax1                                                                      5.0
                                                     max1                       (imp-dep)
PEXLUTVColorApproxMax2                                                                      5.0
                                                     max2                       (imp-dep)
PEXLUTVColorApproxMax3                                                                      5.0
                                                     max3                       (imp-dep)
PEXLUTVColorApproxDither                                                                    5.0
                                                     dither                     (imp-dep)
PEXLUTVColorApproxMult1                                                                     5.0
                                                     mult1                      (imp-dep)
PEXLUTVColorApproxMult2                                                                     5.0
                                                     mult2                      (imp-dep)
PEXLUTVColorApproxMult3                                                                     5.0
                                                     mult3                      (imp-dep)
PEXLUTVColorApproxWeight1                                                                   5.0
                                                     weight1                    (imp-dep)
PEXLUTVColorApproxWeight2                                                                   5.0
                                                     weight2                    (imp-dep)
PEXLUTVColorApproxWeight3                                                                   5.0
                                                     weight3                    (imp-dep)
PEXLUTVColorApproxBasePixel                                                                 5.0
                                                     base pixel                 (imp-dep)
PEXLUTVColorApproxAll (selects entire table entry)                                          5.0
----------------------------------------------------------------------------------------------

Color approximation converts colors computed by the PEX rendering pipeline to pixel values. The PEX rendering pipeline produces a color in a multi-dimensional color space such as RGB. The PEX color approximation process converts that color, called the input color, to a pixel value that selects an entry in an X11 colormap. The method and arguments used to convert the color are taken from the color approximation table entry indicated by the pipeline state's color approximation index. Alpha values are unaffected by color approximation.

PEXlib defines the following values:

color approximation type:
The color approximation type specifies the method and parameters which are used to convert the input color to a pixel value that selects an entry in an X11 colormap.

PEXColorSpace -
intended for use with DirectColor, TrueColor, PseudoColor, and StaticColor visuals.

PEXColorRange -
intended for use with GrayScale and StaticGray visuals.
color approximation model:
During the color approximation process, each color produced by the rendering pipeline is first converted to the color model specified in the selected color approximation table entry. (When that color model is the same as that of the input color, this is an identity mapping.)
PEXColorApproxRGB -
specifies a red, green, blue color model

PEXColorApproxCIE -
specifies a CIELUV color model

PEXColorApproxHSV -
specifies hue, saturation, value

PEXColorApproxHLS -
specifies hue, lightness, saturation

PEXColorApproxYIQ - specifies NTSC luminance (Y), inphase (wideband orange-cyan), quadrature (narrowband magenta-green)

After the input color is converted to the color approximation color model, the converted color is converted to a pixel value according to the method you indicate by the color approximation type in the selected table entry.

ColorSpace Color Approximation

max1, max2, max3:
In ColorSpace color approximation, PEX scales each component of a color, (C1, C2, C3) by the corresponding max value, (max1, max2, max3), in the selected color approximation table entry, as follows:

The are conceptually rounded to integers in this operation.

max1, max2, and max3 typically indicate the number of samplings (minus 1) of each color component in a colormap organized as a color cube. For example, the max values in a colormap organized as a 3-3-2 color cube are 7, 7, 3 (23-1, 23-1, 22-1). Thus, the equation serves to scale the color coordinates into the available range of discrete colors.

The are converted to a pixel value by the formula given in the following equation: (1)

mult1, mult2, mult3, and base pixel:
In ColorSpace color approximation, the implementation combines the scaled color components to produce a pixel value P which is written to the drawable. Typically you use mult1, mult2, and mult3 to shift the color components to the bits within the pixel representing that color component. For example, the mult values in a colormap organized as a 3-3-2 color cube, where bits 5 - 7 of the pixel represent the C1 component, bits 2 - 4 the C2 component, and bits 0 and 1 the C3 component, would be 25, 22, and 1. Use the base pixel to shift the values up to the first pixel of the color cube within the colormap.

ColorSpace color approximation does not use the weight1, weight2, and weight3 values in the color approximation entry.

ColorRange Color Approximation

weight1, weight2, and weight3:
In ColorRange color approximation, PEXlib multiplies the color components in the color approximation color model, (C1, C2, C3), by the corresponding weights, (weight1, weight2, weight3), taken from the color approximation entry. These terms are added together to form a single, conceptual floating-point value:

The weights may emphasize, minimize, or eliminate one or more of the color components. For example, weights of (.299R,.587G,.114B) convert an RGB value to a single-valued intensity used in the NTSC color standard. Typically, you should normalize the weights so that they sum to 1; PEX does not normalize the weights.

After the weights are applied, the computed value, V, is multiplied by max1 in the color approximation entry:

max2 and max3 are not used.

The value V' is replicated for each of the three color components. Each component is then multiplied by mult1, mult2, or mult3, respectively, and the values are added together with base pixel to form the pixel value, P, written to the drawable: (2)

max1 is typically one less than the number of entries in a colormap. For example, a value of 99 for max1 scales colors to the range [0, 99], and might be used to display an image in gray scale using a colormap with 100 contiguous shades of gray. Typically mult1 is 1 and mult2 and mult3 are 0. PEX supports mult2 and mult3 so you can simulate gray ramps on a DirectColor visual by replicating the intensity in all three channels of the pixel.

Restrictions and Errors

Valid color approximation lookup table indices are in the range [0, 65534]. The fallback entry is entry 0.

Multipliers

For an overview of the color approximation lookup table, see Color Approximation Table.

Inquire BestColorApproxValues with request PEXGetImpDepConstants to determine what values, if any, of mult1, mult2, and mult3 are likely to result in the best performance.

Dithering

For an overview of the color approximation lookup table, see Color Approximation Table.

dither is a hint to the renderer as to whether some attempt at dithering (manipulation of pixel values in order to smooth the image) should be performed. With request PEXGetImpDepConstants inquire DitheringSupported to determine if the implementation can dither, and, if the implementation does support dithering, inquire DitheringControllable to determine if you can disable dithering with the dithering hint. Though the implementation might support dithering, the algorithm used is implementation-dependent.

The color approximation table is always accessed when rendering. The value of the pipeline state's color approximation index selects the desired entry of the table.

If you specify an unsupported color approximation type or unsupported color approximation model, then the implementation issues a BadValue error.