Skip to main content

Color

Contains functionality for color conversion.

Public Functions

FORCE_INLINE_FUNCTION uint8_tgetBlueColor(colortype color)
Gets the blue color part of a color.
colortypegetColorFrom24BitHSL(uint8_t hue, uint8_t saturation, uint8_t luminance)
Convert a given color from HSV (Hue, Saturation, Value) to colortype.
colortypegetColorFrom24BitHSV(uint8_t hue, uint8_t saturation, uint8_t value)
Convert a given color from HSV (Hue, Saturation, Value) to colortype.
colortypegetColorFrom24BitRGB(uint8_t red, uint8_t green, uint8_t blue)
Generates a color representation to be used on the LCD, based on 24 bit RGB values.
FORCE_INLINE_FUNCTION uint8_tgetGreenColor(colortype color)
Gets the green color part of a color.
voidgetHSLFrom24BitRGB(uint8_t red, uint8_t green, uint8_t blue, uint8_t & hue, uint8_t & saturation, uint8_t & luminance)
Convert a given color from RGB (Red, Green, Blue) to HSV (Hue, Saturation, Value).
voidgetHSLFromColor(colortype color, uint8_t & hue, uint8_t & saturation, uint8_t & luminance)
Convert a given colortype color to HSV (Hue, Saturation, Value).
voidgetHSLFromHSV(uint8_t hue, uint8_t & saturation, uint8_t value, uint8_t & luminance)
Convert HSV (Hue, Saturation, Value) to HSL (Hue, Saturation, Luminance).
voidgetHSVFrom24BitRGB(uint8_t red, uint8_t green, uint8_t blue, uint8_t & hue, uint8_t & saturation, uint8_t & value)
Convert a given color from RGB (Red, Green, Blue) to HSV (Hue, Saturation, Value).
voidgetHSVFromColor(colortype color, uint8_t & hue, uint8_t & saturation, uint8_t & value)
Convert a given colortype color to HSV (Hue, Saturation, Value).
voidgetHSVFromHSL(uint8_t hue, uint8_t & saturation, uint8_t luminance, uint8_t & value)
Convert HSL (Hue, Saturation, Luminance) to HSV (Hue, Saturation, Value).
FORCE_INLINE_FUNCTION uint8_tgetRedColor(colortype color)
Gets the red color part of a color.
voidgetRGBFrom24BitHSL(uint8_t hue, uint8_t saturation, uint8_t luminance, uint8_t & red, uint8_t & green, uint8_t & blue)
Convert a given color from HSV (Hue, Saturation, Value) to RGB (Red, Green, Blue).
voidgetRGBFrom24BitHSV(uint8_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue)
Convert a given color from HSV (Hue, Saturation, Value) to RGB (Red, Green, Blue).

Public Functions Documentation

getBlueColor

static FORCE_INLINE_FUNCTION uint8_t getBlueColor(colortypecolor)

Gets the blue color part of a color.

As this function must work for all color depths, it can be somewhat slow if used in speed critical sections. Consider finding the color in another way, if possible. If the color depth of the display is known, consider using function getBlueFromColor() from the current LCD.

Parameters:
colorThe color value.
Returns:

The blue part of the color.

See also:

getColorFrom24BitHSL

static colortype getColorFrom24BitHSL(uint8_thue ,
uint8_tsaturation ,
uint8_tluminance
)

Convert a given color from HSV (Hue, Saturation, Value) to colortype.

Parameters:
hueThe input Hue (0 to 255).
saturationThe input Saturation (0 to 255).
luminanceThe input Value (0 to 255).
Returns:

The colortype color.

Note

The conversion is an approximation.

getColorFrom24BitHSV

static colortype getColorFrom24BitHSV(uint8_thue ,
uint8_tsaturation ,
uint8_tvalue
)

Convert a given color from HSV (Hue, Saturation, Value) to colortype.

Parameters:
hueThe input Hue (0 to 255).
saturationThe input Saturation (0 to 255).
valueThe input Value (0 to 255).
Returns:

The colortype color.

Note

The conversion is an approximation.

getColorFrom24BitRGB

static colortype getColorFrom24BitRGB(uint8_tred ,
uint8_tgreen ,
uint8_tblue
)

Generates a color representation to be used on the LCD, based on 24 bit RGB values.

Depending on your display color bit depth, the color might be interpreted internally as fewer than 24 bits with a loss of color precision.

Parameters:
redValue of the red part (0-255).
greenValue of the green part (0-255).
blueValue of the blue part (0-255).
Returns:

The color representation depending on LCD color format.

Note

This function is not available to call before the LCD has been setup, because the color depth is required. Consider using the function getColorFromRGB for a specific class, e.g. LCD16::getColorFromRGB().

See also:

getGreenColor

static FORCE_INLINE_FUNCTION uint8_t getGreenColor(colortypecolor)

Gets the green color part of a color.

As this function must work for all color depths, it can be somewhat slow if used in speed critical sections. Consider finding the color in another way, if possible. If the color depth of the display is known, consider using function getGreenFromColor() from the current LCD.

Parameters:
colorThe color value.
Returns:

The green part of the color.

See also:

getHSLFrom24BitRGB

static void getHSLFrom24BitRGB(uint8_tred ,
uint8_tgreen ,
uint8_tblue ,
uint8_t &hue ,
uint8_t &saturation ,
uint8_t &luminance
)

Convert a given color from RGB (Red, Green, Blue) to HSV (Hue, Saturation, Value).

Parameters:
redThe input Red (0 to 255).
greenThe input Green (0 to 255).
blueThe input Blue (0 to 255).
hueThe output Hue (0 to 255).
saturationThe output Saturation (0 to 255).
luminanceThe output Value (0 to 255).
Note

The conversion is an approximation.

getHSLFromColor

static void getHSLFromColor(colortypecolor ,
uint8_t &hue ,
uint8_t &saturation ,
uint8_t &luminance
)

Convert a given colortype color to HSV (Hue, Saturation, Value).

Parameters:
colorThe input color.
hueThe output Hue (0 to 255).
saturationThe output Saturation (0 to 255).
luminanceThe output Value (0 to 255).
Note

The conversion is an approximation.

getHSLFromHSV

static void getHSLFromHSV(uint8_thue ,
uint8_t &saturation ,
uint8_tvalue ,
uint8_t &luminance
)

Convert HSV (Hue, Saturation, Value) to HSL (Hue, Saturation, Luminance).

The Hue is unaltered, the Saturation is changed and the Luminance is calculated.

Parameters:
hueThe hue (0 to 255).
saturationThe saturation (0 to 255).
valueThe value (0 to 255).
luminanceThe luminance (0 to 255).

getHSVFrom24BitRGB

static void getHSVFrom24BitRGB(uint8_tred ,
uint8_tgreen ,
uint8_tblue ,
uint8_t &hue ,
uint8_t &saturation ,
uint8_t &value
)

Convert a given color from RGB (Red, Green, Blue) to HSV (Hue, Saturation, Value).

Parameters:
redThe input Red.
greenThe input Green.
blueThe input Blue.
hueThe output Hue.
saturationThe output Saturation.
valueThe output Value.
Note

The conversion is an approximation.

getHSVFromColor

static void getHSVFromColor(colortypecolor ,
uint8_t &hue ,
uint8_t &saturation ,
uint8_t &value
)

Convert a given colortype color to HSV (Hue, Saturation, Value).

Parameters:
colorThe input color.
hueThe output Hue (0 to 255).
saturationThe output Saturation (0 to 255).
valueThe output Value (0 to 255).
Note

The conversion is an approximation.

getHSVFromHSL

static void getHSVFromHSL(uint8_thue ,
uint8_t &saturation ,
uint8_tluminance ,
uint8_t &value
)

Convert HSL (Hue, Saturation, Luminance) to HSV (Hue, Saturation, Value).

The Hue is unaltered, the Saturation is changed and the Value is calculated.

Parameters:
hueThe hue (0 to 255).
saturationThe saturation (0 to 255).
luminanceThe luminance (0 to 255).
valueThe value (0 to 255).

getRedColor

static FORCE_INLINE_FUNCTION uint8_t getRedColor(colortypecolor)

Gets the red color part of a color.

As this function must work for all color depths, it can be somewhat slow if used in speed critical sections. Consider finding the color in another way, if possible. If the color depth of the display is known, consider using function getRedFromColor() from the current LCD.

Parameters:
colorThe color value.
Returns:

The red part of the color.

See also:

getRGBFrom24BitHSL

static void getRGBFrom24BitHSL(uint8_thue ,
uint8_tsaturation ,
uint8_tluminance ,
uint8_t &red ,
uint8_t &green ,
uint8_t &blue
)

Convert a given color from HSV (Hue, Saturation, Value) to RGB (Red, Green, Blue).

Parameters:
hueThe input Hue (0 to 255).
saturationThe input Saturation (0 to 255).
luminanceThe input Value (0 to 255).
redThe output Red (0 to 255).
greenThe output Green (0 to 255).
blueThe output Blue (0 to 255).
Note

The conversion is an approximation.

getRGBFrom24BitHSV

static void getRGBFrom24BitHSV(uint8_thue ,
uint8_tsaturation ,
uint8_tvalue ,
uint8_t &red ,
uint8_t &green ,
uint8_t &blue
)

Convert a given color from HSV (Hue, Saturation, Value) to RGB (Red, Green, Blue).

Parameters:
hueThe input Hue (0 to 255).
saturationThe input Saturation (0 to 255).
valueThe input Value (0 to 255).
redThe output Red (0 to 255).
greenThe output Green (0 to 255).
blueThe output Blue (0 to 255).
Note

The conversion is an approximation.