libvisual  0.5.0
lv_color.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
7  * Dennis Smit <ds@nerds-incorporated.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef _LV_COLOR_H
25 #define _LV_COLOR_H
26 
27 #include <libvisual/lv_types.h>
28 
34 #ifdef __cplusplus
35 
36 namespace LV {
37 
38  struct LV_API Color
39  {
40  uint8_t r;
41  uint8_t g;
42  uint8_t b;
43  uint8_t a;
48  Color ()
49  : r (0), g (0), b (0), a (0)
50  {}
51 
60  Color (uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_ = 255)
61  : r (r_), g(g_), b(b_), a(a_)
62  {}
63 
74  friend bool operator== (Color const& c1, Color const& c2)
75  {
76  return ( c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
77  }
78 
87  void set (uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_ = 255)
88  {
89  r = r_; g = g_; b = b_; a = a_;
90  }
91 
99  void set_hsv (float h, float s, float v);
100 
113  void get_hsv (float& h, float& s, float& v) const;
114 
115  void set_from_uint16 (uint16_t rgb);
116  void set_from_uint32 (uint32_t rgba);
117 
118  uint32_t to_uint32 () const;
119  uint16_t to_uint16 () const;
120 
121  static Color const& white()
122  {
123  static Color color(255, 255, 255);
124  return color;
125  }
126 
127  static Color const& black()
128  {
129  static Color color(0, 0, 0);
130  return color;
131  }
132  };
133 
134 } // LV namespace
135 
136 #endif // __cplusplus
137 
138 LV_BEGIN_DECLS
139 
140 #ifdef __cplusplus
141 typedef ::LV::Color VisColor;
142 #else
143 typedef struct _VisColor VisColor;
144 struct _VisColor
145 {
146  uint8_t r, g, b, a; // NOTE: this must be synced with LV::Color
147 };
148 #endif
149 
150 LV_API VisColor *visual_color_new (void);
151 LV_API VisColor *visual_color_clone (VisColor *color);
152 LV_API void visual_color_free (VisColor *color);
153 
154 LV_API int visual_color_compare (VisColor *src1, VisColor *src2);
155 
156 LV_API void visual_color_copy (VisColor *dest, VisColor *src);
157 LV_API void visual_color_set (VisColor *color, uint8_t r, uint8_t g, uint8_t b);
158 LV_API void visual_color_set_rgba (VisColor *color, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
159 LV_API void visual_color_set_hsv (VisColor *color, float h, float s, float v);
160 LV_API void visual_color_get_hsv (VisColor *color, float *h, float *s, float *v);
161 
162 LV_API void visual_color_set_from_uint32 (VisColor *color, uint32_t rgb);
163 LV_API void visual_color_set_from_uint16 (VisColor *color, uint16_t rgb);
164 
165 LV_API uint32_t visual_color_to_uint32 (VisColor *color);
166 LV_API uint16_t visual_color_to_uint16 (VisColor *color);
167 
168 LV_API VisColor *visual_color_black (void);
169 LV_API VisColor *visual_color_white (void);
170 
171 LV_END_DECLS
172 
177 #endif /* _LV_COLOR_H */