libvisual  0.5.0
lv_palette_c.cpp
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  *
5  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 
22 #include "config.h"
23 #include "lv_palette.h"
24 #include "lv_common.h"
25 
26 extern "C" {
27 
28  VisPalette* visual_palette_new (unsigned int ncolors)
29  {
30  return new LV::Palette (ncolors);
31  }
32 
33  void visual_palette_free (VisPalette *self)
34  {
35  delete self;
36  }
37 
38  VisPalette *visual_palette_clone (VisPalette *self)
39  {
40  return new LV::Palette (*self);
41  }
42 
43  void visual_palette_copy (VisPalette *self, VisPalette *src)
44  {
45  visual_return_if_fail (self != nullptr);
46  visual_return_if_fail (src != nullptr);
47 
48  *self = *src;
49  }
50 
51  void visual_palette_allocate_colors (VisPalette *self, int ncolors)
52  {
53  visual_return_if_fail (self != nullptr);
54 
55  self->allocate_colors (ncolors);
56  }
57 
58  unsigned int visual_palette_get_size (VisPalette *self)
59  {
60  visual_return_val_if_fail (self != nullptr, 0);
61 
62  return self->size ();
63  }
64 
65  VisColor *visual_palette_get_colors (VisPalette *self)
66  {
67  visual_return_val_if_fail (self != nullptr, nullptr);
68  visual_return_val_if_fail (self->size() > 0, nullptr);
69 
70  return self->colors.data ();
71  }
72 
73  VisColor *visual_palette_get_color (VisPalette *self, int index)
74  {
75  visual_return_val_if_fail (self != nullptr, nullptr);
76  visual_return_val_if_fail (self->size() > 0, nullptr);
77  visual_return_val_if_fail (index < 0, nullptr);
78 
79  return &self->colors[index];
80  }
81 
82  void visual_palette_blend (VisPalette *self, VisPalette *src1, VisPalette *src2, float rate)
83  {
84  visual_return_if_fail (self != nullptr);
85  visual_return_if_fail (src1 != nullptr);
86  visual_return_if_fail (src2 != nullptr);
87 
88  self->blend (*src1, *src2, rate);
89  }
90 
91  int visual_palette_find_color (VisPalette *self, VisColor *color)
92  {
93  visual_return_val_if_fail (self != nullptr, -1);
94 
95  return self->find_color (*color);
96  }
97 
98 } // C extern