color: formatting code using astyle

Origin commit data
------------------
Branch: ni/coolstream
Commit: 6eaac512fb
Author: vanhofen <vanhofen@gmx.de>
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
This commit is contained in:
vanhofen
2021-11-19 21:51:01 +01:00
parent 61700d8d8c
commit 7e25b366e1
3 changed files with 114 additions and 90 deletions

View File

@@ -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;
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;
}

View File

@@ -53,6 +53,7 @@
#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)
@@ -77,7 +78,9 @@
#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)])
@@ -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

View File

@@ -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())