1 /* Copyright 2017 Jason Williams
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "led_tables.h"
21 RGB
hsv_to_rgb(HSV hsv
) {
23 uint8_t region
, remainder
, p
, q
, t
;
27 #ifdef USE_CIE1931_CURVE
28 rgb
.r
= rgb
.g
= rgb
.b
= pgm_read_byte(&CIE1931_CURVE
[hsv
.v
]);
39 #ifdef USE_CIE1931_CURVE
40 v
= pgm_read_byte(&CIE1931_CURVE
[hsv
.v
]);
46 remainder
= (h
* 2 - region
* 85) * 3;
48 p
= (v
* (255 - s
)) >> 8;
49 q
= (v
* (255 - ((s
* remainder
) >> 8))) >> 8;
50 t
= (v
* (255 - ((s
* (255 - remainder
)) >> 8))) >> 8;
91 # define MIN(a, b) ((a) < (b) ? (a) : (b))
93 void convert_rgb_to_rgbw(LED_TYPE
*led
) {
94 // Determine lowest value in all three colors, put that into
95 // the white channel and then shift all colors by that amount
96 led
->w
= MIN(led
->r
, MIN(led
->g
, led
->b
));