RGB -> HUE Farbkalibrierung auf AVR

Gast #4365506
Lesenswert?

Nutze folgende Funktion um HUE nach RGB umzurechnen. Jedoch finde ich, 
dass gerade Farbraum beim Regenbogen nicht gleichmässig ist.

Gibt es da ein Korrekturarray?
1
const uint8_t dim_curve[] = {
2
  0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
3
  3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4
  4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6,
5
  6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
6
  8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11,
7
  11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15,
8
  15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20,
9
  20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26,
10
  27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35,
11
  36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47,
12
  48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
13
  63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82,
14
  83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109,
15
  110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
16
  146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
17
  193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255,
18
};
19

20
void hsv2rgb(struct cRGB *rgb, struct cHSV *hsv, int16_t led)
21
{
22
  uint8_t val = dim_curve[hsv[led].val];
23
  uint8_t sat = 255 - dim_curve[255-hsv[led].sat];
24
  uint16_t base = 0;
25
  
26
  if(sat == 0)
27
  {
28
    rgb[led].r = val;
29
    rgb[led].g = val;
30
    rgb[led].b = val;
31
  }
32
  else
33
  {
34
    base = ((255 - sat) * val) >> 8;
35
    switch (hsv[led].hue / 60) {
36
      case 0:
37
      rgb[led].r = val;
38
      rgb[led].g = (((val - base)*hsv[led].hue) / 60) + base;
39
      rgb[led].b = base;
40
      break;
41

42
      case 1:
43
      rgb[led].r = (((val - base)*(60 - (hsv[led].hue % 60))) / 60) + base;
44
      rgb[led].g = val;
45
      rgb[led].b = base;
46
      break;
47

48
      case 2:
49
      rgb[led].r = base;
50
      rgb[led].g = val;
51
      rgb[led].b = (((val - base)*(hsv[led].hue % 60)) / 60) + base;
52
      break;
53

54
      case 3:
55
      rgb[led].r = base;
56
      rgb[led].g = (((val - base)*(60 - (hsv[led].hue % 60))) / 60) + base;
57
      rgb[led].b = val;
58
      break;
59

60
      case 4:
61
      rgb[led].r = (((val - base)*(hsv[led].hue % 60)) / 60) + base;
62
      rgb[led].g = base;
63
      rgb[led].b = val;
64
      break;
65

66
      case 5:
67
      rgb[led].r = val;
68
      rgb[led].g = base;
69
      rgb[led].b = (((val - base)*(60 - (hsv[led].hue % 60))) / 60) + base;
70
      break;
71
    }
72
  }
73
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren