diff options
Diffstat (limited to 'quantum/color.c')
-rw-r--r-- | quantum/color.c | 121 |
1 files changed, 57 insertions, 64 deletions
diff --git a/quantum/color.c b/quantum/color.c index a309da379a..1f398e2403 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -14,81 +14,74 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - #include "color.h" #include "led_tables.h" #include "progmem.h" -RGB hsv_to_rgb( HSV hsv ) -{ - RGB rgb; - uint8_t region, remainder, p, q, t; - uint16_t h, s, v; +RGB hsv_to_rgb(HSV hsv) { + RGB rgb; + uint8_t region, remainder, p, q, t; + uint16_t h, s, v; - if ( hsv.s == 0 ) - { + if (hsv.s == 0) { #ifdef USE_CIE1931_CURVE - rgb.r = rgb.g = rgb.b = pgm_read_byte( &CIE1931_CURVE[hsv.v] ); + rgb.r = rgb.g = rgb.b = pgm_read_byte(&CIE1931_CURVE[hsv.v]); #else - rgb.r = hsv.v; - rgb.g = hsv.v; - rgb.b = hsv.v; + rgb.r = hsv.v; + rgb.g = hsv.v; + rgb.b = hsv.v; #endif - return rgb; - } - - h = hsv.h; - s = hsv.s; - v = hsv.v; + return rgb; + } - region = h * 6 / 255; - remainder = (h * 2 - region * 85) * 3; + h = hsv.h; + s = hsv.s; +#ifdef USE_CIE1931_CURVE + v = pgm_read_byte(&CIE1931_CURVE[hsv.v]); +#else + v = hsv.v; +#endif - p = (v * (255 - s)) >> 8; - q = (v * (255 - ((s * remainder) >> 8))) >> 8; - t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8; + region = h * 6 / 255; + remainder = (h * 2 - region * 85) * 3; - switch ( region ) - { - case 6: - case 0: - rgb.r = v; - rgb.g = t; - rgb.b = p; - break; - case 1: - rgb.r = q; - rgb.g = v; - rgb.b = p; - break; - case 2: - rgb.r = p; - rgb.g = v; - rgb.b = t; - break; - case 3: - rgb.r = p; - rgb.g = q; - rgb.b = v; - break; - case 4: - rgb.r = t; - rgb.g = p; - rgb.b = v; - break; - default: - rgb.r = v; - rgb.g = p; - rgb.b = q; - break; - } + p = (v * (255 - s)) >> 8; + q = (v * (255 - ((s * remainder) >> 8))) >> 8; + t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8; -#ifdef USE_CIE1931_CURVE - rgb.r = pgm_read_byte( &CIE1931_CURVE[rgb.r] ); - rgb.g = pgm_read_byte( &CIE1931_CURVE[rgb.g] ); - rgb.b = pgm_read_byte( &CIE1931_CURVE[rgb.b] ); -#endif + switch (region) { + case 6: + case 0: + rgb.r = v; + rgb.g = t; + rgb.b = p; + break; + case 1: + rgb.r = q; + rgb.g = v; + rgb.b = p; + break; + case 2: + rgb.r = p; + rgb.g = v; + rgb.b = t; + break; + case 3: + rgb.r = p; + rgb.g = q; + rgb.b = v; + break; + case 4: + rgb.r = t; + rgb.g = p; + rgb.b = v; + break; + default: + rgb.r = v; + rgb.g = p; + rgb.b = q; + break; + } - return rgb; + return rgb; } - |