Skip to content

Commit

Permalink
removed HSV code
Browse files Browse the repository at this point in the history
HSV colors where never implemented and would introduce no additional
benefit since LED's are at best RGB.

HSV could be added to a separate library if required.
  • Loading branch information
peterzuger committed Jan 29, 2021
1 parent 1da534a commit ca3c669
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 122 deletions.
92 changes: 0 additions & 92 deletions tlc5947/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ rgb12 rgbtorgb12(rgb c){
return _c;
}

hsv hsvfade(hsv a, hsv b, uint32_t steps, uint32_t step){
hsv c;
c.h = a.h + (((b.h - a.h) / steps) * step);
c.s = a.s + (((b.s - a.s) / steps) * step);
c.v = a.v + (((b.v - a.v) / steps) * step);
return c;
}

rgb12 rgb12fade(rgb12 a, rgb12 b, uint32_t steps, uint32_t step){
rgb12 c;
c.r = (a.r > b.r) ? a.r - (((a.r - b.r) / steps) * step) : a.r + (((b.r - a.r) / steps) * step);
Expand All @@ -170,13 +162,6 @@ bool rgbvalid(rgb c){
return true;
}

bool hsvvalid(hsv c){
if((c.s > 1) || (c.v > 1) || (c.h > 360) ||
((c.s < 0) || (c.v < 0) || (c.h < 0)))
return false;
return true;
}


/**
* typesafe min(a,b) / max(a,b) macros
Expand All @@ -194,82 +179,5 @@ bool hsvvalid(hsv c){
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))

hsv rgbtohsv(rgb c){
hsv _c;
float min, max, delta;
min = min3(c.r, c.g, c.b);
max = max3(c.r, c.g, c.b);
_c.v = max; // v
delta = max - min;
if(max != 0){
_c.s = delta / max; // s
}else{
// r = g = b = 0 // s = 0, v is undefined
_c.s = 0;
_c.h = -1;
return _c;
}

if(c.r == max)
_c.h = ( c.g - c.b ) / delta; // between yellow & magenta
else if( c.g == max )
_c.h = 2 + ( c.b - c.r ) / delta; // between cyan & yellow
else
_c.h = 4 + ( c.r - c.g ) / delta; // between magenta & cyan
_c.h *= 60; // degrees
if(_c.h < 0)
_c.h += 360;
return _c;
}

rgb hsvtorgb(hsv c){
rgb _c;
int i;
float f, p, q, t;
if(c.s == 0 || c.v == 0){
// achromatic (grey)
_c.r = _c.g = _c.b = c.v;
return _c;
}
c.h /= 60; // sector 0 to 5
i = (int)floorf( c.h );
f = c.h - i; // factorial part of h
p = c.v * ( 1 - c.s );
q = c.v * ( 1 - c.s * f );
t = c.v * ( 1 - c.s * ( 1 - f ) );
switch(i){
case 0:
_c.r = c.v;
_c.g = t;
_c.b = p;
break;
case 1:
_c.r = q;
_c.g = c.v;
_c.b = p;
break;
case 2:
_c.r = p;
_c.g = c.v;
_c.b = t;
break;
case 3:
_c.r = p;
_c.g = q;
_c.b = c.v;
break;
case 4:
_c.r = t;
_c.g = p;
_c.b = c.v;
break;
default:
_c.r = c.v;
_c.g = p;
_c.b = q;
break;
}
return _c;
}

#endif /* defined(MODULE_TLC5947_ENABLED) && MODULE_TLC5947_ENABLED == 1 */
12 changes: 0 additions & 12 deletions tlc5947/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ typedef struct{
float b; /*< blue [0 -> 1] */
}rgb;

typedef struct{
float h; /*< hue [0 -> 360] */
float s; /*< saturation [0 -> 1] */
float v; /*< value [0 -> 1] */
}hsv;


#if defined(__cplusplus)
extern "C"{
Expand Down Expand Up @@ -86,17 +80,11 @@ rgb rgb8torgb(rgb8 c)__attribute__ ((const));
rgb12 rgbtorgb12(rgb c)__attribute__ ((const));
rgb8 rgbtorgb8(rgb c)__attribute__ ((const));

hsv hsvfade(hsv a, hsv b, uint32_t steps, uint32_t step);
rgb12 rgb12fade(rgb12 a, rgb12 b, uint32_t steps, uint32_t step);

#define rgb12valid (1) /* cannot be invalid */
#define rgb8valid (1) /* cannot be invalid */
bool rgbvalid(rgb c)__attribute__ ((const));
bool hsvvalid(hsv c)__attribute__ ((const));


rgb hsvtorgb(hsv c)__attribute__ ((const));
hsv rgbtohsv(rgb c)__attribute__ ((const));


#if defined(__cplusplus)
Expand Down
20 changes: 2 additions & 18 deletions tlc5947/tlc5947.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
* LED language
*
* "#RRGGBB" this is a color in RGB format
* "$220,1.0,0.5" this is a color in HSV format
* "|50" this sleeps for 50 ticks
* "\b25" this decreases brightness by 25%
* "<5" this pushes 5 onto the stack
Expand Down Expand Up @@ -75,8 +74,7 @@
*
* "<5[#FF0000<10[|50\b-0.1-]>-|50]"
* This is a more complex pattern, it sets the led to full red, and then
* every 50 ticks decreases the brightness by 0.1 in HSV color space and
* this is repeated 5 times.
* every 50 ticks decreases the brightness by 0.1 and this is repeated 5 times.
*/
typedef enum{
pCOLOR, // change color
Expand Down Expand Up @@ -610,7 +608,7 @@ static inline __attribute__((pure)) char gethex(uint8_t i){

/**
* This function checks that all colors used
* in this string are valid RGB or HSV colors.
* in this string are valid RGB.
*/
static bool check_colors(const char* s){
while(*s){
Expand All @@ -620,8 +618,6 @@ static bool check_colors(const char* s){
if(!isxdigit(s[i]))
return false;
break;
case '$':// TODO
break;
default:
break;
}
Expand All @@ -638,11 +634,6 @@ static size_t get_pattern_length(const char* s){
s += 6;
break;

case '$':
len++;
s += 11;
break;

case '\b':
while(isdigit(*s) || (*s == '.') || (*s == '-'))
s++;
Expand Down Expand Up @@ -746,13 +737,6 @@ static void tokenize_pattern_str(const char* s, token_t* pat, size_t len){
s += 7;
break;

case '$':
dprintf("HSV COLOR\n\r");
pat[i].type = pCOLOR;
// TODO: implement HSV color
mp_raise_NotImplementedError(MP_ERROR_TEXT("HSV color"));
break;

case '@':
dprintf("TRANSPARENT\n\r");
pat[i].type = pTRANSPARENT;
Expand Down

0 comments on commit ca3c669

Please sign in to comment.