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

Color corrections for 8-bit RGB values (pure hue, brightness normalization, grayscale, color names) More...

#include "../unit/unit_TCS3472x_data.hpp"
#include <cstdint>

Go to the source code of this file.

Classes

struct  m5::unit::tcs3472x::RGB8
 8-bit RGB value More...
 

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Enumerations

enum class  m5::unit::tcs3472x::ColorName : uint8_t {
  Black , White , Gray , Red ,
  Orange , Yellow , Green , Cyan ,
  Blue , Purple , Magenta , Brown
}
 Color names for nearestColorName. More...
 

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 (pure hue, brightness normalization, grayscale, color names)

Each function takes an 8-bit RGB value, such as Data::R8() or Calibration::R8(), and returns the corrected color. Pass calibrated values (Calibration) for the best results, so that white and gray have equal channels.

Enumeration Type Documentation

◆ ColorName

enum class m5::unit::tcs3472x::ColorName : uint8_t
strong

Color names for nearestColorName.

Enumerator
Black 

Black.

White 

White.

Gray 

Gray.

Red 

Red.

Orange 

Orange.

Yellow 

Yellow.

Green 

Green.

Cyan 

Cyan.

Blue 

Blue.

Purple 

Purple.

Magenta 

Magenta.

Brown 

Brown.

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