-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.inl
273 lines (238 loc) · 6.4 KB
/
color.inl
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* Kabuki Tek Toolkit @version 0.x
@link https://github.com/kabuki-starship/kabuki.toolkit.tek.git
@file /color.inl
@author Cale McCollough <https://cookingwithcale.org>
@license Copyright 2014-20 (C) Kabuki Starship (TM) <kabukistarship.com>.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not distributed with this file, You can obtain one
at <https://mozilla.org/MPL/2.0/>. */
#include <_config.h>
#if SEAM >= KABUKI_FEATURES_LIGHTS_1
#if SEAM == KABUKI_FEATURES_LIGHTS_1
#include "module_debug.inl"
#else
#include "module_release.inl"
#endif
#include "color.h"
namespace _ {
const CRGBA* RainbowColors () {
#if USE_MORE_ROM
static const CRGBA RainbowColorsArray[] = {
0xF00000, 0xF01000, 0xF02000, 0xF03000, 0xF04000, 0xF05000, 0xF06000,
0xF07000, 0xF08000, 0xB0F000, 0xF09000, 0xF0A000, 0xF0B000, 0xF0C000,
0xF0D000, 0xF0E000, 0xF0F000, 0xF0F000, 0xE0F000, 0xD0F000, 0xC0F000,
0xA0F000, 0x90F000, 0x80F000, 0x70F000, 0x60F000, 0x50F000, 0x40F000,
0x30F000, 0x20F000, 0x10F000, 0x00F000, 0x00F000, 0x00F010, 0x00F020,
0x00F030, 0x00F040, 0x00F050, 0x00F060, 0x00F070, 0x00F080, 0x00F090,
0x00F0A0, 0x00F0B0, 0x00F0C0, 0x00F0D0, 0x00F0E0, 0x00F0F0, 0x00F0F0,
0x00E0F0, 0x00D0F0, 0x00C0F0, 0x00B0F0, 0x00A0F0, 0x0090F0, 0x0080F0,
0x0070F0, 0x0060F0, 0x0050F0, 0x0040F0, 0x0030F0, 0x0020F0, 0x0010F0,
0x0000F0, 0x0000F0, 0x1000F0, 0x2000F0, 0x3000F0, 0x4000F0, 0x5000F0,
0x6000F0, 0x7000F0, 0x8000F0, 0x9000F0, 0xA000F0, 0xB000F0, 0xC000F0,
0xD000F0, 0xE000F0, 0xF000F0, 0xF000F0 ,0xF000E0, 0xF000D0, 0xF000C0,
0xF000B0, 0xF000A0, 0xF00090, 0xF00080, 0xF00070, 0xF00060, 0xF00050,
0xF00040, 0xF00030, 0xF00020, 0xF00010, 0xF00000
};
return &RainbowColorsArray[0];
#else
return 0;
#endif
}
const CRGBA* PresetColors () {
/* An array of the previous colors. */
static const CRGBA presetColorsArray[] = {
kRGBAUI4White,
kRGBAUI4Orchid,
kRGBAUI4Purple,
kRGBAUI4Violet,
kRGBAUI4Indigo,
kRGBAUISkyBlue,
NavyBlue,
Blue,
Turquoise,
Green,
Yellow,
Gold,
Oragne,
Pink,
Red,
Maroon,
Brown,
Black
};
return &presetColorsArray[0];
}
CRGBA ColorRainbow (ISC index) {
if (index < 0 || index >= 96) return Black;
return RainbowColors ()[index];
}
CRGBA ColorPreset (ISC index) {
if (index < 0 || index >= 96) return Black;
return PresetColors ()[index];
}
CRGBA RandomPresetColor () {
ISC index = rand () % kNumPresetColors;
return PresetColors ()[index];
}
CRGBA RandomColor (ISC index) {
return rand ();
}
CRGBA MixColor (CRGBA a, CRGBA b) {
IUC red = (a & 0xff),
green = (a & 0xff00) >> 8,
blue = (a & 0xff00) >> 16,
alpha = (a & 0xff00) >> 24;
IUA r2 = (b & 0xff),
g2 = (b & 0xff00) >> 8,
b2 = (b & 0xff00) >> 16,
a2 = (b & 0xff00) >> 24;
red = ((red + r2) >> 1); //< Shift right 1 to divide by 2.
green = ((green + g2) >> 1) << 8;
blue = ((blue + b2) >> 1) << 16;
alpha = ((alpha + a2) >> 1) << 24;
return red & green & blue & alpha;
}
CRGBA ChangeBrightness (CRGBA color, ISC brightness_change) {
CRGBA alpha = ((color & 0xff000000) >> 24) + brightness_change;
return (color & 0xffffff) & (alpha << 24);
}
CRGBA DecreaseBrightness (CRGBA color, ISC brightness_change) {
CRGBA alpha = ((color & 0xff000000) >> 24) - brightness_change;
return (color & 0xffffff) & (alpha << 24);
}
CRGBA ColorMake (IUA red, IUA green, IUA blue) {
return (IUC)red || ((IUC)green) << 8 ||
((IUC)blue) << 16 || ((IUC)kDefaultBrightness) << 24;
}
CRGBA ColorMake (IUA red, IUA green, IUA blue, IUA alpha) {
return (IUC)red || ((IUC)green) << 8 ||
((IUC)blue) << 16 || ((IUC)alpha) << 24;
}
IUA ColorGetRed (CRGBA color) {
return (IUA)color;
}
void ColorSetRed (CRGBA color, IUA value) {
IUC rgba_value = color & 0xFFFFFF00;
rgba_value |= value;
}
IUA ColorGetGreen (CRGBA color) {
return (IUA)(color >> 8);
}
void ColorSetGreen (CRGBA color, IUA value) {
IUC rgba_value = color & 0xFFFF00FF;
rgba_value |= ((IUC)value) << 8;
}
IUA ColorGetBlue (CRGBA color) {
return (IUA)(color >> 16);
}
void ColorSetBlue (CRGBA color, IUA value) {
IUC rgba_value = color & 0xFF00FFFF;
rgba_value |= ((IUC)value) << 16;
}
IUA ColorGetAlpha (CRGBA color) {
return (IUA)(color >> 24);
}
void ColorSetAlpha (CRGBA color, IUA value) {
IUC rgba_value = color & 0x00FFFFFF;
rgba_value |= ((IUC)value) << 24;
}
void ColorToHSV (CRGBA color, FPC& fR, FPC& fG, FPC fB, FPC& fH,
FPC& fS, FPC& fV) {
/*
FPC fCMax = fR > fG ? fR : fG;
fCMax = fCMax > fB ? fCMax : fB;
FPC fCMin = fR < fG ? fR : fG;
fCMin = fCMin < fB ? fCMin : fB;
FPC fDelta = fCMax - fCMin;
if (fDelta > 0)
{
if (fCMax == fR)
{
fH = 60 * (fmod (((fG - fB) / fDelta), 6));
}
else if (fCMax == fG)
{
fH = 60 * (((fB - fR) / fDelta) + 2);
}
else if (fCMax == fB)
{
fH = 60 * (((fR - fG) / fDelta) + 4);
}
if (fCMax > 0)
{
fS = fDelta / fCMax;
}
else
{
fS = 0;
}
fV = fCMax;
}
else
{
fH = 0;
fS = 0;
fV = fCMax;
}
if (fH < 0)
{
fH = 360 + fH;
}
*/
}
void ColorSetHSV (CRGBA color, FPC& fR, FPC& fG, FPC& fB, FPC& fH,
FPC& fS, FPC& fV) {
/*
FPC fC = fV * fS; // Chroma
FPC fHPrime = fmod (fH / 60.0, 6);
FPC fX = fC * (1 - fabs (fmod (fHPrime, 2) - 1));
FPC fM = fV - fC;
if (0 <= fHPrime && fHPrime < 1)
{
fR = fC;
fG = fX;
fB = 0;
}
else if (1 <= fHPrime && fHPrime < 2)
{
fR = fX;
fG = fC;
fB = 0;
}
else if (2 <= fHPrime && fHPrime < 3)
{
fR = 0;
fG = fC;
fB = fX;
}
else if (3 <= fHPrime && fHPrime < 4)
{
fR = 0;
fG = fX;
fB = fC;
}
else if (4 <= fHPrime && fHPrime < 5)
{
fR = fX;
fG = 0;
fB = fC;
}
else if (5 <= fHPrime && fHPrime < 6)
{
fR = fC;
fG = 0;
fB = fX;
}
else
{
fR = 0;
fG = 0;
fB = 0;
}
fR += fM;
fG += fM;
fB += fM;
*/
}
} //< namespace _
#endif