M5Unit-COLOR 0.2.0 git rev:d6fe6e1
Loading...
Searching...
No Matches
color_correction.cpp File Reference

Color corrections for 8-bit RGB values. More...

#include "color_correction.hpp"
#include <algorithm>

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Functions

RGB8 m5::unit::tcs3472x::pureHue (const uint8_t r, const uint8_t g, const uint8_t b)
 Pure hue.
 
RGB8 m5::unit::tcs3472x::normalizeBrightness (const uint8_t r, const uint8_t g, const uint8_t b)
 Brightness normalization.
 
RGB8 m5::unit::tcs3472x::grayscale (const uint8_t r, const uint8_t g, const uint8_t b)
 Grayscale.
 
ColorName m5::unit::tcs3472x::nearestColorName (const uint8_t r, const uint8_t g, const uint8_t b)
 Nearest color name.
 
RGB8 m5::unit::tcs3472x::colorNameToRGB (const ColorName name)
 Representative color of the color name.
 
const char * m5::unit::tcs3472x::colorNameToString (const ColorName name)
 String of the color name.
 

Detailed Description

Color corrections for 8-bit RGB values.

Function Documentation

◆ colorNameToRGB()

RGB8 m5::unit::tcs3472x::colorNameToRGB ( const ColorName name)

Representative color of the color name.

Parameters
nameColor name
Returns
Representative color

◆ colorNameToString()

const char * m5::unit::tcs3472x::colorNameToString ( const ColorName name)

String of the color name.

Parameters
nameColor name
Returns
Color name string (e.g. "Red")

◆ grayscale()

RGB8 m5::unit::tcs3472x::grayscale ( const uint8_t r,
const uint8_t g,
const uint8_t b )

Grayscale.

Luma by the ITU-R BT.709 weights (0.2126 R + 0.7152 G + 0.0722 B)

Parameters
rRed (0-255)
gGreen (0-255)
bBlue (0-255)
Returns
Gray color (r = g = b = luma)

◆ nearestColorName()

ColorName m5::unit::tcs3472x::nearestColorName ( const uint8_t r,
const uint8_t g,
const uint8_t b )

Nearest color name.

Classifies the color by HSV: dark colors are Black, low saturation colors are White or Gray, and the others are named by hue (dark orange is Brown). The thresholds are rough guides for a typical indoor environment

Parameters
rRed (0-255)
gGreen (0-255)
bBlue (0-255)
Returns
Color name

◆ normalizeBrightness()

RGB8 m5::unit::tcs3472x::normalizeBrightness ( const uint8_t r,
const uint8_t g,
const uint8_t b )

Brightness normalization.

Scales all channels by the same factor so that the largest channel becomes 255. The hue and saturation are kept, so the color looks the same at different distances or illuminance

Parameters
rRed (0-255)
gGreen (0-255)
bBlue (0-255)
Returns
Normalized color. Black (all channels 0) is returned unchanged

◆ pureHue()

RGB8 m5::unit::tcs3472x::pureHue ( const uint8_t r,
const uint8_t g,
const uint8_t b )

Pure hue.

Removes the white component (the smallest channel) and scales the largest remaining channel to 255. The result is the most saturated color of the same hue (a dull blue becomes a vivid blue). Useful to classify colors by hue regardless of brightness and dullness

Parameters
rRed (0-255)
gGreen (0-255)
bBlue (0-255)
Returns
Pure hue color. Gray and white (all channels equal) are returned unchanged