#include <stdint.h>
Go to the source code of this file.
|  | 
| uint32_t | hsv_to_rgb (uint16_t h, uint8_t s, uint8_t v) | 
|  | Convert HSV to RGB. 
 | 
|  | 
◆ hsv_to_rgb()
      
        
          | uint32_t hsv_to_rgb | ( | uint16_t | h, | 
        
          |  |  | uint8_t | s, | 
        
          |  |  | uint8_t | v | 
        
          |  | ) |  |  | 
      
 
Convert HSV to RGB. 
- Parameters
- 
  
  
- Returns
- : RGB 32-bit color 
Definition at line 5 of file hsv.c.
    6{
    7    float hf = h / 60.0f;
    8    float sf = s / 255.0f;
    9    float vf = v / 255.0f;
   10 
   11    int i = (int)hf % 6;
   12    float f = hf - (int)hf;
   13    uint8_t p = (uint8_t)(vf * (1.0f - sf) * 255);
   14    uint8_t q = (uint8_t)(vf * (1.0f - sf * f) * 255);
   15    uint8_t t = (uint8_t)(vf * (1.0f - sf * (1.0f - f)) * 255);
   16    uint8_t vi = (uint8_t)(vf * 255);
   17 
   18    uint8_t r, g, b;
   19    switch (i) {
   20        case 0:
   21            r = vi;
   22            g = t;
   23            b = p;
   24            break;
   25        case 1:
   26            r = q;
   27            g = vi;
   28            b = p;
   29            break;
   30        case 2:
   31            r = p;
   32            g = vi;
   33            b = t;
   34            break;
   35        case 3:
   36            r = p;
   37            g = q;
   38            b = vi;
   39            break;
   40        case 4:
   41            r = t;
   42            g = p;
   43            b = vi;
   44            break;
   45        case 5:
   46            r = vi;
   47            g = p;
   48            b = q;
   49            break;
   50        default:
   51            r = 0;
   52            g = 0;
   53            b = 0;
   54            break;
   55    }
   57}
References URGB.
Referenced by apply_rainbow_cycle_effect(), apply_rainbow_wheel_effect(), and set_rainbow_spectrum().