# RGB & HSV Colorspaces

Both the RGB and HSV Colorspaces define a method of uniquely specifying colors via three numbers.

The RGB colorspace is the more commonly used of the two. For example, most color monitors operate on RGB inputs. In RGB colorspace, each color is represented by a three number 'triple'. The components of this triple specify, respectively, the amount of red, the amount of green, and the amount of blue in the color. In most computer graphics systems (and in xv), these values are represented as 8-bit unsigned numbers. Thus, each component has a range of 0-255, inclusive, with 0 meaning 'no output', and 255 meaning 'full output'.

The eight 'primary' colors in the RGB colorspace, and their values in the standard 8-bit unsigned range are:

```Black    (  0,  0,  0)
Red      (255,  0,  0)
Green    (  0,255,  0)
Yellow   (255,255,  0)
Blue     (  0,  0,255)
Magenta  (255,  0,255)
Cyan     (  0,255,255)
White    (255,255,255)```

Other colors are specified by intermediate values. For example, orange is chromatically between red and yellow on the color spectrum. To get an orange, you can simply average red (255,0,0) and yellow (255,255,0) on a component-by-component basis resulting in (255,127,0), which will be some orange-ish color.

You can change the brightness of the colors by raising or lowering all of their components by some factor. For example, if (0,255,255) is cyan (it is), then (0,128,128) would be a dark cyan.

Saturation of a color is a measure of how 'pure' the color is. Desaturated colors will appear washed-out, or pastel, whereas saturated colors will be bold and vibrant, the sort of colors you'd paint a sports car. In the RGB colorspace, you can desaturate colors by adding white to them. For example, if you take red (255,0,0), and add a medium grey to it (128,128,128), you'll get a shade of pink (255,128,128). Note that the component values are 'clipped' to remain in the range 0-255.

The HSV colorspace works somewhat differently. It is considered by many to be more intuitive to use, closer to how an artist actually mixes colors.

In the HSV colorspace, each color is again determined by a three-component 'triple'. The first component, Hue, describes the basic color in terms of its angular position on a 'color wheel'. In this particular implementation, Hue is described in terms of degrees.

Unfortunately, since this document isn't printed in color, it is not possible to show this 'color wheel' in any meaningful way. Here is where the 'primary' colors live:

```Red       0
Yellow   60
Green   120
Cyan    180
Blue    240
Magenta 300
```

The colors appear in the same order that they do on a standard color spectrum, except that they form a circle, with magenta looping back to red.

As with the RGB space, in-between colors are represented by in-between values. For example, orange would have a Hue value of 30, being situated roughly halfway between red and yellow.

The second component of the HSV triple is Saturation, which, as described above, can be thought of as "how pure the color is". In this implementation, saturation can range between 0 and 100, inclusive. Colors with a saturation of 100 are fully-saturated, whereas colors with a saturation of 0 are completely desaturated (in other words, grey).

The third component of the HSV triple is Value , which really should be called Intensity. It is a measure of how 'bright' the color is. In this implementation, Value can range between 0 and 100, inclusive. A color with a Value component of 100 will be as bright as possible, and a color with a Value component of 0 will be as dark as possible (i.e., black).