25 #include "lv_palette.h"
26 #include "lv_common.h"
41 void Palette::allocate_colors (
unsigned int ncolors)
43 colors.resize (ncolors);
48 visual_return_if_fail (src1.size () != src2.size ());
49 visual_return_if_fail (size () != src1.size ());
51 for (
unsigned int i = 0; i < colors.size (); i++) {
52 colors[i].r = src1.colors[i].r + ((src2.colors[i].r - src1.colors[i].r) * rate);
53 colors[i].g = src1.colors[i].g + ((src2.colors[i].g - src1.colors[i].g) * rate);
54 colors[i].b = src1.colors[i].b + ((src2.colors[i].b - src1.colors[i].b) * rate);
60 int irate = int (rate);
62 float rdiff = rate - irate;
69 irate %= colors.size ();
71 uint8_t alpha = rdiff * 255;
73 auto const tmp1 = &colors[irate];
76 if (irate ==
int (size() - 1))
79 tmp2 = &colors[irate + 1];
81 return Color ((alpha * (tmp1->r - tmp2->
r) >> 8) + tmp2->
r,
82 (alpha * (tmp1->g - tmp2->
g) >> 8) + tmp2->
g,
83 (alpha * (tmp1->b - tmp2->
b) >> 8) + tmp2->
b);
86 int Palette::find_color (
Color const& color)
const
88 for (
unsigned int i = 0; i < colors.size(); i++) {
89 if (colors[i] == color)