Why an article on "colors"? It's the same question I asked myself before writing this series.

The fact is, in .NET, there are only two color formats that can be used: the RGB color model and the HSB color model. Those two are encapsulated in the Color structure of the System.Drawing namespace.

It is largely sufficient for simple uses, like changing the background color of a component, but insufficient if we want to develop graphic tools (or something which implies conversion between color formats).

I've started looking for other formats, like CMYK, when I was learning how to add cool design-time support to my custom controls. But, I quickly understood the utilities I was coding would be more than useful in other projects, like my SVG editor.

That's why I publish this series of 3 articles. The proposed article content will be as follows:

Part 1: This one, will be an introduction into color spaces, and the most used ones.

Part 2: Will be about dedicated controls, or how to select/define a color with custom components. I will share a lot of my custom controls for this purpose.

Part 3: Will be about how to use those color controls at design-time. It will be a tutorial on how to create your own editors.

Let's start with some definitions

"Color (or colour, see spelling differences) is the visual perceptual property corresponding in humans to the categories called red, yellow, white, etc. Color derives from the spectrum of light (distribution of light energy versus wavelength) interacting in the eye with the spectral sensitivities of the light receptors. Color categories and physical specifications of color are also associated with objects, materials, light sources, etc., based on their physical properties such as light absorption, reflection, or emission spectra."

"Colorimetry is the science that describes colors in numbers, or provides a physical color match using a variety of measurement instruments. Colorimetry is used in chemistry, and in industries such as color printing, textile manufacturing, paint manufacturing and in the food industry."

I - Color models

A - RGB (Red Green Blue)

The RGB (Red, Green, Blue) color model is the most known, and the most used every day. It defines a color space in terms of three components:

Red, which ranges from 0-255

Green, which ranges from 0-255

Blue, which ranges from 0-255

The RGB color model is an additive one. In other words, Red, Green and Blue values (known as the three primary colors) are combined to reproduce other colors.For example, the color "Red" can be represented as [R=255, G=0, B=0], "Violet" as [R=238, G=130, B=238], etc.

Its common graphic representation is the following image:

In .NET, the Color structure use this model to provide color support through R, G and B properties.

B - HSB color space

Ranges from 0 to 360° in most applications. (each value corresponds to one color : 0 is red, 45 is a shade of orange and 55 is a shade of yellow).

Saturation : the intensity of the color.

Ranges from 0 to 100% (0 means no color, that is a shade of grey between black and white; 100 means intense color).

Also sometimes called the "purity" by analogy to the colorimetric quantities excitation purity.

Brightness (or Value) : the brightness of the color.

Ranges from 0 to 100% (0 is always black; depending on the saturation, 100 may be white or a more or less saturated color).

Its common graphic representation is the following image:

The HSB model is also known as HSV (Hue, Saturation, Value) model. The HSV model was created in 1978 by Alvy Ray Smith. It is a nonlinear transformation of the RGB color space. In other words, color is not defined as a simple combination (addition/substraction) of primary colors but as a mathematical transformation.

It is a subtractive color model used in color printing. CMYK works on an optical illusion that is based on light absorption.The principle is to superimpose three images; one for cyan, one for magenta and one for yellow; which will reproduce colors.

Its common graphic representation is the following image:

Like the RGB color model, CMYK is a combination of primary colors (cyan, magenta, yellow and black). It is, probably, the only thing they have in common.CMYK suffers from a lack of color shades that causes holes in the color spectrum it can reproduce. That's why there are often differencies when someone convert a color between CMYK to RGB.

Why using this model? Why black is used? you can tell me... Well it's only for practical purpose. Wikipedia said:

To improve print quality and reduce moiré patterns,

Text is typically printed in black and includes fine detail (such as serifs); so to reproduce text using three inks would require an extremely precise alignment for each three components image.

Mixing all three color inks together to make black can make the paper rather wet when not using dry toner, which is an issue in high speed printing where the paper must dry extremely rapidly to avoid marking the next sheet, and poor quality paper such as newsprint may break if it becomes too wet.

Using a unit amount of black ink rather than three unit amounts of the process color inks can lead to significant cost savings (black ink is often cheaper).

E - YUV color space

The YUV model defines a color space in terms of one luma and two chrominance components. The YUV color model is used in the PAL, NTSC, and SECAM composite color video standards.YUV models human perception of color more closely than the standard RGB model used in computer graphics hardware.

The YUV color space stands for:

Y, the luma component, or the brightness.

Ranges from 0 to 100% in most applications.

U and V are the chrominance components (blue-luminance and red-luminance differences components).

F - CIE XYZ color space

In opposition to the previous models, the CIE XYZ model defines an absolute color space. It is also known as the CIE 1931 XYZ color space and stands for:

X, which can be compared to red

Ranges from 0 to 0.9505

Y, which can be compared to green

Ranges from 0 to 1.0

Z, which can be compared to blue

Ranges from 0 to 1.089

Before trying to explain why I include this color space in this article, you have to know that it's one of the first standards created by the International Commission on Illumination (CIE) in 1931. It is based on direct measurements of the human eye, and serves as the basis from which many other color spaces are defined.

I have made a quick research to include Cie L*a*b* color model in this article, and I find that a conversion to an absolute color space is required before converting to L*a*b*. The model used in the conversion principle is Cie XYZ. So, I've included it and now everyone can understand "what are those XYZ values" used further in the article.

G - CIE L*a*b* color space

"A Lab color space is a color-opponent space with dimension L for luminance and a and b for the color-opponent dimensions, based on nonlinearly-compressed CIE XYZ color space coordinates."

As said in the previous definition, CIE L*a*b* color space, also know as CIE 1976 color space, stands for:

L*, the luminance

a*, the red/green color-opponent dimension

b*, the yellow/blue color-opponent dimension

The L*a*b* color model has been created to serve as a device independent model to be used as a reference. It is based directly on the CIE 1931 XYZ color space as an attempt to linearize the perceptibility of color differences.

The non-linear relations for L*, a*, and b* are intended to mimic the logarithmic response of the eye, coloring information is referred to the color of the white point of the system.