color.h

Provides generic support for colour conversions.

The library is currently aware of both the RGB and YUV colour spaces and this module allows you to convert between the two. Note that not all of the colours in one colour space are exactly reproducible in another and hence converting from one colour space and back again will not necessarily give the same result.

A colour variable can be created using:-

COLOR myColor;

Although this variable will start with an 'unknown' value.

However: you can assign it a known value using the 'colorSetRGB', 'colorSetYUV' commands. Or you may assign it a value from another colour value using the 'color2rgb', 'color2yuv' commands.

COLOR_RGB* color2rgb(const COLOR * src, COLOR* dest)

The first parameter points to an existing colour which may be in any colour space. The second parameter points to a colour variable which will be assigned the RGB value.

COLOR_YUV* color2yuv(const COLOR * src, COLOR* dest)

Copies a colour and converts it to YUV if required.

The first parameter points to an existing colour which may be in any colour space. The second parameter points to a colour variable which will be assigned the YUV value.

colorSetRGB(COLOR* color, uint8_t r, uint8_t g, uint8_t b )

Assign an RGB value to colour.

The first parameter is the address of the colour variable and the remaining parameters specify the RGB values in the range 0 to 255.

So to set a colour variable to 'red' then use:

COLOR red;

colorSetRGB(&red, 255, 0, 0);

colorSetYUV(COLOR* color, uint8_t y, uint8_t u, uint8_t v )

Assign a YUV value to a colour.

The first parameter is the address of the colour variable and the remaining parameters specify the YUV values in the range 0 to 255.

Example:

COLOR c;

colorSetYUV(&c, 0, 127, 127); // Assign it yuv = 0,127,127

colorDump(const COLOR* color)

Dump a colour value to the current rprintf destination.

boolean colorEquals(const COLOR* c1, const COLOR* c2)

Test if two colours are the same.

The two parameters are the addresses of colours. The function will return TRUE if, and only if, the two colours of the same colour space (ie both RGB or both YUV) and all of the colour band values are the same.