This commit is contained in:
Michael Miller
2019-12-04 13:09:26 -08:00
committed by GitHub
parent d71ad7a1fa
commit 2f63405c5c
5 changed files with 29 additions and 0 deletions

View File

@@ -349,6 +349,7 @@ SetPixelColor KEYWORD2
GetPixelColor KEYWORD2 GetPixelColor KEYWORD2
SwapPixelColor KEYWORD2 SwapPixelColor KEYWORD2
CalculateBrightness KEYWORD2 CalculateBrightness KEYWORD2
Dim KEYWORD2
Darken KEYWORD2 Darken KEYWORD2
Lighten KEYWORD2 Lighten KEYWORD2
LinearBlend KEYWORD2 LinearBlend KEYWORD2

View File

@@ -163,6 +163,12 @@ uint8_t RgbColor::CalculateBrightness() const
return (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3); return (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
} }
RgbColor RgbColor::Dim(uint8_t ratio) const
{
// specifically avoids float math
return RgbColor(R * ratio / 255, G * ratio / 255, B * ratio / 255);
}
void RgbColor::Darken(uint8_t delta) void RgbColor::Darken(uint8_t delta)
{ {
if (R > delta) if (R > delta)

View File

@@ -98,6 +98,14 @@ struct RgbColor
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
uint8_t CalculateBrightness() const; uint8_t CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
// ratio - (0-255) where 255 will return the original color and 0 will return black
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbColor Dim(uint8_t ratio) const;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black // Darken will adjust the color by the given delta toward black
// NOTE: This is a simple linear change // NOTE: This is a simple linear change

View File

@@ -67,6 +67,12 @@ uint8_t RgbwColor::CalculateBrightness() const
} }
} }
RgbwColor RgbwColor::Dim(uint8_t ratio) const
{
// specifically avoids float math
return RgbwColor(R * ratio / 255, G * ratio / 255, B * ratio / 255, W * ratio / 255);
}
void RgbwColor::Darken(uint8_t delta) void RgbwColor::Darken(uint8_t delta)
{ {
if (R > delta) if (R > delta)

View File

@@ -126,6 +126,14 @@ struct RgbwColor
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
uint8_t CalculateBrightness() const; uint8_t CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
// ratio - (0-255) where 255 will return the original color and 0 will return black
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbwColor Dim(uint8_t ratio) const;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black // Darken will adjust the color by the given delta toward black
// NOTE: This is a simple linear change // NOTE: This is a simple linear change