diff options
Diffstat (limited to 'quantum/color.c')
-rw-r--r-- | quantum/color.c | 117 |
1 files changed, 56 insertions, 61 deletions
diff --git a/quantum/color.c b/quantum/color.c index a309da379a..847129736d 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -14,81 +14,76 @@ * 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; - } + return rgb; + } - h = hsv.h; - s = hsv.s; - v = hsv.v; + h = hsv.h; + s = hsv.s; + v = hsv.v; - region = h * 6 / 255; - remainder = (h * 2 - region * 85) * 3; + region = h * 6 / 255; + remainder = (h * 2 - region * 85) * 3; - p = (v * (255 - s)) >> 8; - q = (v * (255 - ((s * remainder) >> 8))) >> 8; - t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8; + p = (v * (255 - s)) >> 8; + q = (v * (255 - ((s * remainder) >> 8))) >> 8; + t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8; - 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; - } + 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; + } #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] ); + 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 - return rgb; + return rgb; } - |