Digging Deeper - The Format of Color

From the comments embedded within the Imaging.h file:

Image pixels are composed of colors. The representation of color in an image, its color format, can take many forms.

a) Indexed vs Direct Color

Color information in an image may be directly specified in the image’s data stream or indirectly via indexes into an associated color palette.

b) Colorspace

Colorspaces are used to define the gamut of available hues. Common colorspaces include RGB, CMYK and Grayscale. Green in RGB would be defined as the tuple { 0, 255, 0 }, in CMYK as the quadruple { 255, 0, 255, 0 } and could not be defined in the Grayscale color space.

Individual values in a color specification are typically called components.

In direct color images, the image’s data stream consists of the color components of all the pixels in the image. In indexed color images, each value in the data stream is an index into a palette of color specifications.

The typical data types of each component varies according to the colorspace and/or the range of available hues. Typically, components are represented as 8-bit unsigned integers, but 16-bit unsigned integers and floating point numbers can be used as well.

c) Depth

Even after taking the component type into account, it is possible that the range of available hues is such that even the smallest base data type, 8-bit unsigned integer, is too large. Black & white images, for example, only contain 2 colors and only need 1-bit per pixel to represent the image. In these situations, each component data value may contain data for more than one pixel. For example, an 8-bit unsigned integer can contain enough color component data for 8 pixels if the color depth is only 1 bit.

d) Layout

The layout of a color specification varies for non-grayscale direct color images. There are two basic types of layouts: planar and interleaved. The planar layout organizes the pixel data by colorspace components. The interleaved layout organizes the pixel data by pixel. A third layout, reverse interleaved, also organizes the pixel data by pixel, but has the component data in reverse order. Frex, RGB data in reverse interleaved layout would group the pixel data as BGRBGRBGR… Finally, a fourth layout, masked interleaved, associates a series of mask values to determine the component layout of the pixels. Frex, an RGB masked layout may consist of three masks: 0×00FF00, 0×0000FF, 0xFF0000 to define a BRG interleaved order among a pixel stream of 24-bit data.

Comments are closed.