Rgb16Color object API - Makuna/NeoPixelBus GitHub Wiki
Rgb16Color represents a color object that is represented by Red, Green, Blue component values using a 565 bit encoding with a total of 16 bits used.
Properties
There is a property that represent the component values Red, Green, and Blue in a 565 bit encoded value. It is best to use the property accessors to get and set the R, G, and B parts of this value.
uint16_t Color565
There are also a few constant properties that are helpful to use. These are..
Max
The highest value for a single color element.
const static uint16_t Max = 255;
Count
The number of color elements. Useful when accessing the elements using the [] operators.
const static size_t Count = 3;
Constructors
Rgb16Color(uint8_t r, uint8_t g, uint8_t b) :
Constructs a Rgb16Color using Red, Green, and Blue color component values.
- r - value of Red component (0 - 255)
- g - value of Green component (0 - 255)
- b - value of Blue component (0 - 255)
Rgb16Color(uint8_t brightness)
Constructs a Rgb16Color using a single brightness value(0 - 255). This works well for creating gray tone colors.
- brightness - brightness value where (0) = black, (128) = gray, (255) = white
Rgb16Color(uint16_t color)
Constructs a Rgb16Color using a single color value encoded in 565 model.
- color - color encoded in 565 model
Rgb16Color(RgbColor color);
Construct a Rgb16Color using RgbColor, encoding the 8 bit elements into the single 565 16 bit value
- color - an RgbColor object
Rgb16Color(HtmlColor color);
Construct a Rgb16Color using HtmlColor, converting the Html single value to Rgb component values
- color - an HtmlColor object
Rgb16Color(HslColor color);
Construct a Rgb16Color using HslColor, converting the Hsl to Rgb
- color - an HslColor object
Rgb16Color(HsbColor color);
Construct a Rgb16Color using HsbColor, converting the Hsb to Rgb
- color - an HsbColor object
Rgb16Color()
Construct a Rgb16Color that will have its values set in latter operations.
CAUTION: The Color565 member is not initialized and may not be consistent until set.
Property Accessors
void setR(uint8_t r)
Set the red value, encoding it into the single 16 bit value.
- r - (0-255)
uint8_t getR()
get the red value, decoding it from the single 16 bit value
void setG(uint8_t g)
Set the green value, encoding it into the single 16 bit value.
- g - (0-255)
uint8_t getG()
get the green value, decoding it from the single 16 bit value
void setB(uint8_t b)
Set the blue value, encoding it into the single 16 bit value.
- b - (0-255)
uint8_t getB()
get the blue value, decoding it from the single 16 bit value
Methods
uint8_t CalculateBrightness();
CalculateBrightness will calculate the overall brightness.
NOTE: This is a simple linear brightness
Rgb16Color Dim(uint8_t ratio);
Dim will return a new color that is blended to black with the given ratio.
NOTE: This is a simple linear change.
- ratio - (0-255) where 255 will return the original color and 0 will return black.
Rgb16Color Brighten(uint8_t ratio);
Brighten will return a new color that is blended to white with the given ratio.
NOTE: This is a simple linear change.
- ratio - (0-255) where 255 will return the original color and 0 will return white.
void Darken(uint8_t delta);
Darken will adjust the color by the given delta toward black.
NOTE: This is a simple linear change.
- delta - (0-255) the amount to dim the color by.
void Lighten(uint8_t delta);
Lighten will adjust the color by the given delta toward white.
NOTE: This is a simple linear change.
- delta - (0-255) the amount to lighten the color by.
static Rgb16Color LinearBlend(Rgb16Color left, Rgb16Color right, float progress);
This will blend between two colors by the amount defined by the progress variable.
- left - the color to start the blend at.
- right - the color to end the blend at.
- progress - (0.0f - 1.0f) value where 0.0f will return left and 1.0f will return right and a value between will blend the color weighted linearly between them.
This is a static function, which means you need to call it scoped to the object class and not an instance like...
Rgb16Color results = Rgb16Color::LinearBlend(Rgb16Color(255,0,0), Rgb16Color(0,255,0), 0.33f);
static Rgb16Color LinearBlend(Rgb16Color left, Rgb16Color right, uint8_t progress);
This will blend between two colors by the amount defined by the progress variable.
- left - the color to start the blend at.
- right - the color to end the blend at.
- progress - (0 - 255) value where 0 will return left and 255 will return right and a value between will blend the color weighted linearly between them.
This is a static function, which means you need to call it scoped to the object class and not an instance like...
Rgb16Color results = Rgb16Color::LinearBlend(Rgb16Color(255,0,0), Rgb16Color(0,255,0), 85);
static Rgb16Color BilinearBlend(Rgb16Color c00, Rgb16Color c01, Rgb16Color c10, Rgb16Color c11, float x, float y);
This will blend between four colors by the amount defined by 2d weighting values.
- c00 - upper left quadrant color
- c01 - upper right quadrant color
- c10 - lower left quadrant color
- c11 - lower right quadrant color
- x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
- y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
Operators
uint8_t operator[](size_t idx)
The index operator allows accessing the R, G, and B properties using an index. There are both read only and read write versions.
uint16_t green = color[1];
You can also use the color index constants.
uint16_t green = color[ColorIndexG];