Class: Color
The Color class provides methods for handling RGBW colors, scaling brightness, and converting between color formats.
The header file for this class is located in OS/Framework/Color/Color.h and the implementation is in OS/Framework/Color/Color.cpp.
Constructorsβ
Default Constructorβ
Color();
Default constructor. Initializes the color to black (R = 0, G = 0, B = 0, W = 0).
From 32-bit WRGBβ
Color(uint32_t WRGB);
Constructs a color using a 32-bit WRGB value.
Parameters:
WRGB(uint32_t): A 32-bit value containing W, R, G, and B components.
From R, G, B, Wβ
Color(uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nW = 0);
Constructs a color using individual RGBW values. W defaults to 0 if not specified.
Parameters:
nR(uint8_t): Red component.nG(uint8_t): Green component.nB(uint8_t): Blue component.nW(uint8_t, optional): White component. Defaults to0.
Member Functionsβ
Updateβ
virtual void Update();
A virtual method for updating the color. Can be overridden in derived classes.
RGBβ
uint32_t RGB(uint8_t brightness = 255);
Returns the RGB value as a 32-bit integer, scaled by brightness.
Parameters:
brightness(uint8_t, optional): Brightness scale (0-255). Defaults to255.
Returns:
uint32_t: The scaled RGB value.
GRBβ
uint32_t GRB(uint8_t brightness = 255);
Returns the GRB value as a 32-bit integer, scaled by brightness.
Parameters:
brightness(uint8_t, optional): Brightness scale (0-255). Defaults to255.
Returns:
uint32_t: The scaled GRB value.
Scaleβ
Color Scale(uint8_t scale);
Scales the color by the specified factor.
Parameters:
scale(uint8_t): The scale factor (0-255).
Returns:
Color: The scaled color.
Dimβ
Color Dim(uint8_t scale = COLOR_LOW_STATE_SCALE);
Dims the color by the specified factor.
Parameters:
scale(uint8_t, optional): The dimming factor. Defaults toCOLOR_LOW_STATE_SCALE.
Returns:
Color: The dimmed color.
DimIfNotβ
Color DimIfNot(bool not_dim = false, uint8_t scale = COLOR_LOW_STATE_SCALE);
Dims the color conditionally. This is useful to pass in a boolean to determine if the color should be dimmed. Like UI elements that are disabled.
Parameters:
not_dim(bool, optional): Iftrue, the color will not be dimmed. Defaults tofalse.scale(uint8_t, optional): The dimming factor. Defaults toCOLOR_LOW_STATE_SCALE.
Returns:
Color: The resulting color.
Gammaβ
Color Gamma();
Applies gamma correction to the color.
Returns:
Color: The gamma-corrected color.
Color::scale8β
static uint8_t scale8(uint8_t i, uint8_t scale);
Scales a value using an 8-bit factor.
Parameters:
i(uint8_t): The value to scale.scale(uint8_t): The scale factor.
Returns:
uint8_t: The scaled value.
Color::scale8_videoβ
static uint8_t scale8_video(uint8_t i, uint8_t scale);
Scales a value using an 8-bit factor, ensuring the result is never zero unless the input is zero.
Parameters:
i(uint8_t): The value to scale.scale(uint8_t): The scale factor.
Returns:
uint8_t: The scaled value.
Color::HsvToRgbβ
static Color HsvToRgb(float h, float s, float v);
Converts an HSV value to an RGB color.
Parameters:
h(float): Hue (0-360).s(float): Saturation (0-1).v(float): Value (0-1).
Returns:
Color: The RGB color.
Color::RgbToHsvβ
static void RgbToHsv(Color rgb, float* h, float* s, float* v);
Converts an RGB color to HSV.
Parameters:
rgb(Color): The RGB color.h(float*): Pointer to store the hue.s(float*): Pointer to store the saturation.v(float*): Pointer to store the value.
Color::Crossfadeβ
static Color Crossfade(Color color1, Color color2, Fract16 ratio);
Crossfades between two colors.
Parameters:
color1(Color): The starting color.color2(Color): The ending color.ratio(Fract16): The crossfade ratio (0-65535).
Returns:
Color: The resulting color.
Operatorsβ
Conversion to boolβ
operator bool();
Checks if the color is non-zero.
Returns:
bool:trueif any component (R, G, B, or W) is non-zero, otherwisefalse.
Comments