The friendly Operating System for the Internet of Things
color.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 - 2016 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
23 #ifndef COLOR_H
24 #define COLOR_H
25 
26 #include <stdint.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
35 typedef struct {
36  uint8_t r;
37  uint8_t g;
38  uint8_t b;
39 } color_rgb_t;
40 
44 typedef struct {
45  float h;
46  float s;
47  float v;
48 } color_hsv_t;
49 
50 
57 void color_rgb2hsv(color_rgb_t *rgb, color_hsv_t *hsv);
58 
65 void color_hsv2rgb(color_hsv_t *hsv, color_rgb_t *rgb);
66 
75 void color_hex2rgb(const uint32_t hex, color_rgb_t *rgb);
76 
85 void color_rgb2hex(const color_rgb_t *rgb, uint32_t *hex);
86 
96 void color_str2rgb(const char *str, color_rgb_t *color);
97 
106 void color_rgb2str(const color_rgb_t *rgb, char *str);
107 
116 static inline void color_rgb_invert(const color_rgb_t *rgb, color_rgb_t *inv_rgb)
117 {
118  inv_rgb->r = rgb->r ^ 0xFF;
119  inv_rgb->g = rgb->g ^ 0xFF;
120  inv_rgb->b = rgb->b ^ 0xFF;
121 }
122 
134 void color_rgb_complementary(const color_rgb_t *rgb, color_rgb_t *comp_rgb);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* COLOR_H */
141 
float h
hue value [0.0 - 360.0]
Definition: color.h:45
void color_rgb2hex(const color_rgb_t *rgb, uint32_t *hex)
Convert a rgb struct to a hex value of the form 0x00RRGGBB.
void color_str2rgb(const char *str, color_rgb_t *color)
Convert a hex color string of the form 'RRGGBB' to a color_rgb_t struct.
void color_rgb2hsv(color_rgb_t *rgb, color_hsv_t *hsv)
Convert RGB color to HSV color.
static void color_rgb_invert(const color_rgb_t *rgb, color_rgb_t *inv_rgb)
Invert a given rgb color.
Definition: color.h:116
uint8_t b
blue value [0 - 255]
Definition: color.h:38
void color_hex2rgb(const uint32_t hex, color_rgb_t *rgb)
Convert a hex value of the form 0x00RRGGBB to an RGB color struct.
uint8_t g
green value [0 - 255]
Definition: color.h:37
Data-structure for holding HSV colors.
Definition: color.h:44
void color_hsv2rgb(color_hsv_t *hsv, color_rgb_t *rgb)
Convert HSV color to RGB color.
uint8_t r
red value [0 - 255]
Definition: color.h:36
void color_rgb_complementary(const color_rgb_t *rgb, color_rgb_t *comp_rgb)
Calculate the complementary color of a given rgb color.
Data-structure describing a RGB color.
Definition: color.h:35
float s
saturation value [0.0 - 1.0]
Definition: color.h:46
void color_rgb2str(const color_rgb_t *rgb, char *str)
Convert a color_rgb_t struct to a hex color string of the form 'RRGGBB'.
float v
value [0.0 - 1.0]
Definition: color.h:47