libvisual  0.5.0
lv_palette.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_PALETTE_H
25 #define _LV_PALETTE_H
26 
27 #include <libvisual/lvconfig.h>
28 #include <libvisual/lv_defines.h>
29 #include <libvisual/lv_color.h>
30 
36 #ifdef __cplusplus
37 
38 #include <vector>
39 
40 namespace LV {
41 
46  struct LV_API Palette
47  {
48  std::vector<Color> colors;
49 
53  Palette () = default;
54 
55  explicit Palette (unsigned int ncolors);
56 
57  Palette (Palette const&) = default;
58 
59  Palette (Palette&& palette)
60  : colors (std::move (palette.colors))
61  {}
62 
63  ~Palette ();
64 
65  Palette& operator= (Palette const& rhs) = default;
66 
67  Palette& operator= (Palette&& rhs)
68  {
69  colors.swap (rhs.colors);
70  return *this;
71  }
72 
73  bool empty () const
74  {
75  return colors.empty ();
76  }
77 
78  unsigned int size () const
79  {
80  return colors.size ();
81  }
82 
90  void blend (Palette const& src1, Palette const& src2, float rate);
91 
92 
98  void allocate_colors (unsigned int size);
99 
112  Color color_cycle (float rate);
113 
114  int find_color (Color const& color) const;
115  };
116 
117 } // LV namespace
118 
119 #endif // __cplusplus
120 
121 #ifdef __cplusplus
122 typedef struct LV::Palette VisPalette;
123 #else
124 typedef struct _VisPalette VisPalette;
125 struct _VisPalette;
126 #endif
127 
128 LV_BEGIN_DECLS
129 
130 LV_API VisPalette *visual_palette_new (unsigned int ncolors);
131 
132 LV_API void visual_palette_free (VisPalette *palette);
133 
134 LV_API VisPalette *visual_palette_clone (VisPalette *self);
135 
136 LV_API void visual_palette_copy (VisPalette *dest, VisPalette *src);
137 
138 LV_API VisColor *visual_palette_get_colors (VisPalette *pal);
139 
140 LV_API VisColor *visual_palette_get_color (VisPalette *pal, int index);
141 
142 LV_API unsigned int visual_palette_get_size (VisPalette *pal);
143 
144 LV_API void visual_palette_blend (VisPalette *dest, VisPalette *src1, VisPalette *src2, float rate);
145 
146 LV_API int visual_palette_find_color (VisPalette *pal, VisColor *color);
147 
148 
149 LV_END_DECLS
150 
155 #endif /* _LV_PALETTE_H */