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 {
46  uint8_t alpha;
47 } color_rgba_t;
48 
52 typedef struct {
53  float h;
54  float s;
55  float v;
56 } color_hsv_t;
57 
64 void color_rgb2hsv(color_rgb_t *rgb, color_hsv_t *hsv);
65 
72 void color_hsv2rgb(color_hsv_t *hsv, color_rgb_t *rgb);
73 
82 void color_hex2rgb(const uint32_t hex, color_rgb_t *rgb);
83 
92 void color_rgb2hex(const color_rgb_t *rgb, uint32_t *hex);
93 
103 void color_str2rgb(const char *str, color_rgb_t *color);
104 
113 void color_rgb2str(const color_rgb_t *rgb, char *str);
114 
123 static inline void color_rgb_invert(const color_rgb_t *rgb, color_rgb_t *inv_rgb)
124 {
125  inv_rgb->r = rgb->r ^ 0xFF;
126  inv_rgb->g = rgb->g ^ 0xFF;
127  inv_rgb->b = rgb->b ^ 0xFF;
128 }
129 
141 void color_rgb_complementary(const color_rgb_t *rgb, color_rgb_t *comp_rgb);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* COLOR_H */
148 
float h
hue value [0.0 - 360.0]
Definition: color.h:53
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 &#39;RRGGBB&#39; to a color_rgb_t struct.
void color_rgb2hsv(color_rgb_t *rgb, color_hsv_t *hsv)
Convert RGB color to HSV color.
uint8_t alpha
alpha value [0 - 255]
Definition: color.h:46
static void color_rgb_invert(const color_rgb_t *rgb, color_rgb_t *inv_rgb)
Invert a given rgb color.
Definition: color.h:123
uint8_t b
blue value [0 - 255]
Definition: color.h:38
RGBA color value.
Definition: color.h:44
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:52
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
color_rgb_t color
RGB value.
Definition: color.h:45
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:54
void color_rgb2str(const color_rgb_t *rgb, char *str)
Convert a color_rgb_t struct to a hex color string of the form &#39;RRGGBB&#39;.
float v
value [0.0 - 1.0]
Definition: color.h:55