-
-
Notifications
You must be signed in to change notification settings - Fork 264
Rgb16Color object API
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.
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..
The highest value for a single color element.
const static uint16_t Max = 255;
The number of color elements. Useful when accessing the elements using the [] operators.
const static size_t Count = 3;
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)
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
Constructs a Rgb16Color using a single color value encoded in 565 model.
- color - color encoded in 565 model
Construct a Rgb16Color using RgbColor, encoding the 8 bit elements into the single 565 16 bit value
- color - an RgbColor object
Construct a Rgb16Color using HtmlColor, converting the Html single value to Rgb component values
- color - an HtmlColor object
Construct a Rgb16Color using HslColor, converting the Hsl to Rgb
- color - an HslColor object
Construct a Rgb16Color using HsbColor, converting the Hsb to Rgb
- color - an HsbColor object
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.
Set the red value, encoding it into the single 16 bit value.
- r - (0-255)
get the red value, decoding it from the single 16 bit value
Set the green value, encoding it into the single 16 bit value.
- g - (0-255)
get the green value, decoding it from the single 16 bit value
Set the blue value, encoding it into the single 16 bit value.
- b - (0-255)
get the blue value, decoding it from the single 16 bit value
CalculateBrightness will calculate the overall brightness.
NOTE: This is a simple linear brightness
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.
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.
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.
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.
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);
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
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];