forked from Makuna/NeoPixelBus
Dim (#312)
This commit is contained in:
@@ -349,6 +349,7 @@ SetPixelColor KEYWORD2
|
||||
GetPixelColor KEYWORD2
|
||||
SwapPixelColor KEYWORD2
|
||||
CalculateBrightness KEYWORD2
|
||||
Dim KEYWORD2
|
||||
Darken KEYWORD2
|
||||
Lighten KEYWORD2
|
||||
LinearBlend KEYWORD2
|
||||
|
@@ -163,6 +163,12 @@ uint8_t RgbColor::CalculateBrightness() const
|
||||
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)
|
||||
{
|
||||
if (R > delta)
|
||||
|
@@ -98,6 +98,14 @@ struct RgbColor
|
||||
// ------------------------------------------------------------------------
|
||||
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
|
||||
// NOTE: This is a simple linear change
|
||||
|
@@ -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)
|
||||
{
|
||||
if (R > delta)
|
||||
|
@@ -126,6 +126,14 @@ struct RgbwColor
|
||||
// ------------------------------------------------------------------------
|
||||
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
|
||||
// NOTE: This is a simple linear change
|
||||
|
Reference in New Issue
Block a user