-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaletteGenerator.hpp
96 lines (85 loc) · 1.91 KB
/
PaletteGenerator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef PaletteGenerator_h
#define PaletteGenerator_h
#include "Arduino.h"
#include <FastLED.h>
class RGBcolor
{
public:
RGBcolor();
RGBcolor(int r, int g, int b);
bool isValid();
int _r;
int _g;
int _b;
private:
};
class HCLcolor
{
public:
HCLcolor();
HCLcolor(float h, float c, float l);
bool inRange(int hmin, int hmax, int cmin, int cmax, int lmin, int lmax);
int _h;
int _c;
int _l;
private:
};
class LABcolor
{
public:
float _l;
float _a;
float _b;
bool sorted;
LABcolor();
LABcolor(float l, float a, float b);
LABcolor(const LABcolor &lab);
LABcolor &operator=(const LABcolor &rhs);
LABcolor &operator+=(const LABcolor &rhs);
LABcolor &operator/=(const int &rhs);
void setLAB(float fl, float fa, float fb);
RGBcolor toRGB();
HCLcolor toHCL();
bool checkColor();
private:
const struct
{
float xn = 0.950470;
float yn = 1;
float zn = 1.088830;
float t0 = 0.137931034; // 4 / 29
float t1 = 0.206896552; // 6 / 29
float t2 = 0.12841855; // 3 * t1 * t1
float t3 = 0.008856452; // t1 * t1 * t1
} _constants;
float lab_xyz(float t);
int xyz_rgb(float r);
};
class PaletteGenerator
{
public:
static const int all[6];
int _hmin;
int _hmax;
int _cmin;
int _cmax;
int _lmin;
int _lmax;
PaletteGenerator();
void setColorSpace(const int *space);
CRGBPalette16 generate(const byte colorsCount);
private:
struct Vector
{
float dl, da, db;
Vector(){};
Vector(float dl, float da, float db) : dl(dl), da(da), db(db){};
};
float rnd();
float euclidean(LABcolor lab1, LABcolor lab2);
void initPalette(LABcolor *colors, byte colorsCount);
void forceVector(LABcolor *colors, byte colorsCount);
void kMeans(LABcolor *colors, byte colorsCount);
bool checkColor(LABcolor lab);
};
#endif