From ae52bea87277f208bd74a3c5682b321ae186c40c Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:56:27 +0200 Subject: [PATCH 1/3] Update Misc.cpp --- src/src/Helpers/Misc.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/src/Helpers/Misc.cpp b/src/src/Helpers/Misc.cpp index 966de49e38..1b581289da 100644 --- a/src/src/Helpers/Misc.cpp +++ b/src/src/Helpers/Misc.cpp @@ -410,8 +410,8 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { I = I > 0 ? (I < 1 ? I : 1) : 0; #define RGB_ORDER 0 - #define GBR_ORDER 1 - #define BRG_ORDER 2 + #define BRG_ORDER 1 + #define GBR_ORDER 2 int order = RGB_ORDER; @@ -423,10 +423,10 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { order = RGB_ORDER; } else if (H < ANGLE_240_DEG) { H = H - ANGLE_120_DEG; - order = GBR_ORDER; + order = BRG_ORDER; } else { H = H - ANGLE_240_DEG; - order = BRG_ORDER; + order = GBR_ORDER; } const float cos_h = cosf(H); const float cos_1047_h = cosf(ANGLE_60_DEG - H); @@ -440,14 +440,14 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { rgbw[0] = r; rgbw[1] = g; rgbw[2] = b; - } else if (GBR_ORDER == order) { - rgbw[0] = g; - rgbw[1] = b; - rgbw[2] = r; } else if (BRG_ORDER == order) { rgbw[0] = b; rgbw[1] = r; rgbw[2] = g; + } else if (GBR_ORDER == order) { + rgbw[0] = g; + rgbw[1] = b; + rgbw[2] = r; } } From 148c7030f596ce55250d8737ad44a1d396b292a6 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:51:20 +0200 Subject: [PATCH 2/3] Update Misc.cpp --- src/src/Helpers/Misc.cpp | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/src/Helpers/Misc.cpp b/src/src/Helpers/Misc.cpp index 1b581289da..8dc19bb765 100644 --- a/src/src/Helpers/Misc.cpp +++ b/src/src/Helpers/Misc.cpp @@ -409,25 +409,21 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { I = I / 100; I = I > 0 ? (I < 1 ? I : 1) : 0; - #define RGB_ORDER 0 - #define BRG_ORDER 1 - #define GBR_ORDER 2 - - int order = RGB_ORDER; - constexpr float ANGLE_120_DEG = 120.0f * deg2rad; constexpr float ANGLE_240_DEG = 240.0f * deg2rad; constexpr float ANGLE_60_DEG = 60.0f * deg2rad; + int order; if (H < ANGLE_120_DEG) { - order = RGB_ORDER; + order = 0; // RGB_ORDER } else if (H < ANGLE_240_DEG) { - H = H - ANGLE_120_DEG; - order = BRG_ORDER; + H -= ANGLE_120_DEG; + order = 1; // BRG_ORDER } else { - H = H - ANGLE_240_DEG; - order = GBR_ORDER; + H -= ANGLE_240_DEG; + order = 2; // GBR_ORDER } + const float cos_h = cosf(H); const float cos_1047_h = cosf(ANGLE_60_DEG - H); @@ -436,18 +432,22 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { const int b = 0; rgbw[3] = 255 * (1 - S) * I; - if (RGB_ORDER == order) { - rgbw[0] = r; - rgbw[1] = g; - rgbw[2] = b; - } else if (BRG_ORDER == order) { - rgbw[0] = b; - rgbw[1] = r; - rgbw[2] = g; - } else if (GBR_ORDER == order) { - rgbw[0] = g; - rgbw[1] = b; - rgbw[2] = r; + switch (order) { + case 0: // RGB_ORDER + rgbw[0] = r; + rgbw[1] = g; + rgbw[2] = b; + break; + case 1: // BRG_ORDER + rgbw[0] = b; + rgbw[1] = r; + rgbw[2] = g; + break; + case 2: // GBR_ORDER + rgbw[0] = g; + rgbw[1] = b; + rgbw[2] = r; + break; } } From 9de293ba624fc7b1aefa67a239afe12388c1c982 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:03:19 +0200 Subject: [PATCH 3/3] Update Misc.cpp reverting back to the state of the first commit --- src/src/Helpers/Misc.cpp | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/src/Helpers/Misc.cpp b/src/src/Helpers/Misc.cpp index 8dc19bb765..1b581289da 100644 --- a/src/src/Helpers/Misc.cpp +++ b/src/src/Helpers/Misc.cpp @@ -409,21 +409,25 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { I = I / 100; I = I > 0 ? (I < 1 ? I : 1) : 0; + #define RGB_ORDER 0 + #define BRG_ORDER 1 + #define GBR_ORDER 2 + + int order = RGB_ORDER; + constexpr float ANGLE_120_DEG = 120.0f * deg2rad; constexpr float ANGLE_240_DEG = 240.0f * deg2rad; constexpr float ANGLE_60_DEG = 60.0f * deg2rad; - int order; if (H < ANGLE_120_DEG) { - order = 0; // RGB_ORDER + order = RGB_ORDER; } else if (H < ANGLE_240_DEG) { - H -= ANGLE_120_DEG; - order = 1; // BRG_ORDER + H = H - ANGLE_120_DEG; + order = BRG_ORDER; } else { - H -= ANGLE_240_DEG; - order = 2; // GBR_ORDER + H = H - ANGLE_240_DEG; + order = GBR_ORDER; } - const float cos_h = cosf(H); const float cos_1047_h = cosf(ANGLE_60_DEG - H); @@ -432,22 +436,18 @@ void HSV2RGBW(float H, float S, float I, int rgbw[4]) { const int b = 0; rgbw[3] = 255 * (1 - S) * I; - switch (order) { - case 0: // RGB_ORDER - rgbw[0] = r; - rgbw[1] = g; - rgbw[2] = b; - break; - case 1: // BRG_ORDER - rgbw[0] = b; - rgbw[1] = r; - rgbw[2] = g; - break; - case 2: // GBR_ORDER - rgbw[0] = g; - rgbw[1] = b; - rgbw[2] = r; - break; + if (RGB_ORDER == order) { + rgbw[0] = r; + rgbw[1] = g; + rgbw[2] = b; + } else if (BRG_ORDER == order) { + rgbw[0] = b; + rgbw[1] = r; + rgbw[2] = g; + } else if (GBR_ORDER == order) { + rgbw[0] = g; + rgbw[1] = b; + rgbw[2] = r; } }