From 7e25b366e1283a86f5963b4e89f5865c04badfe7 Mon Sep 17 00:00:00 2001 From: vanhofen Date: Fri, 19 Nov 2021 21:51:01 +0100 Subject: [PATCH] color: formatting code using astyle Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/6eaac512fb8c80a0bcbe581c011bde906683e59c Author: vanhofen Date: 2021-11-19 (Fri, 19 Nov 2021) Origin message was: ------------------ - color: formatting code using astyle ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/color.cpp | 74 ++++++++++++++----------- src/gui/color.h | 123 ++++++++++++++++++++++------------------- src/gui/color_custom.h | 7 ++- 3 files changed, 114 insertions(+), 90 deletions(-) diff --git a/src/gui/color.cpp b/src/gui/color.cpp index 3524633ce..4b3af1364 100644 --- a/src/gui/color.cpp +++ b/src/gui/color.cpp @@ -1,29 +1,29 @@ /* Neutrino-GUI - DBoxII-Project - + Copyright (C) 2001 Steffen Hehn 'McClean' Homepage: http://dbox.cyberphoria.org/ - + Kommentar: - + Diese GUI wurde von Grund auf neu programmiert und sollte nun vom Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert auf der Client-Server Idee, diese GUI ist also von der direkten DBox- Steuerung getrennt. Diese wird dann von Daemons uebernommen. - - + + License: GPL - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -55,8 +55,10 @@ int convertSetupColor2RGB(const unsigned char r, const unsigned char g, const un int convertSetupAlpha2Alpha(unsigned char alpha) { - if(alpha == 0) return 0xFF; - else if(alpha >= 100) return 0; + if (alpha == 0) + return 0xFF; + else if (alpha >= 100) + return 0; int a = 100 - alpha; int ret = a * 0xFF / 100; return ret; @@ -64,27 +66,27 @@ int convertSetupAlpha2Alpha(unsigned char alpha) void recalcColor(unsigned char &orginal, int fade) { - if(fade==100) + if (fade == 100) { return; } - int color = orginal * fade / 100; - if(color>255) - color=255; - if(color<0) - color=0; + int color = orginal * fade / 100; + if (color > 255) + color = 255; + if (color < 0) + color = 0; orginal = (unsigned char)color; } -void protectColor( unsigned char &r, unsigned char &g, unsigned char &b, bool protect ) +void protectColor(unsigned char &r, unsigned char &g, unsigned char &b, bool protect) { if (!protect) return; - if ((r==0) && (g==0) && (b==0)) + if ((r == 0) && (g == 0) && (b == 0)) { - r=1; - g=1; - b=1; + r = 1; + g = 1; + b = 1; } } @@ -93,7 +95,7 @@ void fadeColor(unsigned char &r, unsigned char &g, unsigned char &b, int fade, b recalcColor(r, fade); recalcColor(g, fade); recalcColor(b, fade); - protectColor(r,g,b, protect); + protectColor(r, g, b, protect); } uint8_t getBrightnessRGB(fb_pixel_t color) @@ -110,8 +112,10 @@ fb_pixel_t changeBrightnessRGBRel(fb_pixel_t color, int br, bool transp) { int br_ = (int)getBrightnessRGB(color); br_ += br; - if (br_ < 0) br_ = 0; - if (br_ > 255) br_ = 255; + if (br_ < 0) + br_ = 0; + if (br_ > 255) + br_ = 255; return changeBrightnessRGB(color, (uint8_t)br_, transp); } @@ -152,17 +156,21 @@ void Hsv2Rgb(HsvColor *hsv, RgbColor *rgb) float f_H = hsv->h; float f_S = hsv->s; float f_V = hsv->v; - if (fabsf(f_S) < FLT_EPSILON) { + if (fabsf(f_S) < FLT_EPSILON) + { rgb->r = (uint8_t)(f_V * 255); rgb->g = (uint8_t)(f_V * 255); rgb->b = (uint8_t)(f_V * 255); - } else { + } + else + { float f_R; float f_G; float f_B; float hh = f_H; - if (hh >= 360) hh = 0; + if (hh >= 360) + hh = 0; hh /= 60; int i = (int)hh; float ff = hh - (float)i; @@ -170,7 +178,8 @@ void Hsv2Rgb(HsvColor *hsv, RgbColor *rgb) float q = f_V * (1 - (f_S * ff)); float t = f_V * (1 - (f_S * (1 - ff))); - switch (i) { + switch (i) + { case 0: f_R = f_V; f_G = t; f_B = p; break; @@ -211,10 +220,13 @@ void Rgb2Hsv(RgbColor *rgb, HsvColor *hsv) float f_H = 0; float f_S = 0; - if (fabsf(delta) < FLT_EPSILON) { //gray + if (fabsf(delta) < FLT_EPSILON) //gray + { f_S = 0; f_H = 0; - } else { + } + else + { f_S = (delta / max); if (f_R >= max) f_H = (f_G - f_B) / delta; @@ -264,7 +276,7 @@ fb_pixel_t getRandomColor(col_range_t range_r, col_range_t range_g, col_range_t { if (!range_r.min || !range_g.min || !range_b.min) { - dprintf(DEBUG_NORMAL, "\033[31m[color.cpp] [Error:]\033[0m %s: color range min value < 1 in argument, allowed values are 1-255 [r: min%u/max%u] [g: min%u/max%u] [b: min%u/max%u]\n",__func__, range_r.min, range_r.max, range_g.min, range_g.max, range_b.min, range_b.max); + dprintf(DEBUG_NORMAL, "\033[31m[color.cpp] [Error:]\033[0m %s: color range min value < 1 in argument, allowed values are 1-255 [r: min%u/max%u] [g: min%u/max%u] [b: min%u/max%u]\n", __func__, range_r.min, range_r.max, range_g.min, range_g.max, range_b.min, range_b.max); return 0; } diff --git a/src/gui/color.h b/src/gui/color.h index 9824b640c..1f5d253b8 100644 --- a/src/gui/color.h +++ b/src/gui/color.h @@ -50,58 +50,61 @@ #define COL_MENUCONTENTSELECTED 254-8*2 #define COL_MENUCONTENTINACTIVE 254-8*1 -#define COL_BACKGROUND 255 +#define COL_BACKGROUND 255 #ifdef FB_USE_PALETTE -#define COL_SHADOW_PLUS_0 (COL_SHADOW + 0) -#define COL_INFOBAR_PLUS_0 (COL_INFOBAR + 0) -#define COL_INFOBAR_PLUS_1 (COL_INFOBAR + 1) -#define COL_INFOBAR_PLUS_3 (COL_INFOBAR + 3) -#define COL_INFOBAR_PLUS_7 (COL_INFOBAR + 7) -#define COL_INFOBAR_CASYSTEM_PLUS_0 (COL_INFOBAR_CASYSTEM + 0) -#define COL_INFOBAR_CASYSTEM_PLUS_2 (COL_INFOBAR_CASYSTEM + 2) -#define COL_MENUHEAD_PLUS_0 (COL_MENUHEAD + 0) -#define COL_MENUCONTENT_PLUS_0 (COL_MENUCONTENT + 0) -#define COL_MENUCONTENT_PLUS_1 (COL_MENUCONTENT + 1) -#define COL_MENUCONTENT_PLUS_2 (COL_MENUCONTENT + 2) -#define COL_MENUCONTENT_PLUS_3 (COL_MENUCONTENT + 3) -#define COL_MENUCONTENT_PLUS_4 (COL_MENUCONTENT + 4) -#define COL_MENUCONTENT_PLUS_5 (COL_MENUCONTENT + 5) -#define COL_MENUCONTENT_PLUS_6 (COL_MENUCONTENT + 6) -#define COL_MENUCONTENT_PLUS_7 (COL_MENUCONTENT + 7) -#define COL_MENUCONTENTDARK_PLUS_0 (COL_MENUCONTENTDARK + 0) -#define COL_MENUCONTENTDARK_PLUS_2 (COL_MENUCONTENTDARK + 2) -#define COL_MENUCONTENTSELECTED_PLUS_0 (COL_MENUCONTENTSELECTED + 0) -#define COL_MENUCONTENTSELECTED_PLUS_2 (COL_MENUCONTENTSELECTED + 2) -#define COL_MENUCONTENTINACTIVE_PLUS_0 (COL_MENUCONTENTINACTIVE + 0) -#define COL_MENUFOOT_PLUS_0 (COL_MENUFOOT + 0) -#define COL_BACKGROUND_PLUS_0 (COL_BACKGROUND + 0) -#define COL_PROGRESSBAR_PASSIVE_PLUS_0 (COL_PROGRESSBAR + 0) + +#define COL_SHADOW_PLUS_0 (COL_SHADOW + 0) +#define COL_INFOBAR_PLUS_0 (COL_INFOBAR + 0) +#define COL_INFOBAR_PLUS_1 (COL_INFOBAR + 1) +#define COL_INFOBAR_PLUS_3 (COL_INFOBAR + 3) +#define COL_INFOBAR_PLUS_7 (COL_INFOBAR + 7) +#define COL_INFOBAR_CASYSTEM_PLUS_0 (COL_INFOBAR_CASYSTEM + 0) +#define COL_INFOBAR_CASYSTEM_PLUS_2 (COL_INFOBAR_CASYSTEM + 2) +#define COL_MENUHEAD_PLUS_0 (COL_MENUHEAD + 0) +#define COL_MENUCONTENT_PLUS_0 (COL_MENUCONTENT + 0) +#define COL_MENUCONTENT_PLUS_1 (COL_MENUCONTENT + 1) +#define COL_MENUCONTENT_PLUS_2 (COL_MENUCONTENT + 2) +#define COL_MENUCONTENT_PLUS_3 (COL_MENUCONTENT + 3) +#define COL_MENUCONTENT_PLUS_4 (COL_MENUCONTENT + 4) +#define COL_MENUCONTENT_PLUS_5 (COL_MENUCONTENT + 5) +#define COL_MENUCONTENT_PLUS_6 (COL_MENUCONTENT + 6) +#define COL_MENUCONTENT_PLUS_7 (COL_MENUCONTENT + 7) +#define COL_MENUCONTENTDARK_PLUS_0 (COL_MENUCONTENTDARK + 0) +#define COL_MENUCONTENTDARK_PLUS_2 (COL_MENUCONTENTDARK + 2) +#define COL_MENUCONTENTSELECTED_PLUS_0 (COL_MENUCONTENTSELECTED + 0) +#define COL_MENUCONTENTSELECTED_PLUS_2 (COL_MENUCONTENTSELECTED + 2) +#define COL_MENUCONTENTINACTIVE_PLUS_0 (COL_MENUCONTENTINACTIVE + 0) +#define COL_MENUFOOT_PLUS_0 (COL_MENUFOOT + 0) +#define COL_BACKGROUND_PLUS_0 (COL_BACKGROUND + 0) +#define COL_PROGRESSBAR_PASSIVE_PLUS_0 (COL_PROGRESSBAR + 0) + #else -#define COL_SHADOW_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_SHADOW + 0)]) -#define COL_INFOBAR_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 0)]) -#define COL_INFOBAR_PLUS_1 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 1)]) -#define COL_INFOBAR_PLUS_3 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 3)]) -#define COL_INFOBAR_PLUS_7 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 7)]) -#define COL_INFOBAR_CASYSTEM_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR_CASYSTEM + 0)]) -#define COL_INFOBAR_CASYSTEM_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR_CASYSTEM + 2)]) -#define COL_MENUHEAD_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUHEAD + 0)]) -#define COL_MENUCONTENT_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 0)]) -#define COL_MENUCONTENT_PLUS_1 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 1)]) -#define COL_MENUCONTENT_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 2)]) -#define COL_MENUCONTENT_PLUS_3 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 3)]) -#define COL_MENUCONTENT_PLUS_4 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 4)]) -#define COL_MENUCONTENT_PLUS_5 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 5)]) -#define COL_MENUCONTENT_PLUS_6 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 6)]) -#define COL_MENUCONTENT_PLUS_7 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 7)]) -#define COL_MENUCONTENTDARK_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTDARK + 0)]) -#define COL_MENUCONTENTDARK_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTDARK + 2)]) -#define COL_MENUCONTENTSELECTED_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTSELECTED + 0)]) -#define COL_MENUCONTENTSELECTED_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTSELECTED + 2)]) -#define COL_MENUCONTENTINACTIVE_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTINACTIVE + 0)]) -#define COL_MENUFOOT_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUFOOT + 0)]) -#define COL_BACKGROUND_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_BACKGROUND + 0)]) -#define COL_PROGRESSBAR_PASSIVE_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_PROGRESSBAR + 0)]) + +#define COL_SHADOW_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_SHADOW + 0)]) +#define COL_INFOBAR_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 0)]) +#define COL_INFOBAR_PLUS_1 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 1)]) +#define COL_INFOBAR_PLUS_3 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 3)]) +#define COL_INFOBAR_PLUS_7 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR + 7)]) +#define COL_INFOBAR_CASYSTEM_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR_CASYSTEM + 0)]) +#define COL_INFOBAR_CASYSTEM_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_INFOBAR_CASYSTEM + 2)]) +#define COL_MENUHEAD_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUHEAD + 0)]) +#define COL_MENUCONTENT_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 0)]) +#define COL_MENUCONTENT_PLUS_1 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 1)]) +#define COL_MENUCONTENT_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 2)]) +#define COL_MENUCONTENT_PLUS_3 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 3)]) +#define COL_MENUCONTENT_PLUS_4 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 4)]) +#define COL_MENUCONTENT_PLUS_5 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 5)]) +#define COL_MENUCONTENT_PLUS_6 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 6)]) +#define COL_MENUCONTENT_PLUS_7 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENT + 7)]) +#define COL_MENUCONTENTDARK_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTDARK + 0)]) +#define COL_MENUCONTENTDARK_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTDARK + 2)]) +#define COL_MENUCONTENTSELECTED_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTSELECTED + 0)]) +#define COL_MENUCONTENTSELECTED_PLUS_2 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTSELECTED + 2)]) +#define COL_MENUCONTENTINACTIVE_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUCONTENTINACTIVE + 0)]) +#define COL_MENUFOOT_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_MENUFOOT + 0)]) +#define COL_BACKGROUND_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_BACKGROUND + 0)]) +#define COL_PROGRESSBAR_PASSIVE_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_PROGRESSBAR + 0)]) // text colors #define COL_COLORED_EVENTS_TEXT (CFrameBuffer::getInstance()->realcolor[(COL_NEUTRINO_TEXT + 0)]) @@ -121,7 +124,8 @@ #define COL_MENUCONTENTINACTIVE_TEXT (CFrameBuffer::getInstance()->realcolor[(COL_NEUTRINO_TEXT + 14)]) #define COL_INFOCLOCK_TEXT (CFrameBuffer::getInstance()->realcolor[(COL_NEUTRINO_TEXT + 15)]) #define COL_PROGRESSBAR_ACTIVE_PLUS_0 (CFrameBuffer::getInstance()->realcolor[(COL_NEUTRINO_TEXT + 16)]) -#endif + +#endif // FB_USE_PALETTE // some wrappers to get more readability #define COL_FRAME COL_MENUCONTENT_PLUS_1 //NI @@ -144,15 +148,17 @@ int convertSetupColor2RGB(unsigned char r, unsigned char g, unsigned char b); int convertSetupAlpha2Alpha(unsigned char alpha); -void fadeColor(unsigned char &r, unsigned char &g, unsigned char &b, int fade, bool protect=true); +void fadeColor(unsigned char &r, unsigned char &g, unsigned char &b, int fade, bool protect = true); -typedef struct { +typedef struct +{ uint8_t r; uint8_t g; uint8_t b; } RgbColor; -typedef struct { +typedef struct +{ float h; float s; float v; @@ -160,10 +166,10 @@ typedef struct { uint8_t getBrightnessRGB(fb_pixel_t color); -fb_pixel_t changeBrightnessRGBRel(fb_pixel_t color, int br, bool transp=true); -fb_pixel_t changeBrightnessRGB(fb_pixel_t color, uint8_t br, bool transp=true); +fb_pixel_t changeBrightnessRGBRel(fb_pixel_t color, int br, bool transp = true); +fb_pixel_t changeBrightnessRGB(fb_pixel_t color, uint8_t br, bool transp = true); -fb_pixel_t Hsv2SysColor(HsvColor *hsv, uint8_t tr=0xFF); +fb_pixel_t Hsv2SysColor(HsvColor *hsv, uint8_t tr = 0xFF); uint8_t SysColor2Hsv(fb_pixel_t color, HsvColor *hsv); void Hsv2Rgb(HsvColor *hsv, RgbColor *rgb); @@ -172,12 +178,13 @@ void Rgb2Hsv(RgbColor *rgb, HsvColor *hsv); void getItemColors(fb_pixel_t &t, fb_pixel_t &b, bool selected = false, bool marked = false, bool toggle_background = false, bool toggle_enlighten = false); -typedef struct { +typedef struct +{ uint8_t min; uint8_t max; } col_range_t; -fb_pixel_t getRandomColor(col_range_t range_r = {1,255}, col_range_t range_g = {1,255}, col_range_t range_b = {1,255}, uint8_t Alpha = 0); +fb_pixel_t getRandomColor(col_range_t range_r = {1, 255}, col_range_t range_g = {1, 255}, col_range_t range_b = {1, 255}, uint8_t Alpha = 0); #endif diff --git a/src/gui/color_custom.h b/src/gui/color_custom.h index ffaf331db..dd48d2a99 100644 --- a/src/gui/color_custom.h +++ b/src/gui/color_custom.h @@ -2,7 +2,9 @@ #define __color_custom__ #define COLOR_CUSTOM 0x0 + #ifdef FB_USE_PALETTE + /* #define COL_WHITE (COLOR_CUSTOM + 0) #define COL_RED (COLOR_CUSTOM + 1) @@ -25,7 +27,9 @@ #define COL_LIGHT_BLUE 0x0F #define COL_WHITE 0x10 #define COL_BLACK 0x11 + #else + #define COL_DARK_RED0 0x02 #define COL_DARK_GREEN0 0x03 #define COL_OLIVE0 0x04 @@ -55,7 +59,8 @@ #define COL_LIGHT_BLUE (CFrameBuffer::getInstance()->realcolor[0x0F]) #define COL_WHITE (CFrameBuffer::getInstance()->realcolor[0x10]) #define COL_BLACK (CFrameBuffer::getInstance()->realcolor[0x11]) -#endif + +#endif // FB_USE_PALETTE #define COL_RANDOM (getRandomColor())