Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hsv->rgb conversion without using CIE curve. #9856

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion keyboards/anavi/macropad8/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: ht
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = no # Audio output on port C6
UNICODE_ENABLE = yes # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight.
OLED_DRIVER_ENABLE = yes # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C
Expand Down
26 changes: 23 additions & 3 deletions quantum/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
#include "led_tables.h"
#include "progmem.h"

RGB hsv_to_rgb(HSV hsv) {
RGB hsv_to_rgb_impl(HSV hsv, bool use_cie) {
RGB rgb;
uint8_t region, remainder, p, q, t;
uint16_t h, s, v;

if (hsv.s == 0) {
#ifdef USE_CIE1931_CURVE
rgb.r = rgb.g = rgb.b = pgm_read_byte(&CIE1931_CURVE[hsv.v]);
if (use_cie) {
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;
}
#else
rgb.r = hsv.v;
rgb.g = hsv.v;
Expand All @@ -37,7 +43,11 @@ RGB hsv_to_rgb(HSV hsv) {
h = hsv.h;
s = hsv.s;
#ifdef USE_CIE1931_CURVE
v = pgm_read_byte(&CIE1931_CURVE[hsv.v]);
if (use_cie) {
v = pgm_read_byte(&CIE1931_CURVE[hsv.v]);
} else {
v = hsv.v;
}
#else
v = hsv.v;
#endif
Expand Down Expand Up @@ -86,6 +96,16 @@ RGB hsv_to_rgb(HSV hsv) {
return rgb;
}

RGB hsv_to_rgb(HSV hsv) {
#ifdef USE_CIE1931_CURVE
return hsv_to_rgb_impl(hsv, true);
#else
return hsv_to_rgb_impl(hsv, false);
#endif
}

RGB hsv_to_rgb_nocie(HSV hsv) { return hsv_to_rgb_impl(hsv, false); }

#ifdef RGBW
# ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
Expand Down
1 change: 1 addition & 0 deletions quantum/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct PACKED {
#endif

RGB hsv_to_rgb(HSV hsv);
RGB hsv_to_rgb_nocie(HSV hsv);
#ifdef RGBW
void convert_rgb_to_rgbw(LED_TYPE *led);
#endif
Expand Down