Skip to content

Commit

Permalink
8bit dim support on 16bit color elements (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Makuna authored Jun 23, 2023
1 parent 66a6ae4 commit 3c77a63
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/internal/colors/Rgb48Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/internal/colors/Rgbw64Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3c77a63

Please sign in to comment.