Skip to content

Rgb48Color object API

Michael Miller edited this page Jul 5, 2023 · 11 revisions

Rgb48Color represents a color object that is represented by Red, Green, Blue component values. Its primary use is to contain and manipulate colors for 3 element Pixels with 16bit resolution.

Properties

There are three properties that represent the component values Red, Green, and Blue. The values range from 0 to 65535. Black would 0,0,0 and white would be 65535,65535,65535.

uint16_t R;
uint16_t G;
uint16_t B;

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 = 65535;

Count

The number of color elements. Useful when accessing the elements using the [] operators.

    const static size_t Count = 3;

Constructors

Rgb48Color(uint16_t r, uint16_t g, uint16_t b) :

Constructs a Rgb48Color using Red, Green, and Blue color component values.

  • r - value of Red component (0 - 65535)
  • g - value of Green component (0 - 65535)
  • b - value of Blue component (0 - 65535)

Rgb48Color(uint16_t brightness)

Constructs a Rgb48Color using a single brightness value(0 - 65535). This works well for creating gray tone colors.

  • brightness - brightness value where (0) = black, (32767) = gray, (65535) = white

explicit Rgb48Color(RgbwColor color);

Construct a Rgb48Color using RgbwColor, converting the R,G,B values and ignoring the W value. Due to the loss of information of the W value, this constructor is marked explicit so it will not automatically be used for conversion.

  • color - a RgbwColor object.

explicit Rgb48Color(Rgbw64Color color);

Construct a Rgb48Color using Rgbw64Color, copying the R,G,B values and ignoring the W value. Due to the loss of information of the W value, this constructor is marked explicit so it will not automatically be used for conversion.

  • color - a Rgbw64Color object.

Rgb48Color(RgbColor color);

Construct a Rgb48Color using RgbColor, converting the R,G,B values.

  • color - a RgbColor object.

Rgb48Color(HtmlColor color);

Construct a Rgb48Color using HtmlColor, converting the Html single value to Rgb component values

  • color - an HtmlColor object

Rgb48Color(HslColor color);

Construct a Rgb48Color using HslColor, converting the Hsl to Rgb

  • color - an HslColor object

Rgb48Color(HsbColor color);

Construct a Rgb48Color using HsbColor, converting the Hsb to Rgb

  • color - an HsbColor object

Rgb48Color()

Construct a Rgb48Color that will have its values set in latter operations.
CAUTION: The R,G,B members are not initialized and may not be consistent until set.

Methods

uint16_t CalculateBrightness();

CalculateBrightness will calculate the overall brightness.
NOTE: This is a simple linear brightness

Rgb48Color Dim(uint16_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-65535) where 65535 will return the original color and 0 will return black.

Rgb48Color Brighten(uint16_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-65535) where 65535 will return the original color and 0 will return white.

Rgb48Color 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.

Rgb48Color 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(uint16_t delta);

Darken will adjust the color by the given delta toward black.
NOTE: This is a simple linear change.

  • delta - (0-65535) the amount to dim the color by.

void Lighten(uint16_t delta);

Lighten will adjust the color by the given delta toward white.
NOTE: This is a simple linear change.

  • delta - (0-65535) the amount to lighten the color by.

int32_t CompareTo(const Rgb48Color& other, uint16_t epsilon = 1)

Compares against another color with the given epsilon.
Returns the greatest difference of a set of elements, where 0 means the colors are equal within epsilon delta, negative means this is less than the other, positive means this is greater than the other.

  • other - the color to compare against.
  • epsilon - the max delta acceptable for them to be considered the same color.

static int32_t Compare(const Rgb48Color& left, const Rgb48Color& right, uint16_t epsilon = 1)

Compares two colors with the given epsilon.
Returns the greatest difference of a set of elements, where 0 means the colors are equal within epsilon delta, negative means left is less than the right, positive means left is greater than the right.

  • left - the first color to compare.
  • right - the other color to compare.
  • epsilon - the max delta acceptable for them to be considered the same color.

static Rgb48Color LinearBlend(Rgb48Color left, Rgb48Color 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...
    Rgb48Color results = Rgb48Color::LinearBlend(Rgb48Color(65535,0,0), Rgb48Color(0,65535,0), 0.33f);

static Rgb48Color LinearBlend(Rgb48Color left, Rgb48Color 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...
    Rgb48Color results = Rgb48Color::LinearBlend(Rgb48Color(65535,0,0), Rgb48Color(0,65535,0), 85);

static Rgb48Color BilinearBlend(Rgb48Color c00, Rgb48Color c01, Rgb48Color c10, Rgb48Color 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

uint16_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];
Clone this wiki locally