From a4173d56a3044a75bd3f717e2785d909578ba79b Mon Sep 17 00:00:00 2001 From: Makuna Date: Sat, 18 Oct 2014 09:50:23 -0700 Subject: [PATCH] Fixed Color Merge Bug Fixed incorrect color merge calculation Added comments to color object methods. --- RgbColor.cpp | 6 +++--- RgbColor.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/RgbColor.cpp b/RgbColor.cpp index e1a1494..ecaa768 100644 --- a/RgbColor.cpp +++ b/RgbColor.cpp @@ -83,7 +83,7 @@ void RgbColor::Lighten(uint8_t delta) RgbColor RgbColor::LinearBlend(RgbColor left, RgbColor right, uint8_t progress) { - return RgbColor( left.R + ((right.R - left.R) * progress >> 8), - left.G + ((right.G - left.G) * progress >> 8), - left.B + ((right.B - left.B) * progress >> 8)); + return RgbColor( left.R + ((right.R - left.R) * progress / 255), + left.G + ((right.G - left.G) * progress / 255), + left.B + ((right.B - left.B) * progress / 255)); } \ No newline at end of file diff --git a/RgbColor.h b/RgbColor.h index f744ad5..48aa81c 100644 --- a/RgbColor.h +++ b/RgbColor.h @@ -24,29 +24,72 @@ License along with NeoPixel. If not, see #include #endif +// ------------------------------------------------------------------------ +// RgbColor represents a color object that is represented by Red, Green, Blue +// component values. It contains helpful color routines to manipulate the +// color. +// ------------------------------------------------------------------------ struct RgbColor { + // ------------------------------------------------------------------------ + // Construct a RgbColor using R, G, B values (0-255) + // ------------------------------------------------------------------------ RgbColor(uint8_t r, uint8_t g, uint8_t b) : R(r), G(g), B(b) { }; + // ------------------------------------------------------------------------ + // Construct a RgbColor using a single brightness value (0-255) + // This works well for creating gray tone colors + // (0) = blakc, (255) = white, (128) = gray + // ------------------------------------------------------------------------ RgbColor(uint8_t brightness) : R(brightness), G(brightness), B(brightness) { }; + // ------------------------------------------------------------------------ + // Construct a RgbColor that will have its values set in latter operations + // CAUTION: The R,G,B members are not initialized and may not be consistent + // ------------------------------------------------------------------------ RgbColor() { }; + // ------------------------------------------------------------------------ + // CalculateBrightness will calculate the overall brightness + // NOTE: This is a simple linear brightness + // ------------------------------------------------------------------------ uint8_t CalculateBrightness(); + // ------------------------------------------------------------------------ + // Darken will adjust the color by the given delta toward black + // NOTE: This is a simple linear change + // delta - (0-255) the amount to dim the color + // ------------------------------------------------------------------------ void Darken(uint8_t delta); + + // ------------------------------------------------------------------------ + // Lighten will adjust the color by the given delta toward white + // NOTE: This is a simple linear change + // delta - (0-255) the amount to lighten the color + // ------------------------------------------------------------------------ void Lighten(uint8_t delta); + // ------------------------------------------------------------------------ + // LinearBlend between two colors by the amount defined by 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 + // ------------------------------------------------------------------------ static RgbColor LinearBlend(RgbColor left, RgbColor right, uint8_t progress); - + + // ------------------------------------------------------------------------ + // Red, Green, Blue color members (0-255) where + // (0,0,0) is black and (255,255,255) is white + // ------------------------------------------------------------------------ uint8_t R; uint8_t G; uint8_t B;