From 3c77a63b4bfa42612207e0ea1a7d280199e331fa Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 23 Jun 2023 11:19:14 -0700 Subject: [PATCH] 8bit dim support on 16bit color elements (#720) --- src/internal/colors/Rgb48Color.h | 24 ++++++++++++++++++++++++ src/internal/colors/Rgbw64Color.h | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/internal/colors/Rgb48Color.h b/src/internal/colors/Rgb48Color.h index 05986db..b7881c8 100644 --- a/src/internal/colors/Rgb48Color.h +++ b/src/internal/colors/Rgb48Color.h @@ -193,6 +193,18 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ Rgb48Color Dim(uint16_t ratio) 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 + // ------------------------------------------------------------------------ + Rgb48Color Dim(uint8_t ratio) const + { + uint16_t expanded = ratio << 8; + return Dim(expanded); + } + // ------------------------------------------------------------------------ // Brighten will return a new color that is blended to white with the given ratio // ratio - (0-65535) where 65535 will return the original color and 0 will return white @@ -201,6 +213,18 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ Rgb48Color Brighten(uint16_t ratio) const; + // ------------------------------------------------------------------------ + // Brighten will return a new color that is blended to white with the given ratio + // ratio - (0-255) where 255 will return the original color and 0 will return white + // + // NOTE: This is a simple linear blend + // ------------------------------------------------------------------------ + Rgb48Color Brighten(uint8_t ratio) const + { + uint16_t expanded = ratio << 8; + return Brighten(expanded); + } + // ------------------------------------------------------------------------ // Darken will adjust the color by the given delta toward black // NOTE: This is a simple linear change diff --git a/src/internal/colors/Rgbw64Color.h b/src/internal/colors/Rgbw64Color.h index 38509ff..9729740 100644 --- a/src/internal/colors/Rgbw64Color.h +++ b/src/internal/colors/Rgbw64Color.h @@ -224,6 +224,18 @@ struct Rgbw64Color : RgbColorBase // ------------------------------------------------------------------------ Rgbw64Color Dim(uint16_t ratio) 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 + // ------------------------------------------------------------------------ + Rgbw64Color Dim(uint8_t ratio) const + { + uint16_t expanded = ratio << 8; + return Dim(expanded); + } + // ------------------------------------------------------------------------ // Brighten will return a new color that is blended to white with the given ratio // ratio - (0-65535) where 65535 will return the original color and 0 will return white @@ -232,6 +244,18 @@ struct Rgbw64Color : RgbColorBase // ------------------------------------------------------------------------ Rgbw64Color Brighten(uint16_t ratio) const; + // ------------------------------------------------------------------------ + // Brighten will return a new color that is blended to white with the given ratio + // ratio - (0-255) where 255 will return the original color and 0 will return white + // + // NOTE: This is a simple linear blend + // ------------------------------------------------------------------------ + Rgbw64Color Brighten(uint8_t ratio) const + { + uint16_t expanded = ratio << 8; + return Brighten(expanded); + } + // ------------------------------------------------------------------------ // Darken will adjust the color by the given delta toward black // NOTE: This is a simple linear change