Debian Codegraph @

pt_pal_editor/src/palette.c

raw symbols SCIP
1 #include <stdio.h>
2 #include <string.h>
3 #include "gui.h"
4 #include "palette.h"
5 #include "tinyfiledialogs/tinyfiledialogs.h"
6
7 // 12-bit RGB values
8 uint16_t palette[8];
9 uint16_t vuColors[48];
10 uint16_t analyzerColors[36];
11
12 // 12-bit RGB values
13 static const uint16_t originalPalette[8] =
14 {
15 0x000, // 00- PAL_BACKGRD
16 0xBBB, // 01- PAL_BORDER
17 0x888, // 02- PAL_GENBKG
18 0x555, // 03- PAL_GENBKG2
19 0xFD0, // 04- PAL_QADSCP
20 0xD04, // 05- PAL_PATCURSOR
21 0x000, // 06- PAL_GENTXT
22 0x34F // 07- PAL_PATTXT
23 };
24
25 // 12-bit RGB values
26 static const uint16_t vuOriginalColors[48] =
27 {
28 0xF00, 0xF00, 0xF10, 0xF10, 0xF20, 0xF20, 0xF30, 0xF30,
29 0xF40, 0xF50, 0xF60, 0xF70, 0xF80, 0xF90, 0xFA0, 0xFB0,
30 0xFC0, 0xFD0, 0xFE0, 0xFF0, 0xFF0, 0xEF0, 0xEF0, 0xDF0,
31 0xDF0, 0xCF0, 0xCF0, 0xBF0, 0xBF0, 0xAF0, 0x9F0, 0x9F0,
32 0x8F0, 0x8F0, 0x7F0, 0x7F0, 0x6F0, 0x6F0, 0x5F0, 0x5F0,
33 0x4F0, 0x4F0, 0x3F0, 0x3F0, 0x2F0, 0x1F0, 0x0F0, 0x0E0
34 };
35
36 // 12-bit RGB values
37 static const uint16_t analyzerOriginalColors[48] =
38 {
39 0xF00, 0xF10, 0xF20, 0xF30, 0xF40, 0xF50, 0xF60, 0xF70,
40 0xF80, 0xF90, 0xFA0, 0xFB0, 0xFC0, 0xFD0, 0xFE0, 0xFF0,
41 0xEF0, 0xDF0, 0xCF0, 0xBF0, 0xAF0, 0x9F0, 0x8F0, 0x7F0,
42 0x6F0, 0x5F0, 0x4F0, 0x3F0, 0x2F0, 0x1F0, 0x0F0, 0x0E0,
43 0x0D0, 0x0C0, 0x0B0, 0x0A0
44 };
45
46 static uint16_t undo1Col, undo1ColIndex, can1Cols[8];
47 static uint16_t undo2Col, undo2ColIndex, can2ColsVu[48], can2ColsAna[36];
48
49 // these will be generated in realtime based on vuColors
50 uint32_t spectrumAnalyzerBMP[36], vuMeterBMP[480], patternCursorBMP[154];
51
52 void fillCancel1Colors(void)
53 {
54 memcpy(can1Cols, palette, sizeof (palette));
55 }
56
57 void cancel1Color(void)
58 {
59 memcpy(palette, can1Cols, sizeof (palette));
60 }
61
62 void setUndo1Color(uint8_t paletteIndex)
63 {
64 undo1ColIndex = paletteIndex;
65 undo1Col = palette[undo1ColIndex];
66 }
67
68 void undo1Color(void)
69 {
70 uint16_t oldColor = palette[undo1ColIndex];
71 palette[undo1ColIndex] = undo1Col;
72 undo1Col = oldColor;
73 }
74
75 void fillCancel2Colors(void)
76 {
77 memcpy(can2ColsVu, vuColors, sizeof (vuColors));
78 memcpy(can2ColsAna, analyzerColors, sizeof (analyzerColors));
79 }
80
81 void cancel2Color(void)
82 {
83 if (theRightColors == vuColors)
84 memcpy(vuColors, can2ColsVu, sizeof (vuColors));
85 else
86 memcpy(analyzerColors, can2ColsAna, sizeof (analyzerColors));
87 }
88
89 void setUndo2Color(uint8_t colorIndex)
90 {
91 undo2ColIndex = colorIndex;
92 undo2Col = theRightColors[colorIndex];
93 }
94
95 void undo2Color(void)
96 {
97 uint16_t oldColor = theRightColors[undo2ColIndex];
98 theRightColors[undo2ColIndex] = undo2Col;
99 undo2Col = oldColor;
100 }
101
102 void setDefaultPalette(void)
103 {
104 memcpy(palette, originalPalette, sizeof (palette));
105 }
106
107 void setDefaultVuColors(void)
108 {
109 memcpy(vuColors, vuOriginalColors, sizeof (vuColors));
110 }
111
112 void setDefaultAnalyzerColors(void)
113 {
114 memcpy(analyzerColors, analyzerOriginalColors, sizeof (analyzerColors));
115 }
116
117 uint16_t colorPicker(uint16_t inputColor)
118 {
119 uint8_t aDefaultRGB[3], aoResultRGB[3];
120 uint32_t pixel32, defaultCol24;
121
122 defaultCol24 = RGB12_to_RGB24(inputColor);
123
124 aDefaultRGB[0] = R24(defaultCol24);
125 aDefaultRGB[1] = G24(defaultCol24);
126 aDefaultRGB[2] = B24(defaultCol24);
127
128 if (tinyfd_colorChooser("Pick a color", NULL, aDefaultRGB, aoResultRGB) == NULL)
129 return 0xFFFF; // cancel/exit
130
131 pixel32 = (aoResultRGB[0] << 16) | (aoResultRGB[1] << 8) | aoResultRGB[2];
132 return RGB24_to_RGB12(pixel32);
133 }
134
135 void updatePatternCursorBMP(void)
136 {
137 uint8_t r8, g8, b8;
138 int32_t x;
139 uint32_t pixel24;
140
141 pixel24 = RGB12_to_RGB24(palette[PAL_PATCURSOR]);
142 for (int32_t y = 0; y < 14; y++)
143 {
144 // top two rows have a lighter color
145 if (y < 2)
146 {
147 r8 = R24(pixel24);
148 g8 = G24(pixel24);
149 b8 = B24(pixel24);
150
151 if (r8 <= 0xFF-0x33)
152 r8 += 0x33;
153 else
154 r8 = 0xFF;
155
156 if (g8 <= 0xFF-0x33)
157 g8 += 0x33;
158 else
159 g8 = 0xFF;
160
161 if (b8 <= 0xFF-0x33)
162 b8 += 0x33;
163 else
164 b8 = 0xFF;
165
166 for (x = 0; x < 11; x++)
167 patternCursorBMP[(y * 11) + x] = RGB24(r8, g8, b8);
168 }
169
170 // sides (same color)
171 if (y >= 2 && y <= 12)
172 {
173 patternCursorBMP[(y * 11) + 0] = pixel24;
174
175 for (x = 1; x < 10; x++)
176 patternCursorBMP[(y * 11) + x] = RGB24_COLORKEY;
177
178 patternCursorBMP[(y * 11) + 10] = pixel24;
179 }
180
181 // bottom two rows have a darker color
182 if (y > 11)
183 {
184 r8 = R24(pixel24);
185 g8 = G24(pixel24);
186 b8 = B24(pixel24);
187
188 if (r8 >= 0x33)
189 r8 -= 0x33;
190 else
191 r8 = 0x00;
192
193 if (g8 >= 0x33)
194 g8 -= 0x33;
195 else
196 g8 = 0x00;
197
198 if (b8 >= 0x33)
199 b8 -= 0x33;
200 else
201 b8 = 0x00;
202
203 for (x = 0; x < 11; x++)
204 patternCursorBMP[(y * 11) + x] = RGB24(r8, g8, b8);
205 }
206 }
207 }
208
209 void updateSpectrumAnalyzerBMP(void)
210 {
211 for (int32_t i = 0; i < 36; i++)
212 spectrumAnalyzerBMP[i] = RGB12_to_RGB24(analyzerColors[35-i]);
213 }
214
215 void updateVuMeterBMP(void)
216 {
217 uint8_t r8, g8, b8, r8_2, g8_2, b8_2;
218 uint16_t pixel12;
219 uint32_t pixel24;
220
221 for (int32_t i = 0; i < 48; i++)
222 {
223 pixel12 = vuColors[47-i];
224
225 r8_2 = r8 = R12_to_R24(pixel12);
226 g8_2 = g8 = G12_to_G24(pixel12);
227 b8_2 = b8 = B12_to_B24(pixel12);
228
229 // brighter pixels on the left side
230
231 if (r8_2 <= 0xFF-0x33)
232 r8_2 += 0x33;
233 else
234 r8_2 = 0xFF;
235
236 if (g8_2 <= 0xFF-0x33)
237 g8_2 += 0x33;
238 else
239 g8_2 = 0xFF;
240
241 if (b8_2 <= 0xFF-0x33)
242 b8_2 += 0x33;
243 else
244 b8_2 = 0xFF;
245
246 pixel24 = RGB24(r8_2, g8_2, b8_2);
247
248 vuMeterBMP[(i * 10) + 0] = pixel24;
249 vuMeterBMP[(i * 10) + 1] = pixel24;
250
251 // main pixels
252 for (int32_t j = 2; j < 8; j++)
253 vuMeterBMP[(i * 10) + j] = RGB24(r8, g8, b8);
254
255 // darker pixels on the right side
256 r8_2 = r8;
257 g8_2 = g8;
258 b8_2 = b8;
259
260 if (r8_2 >= 0x33)
261 r8_2 -= 0x33;
262 else
263 r8_2 = 0x00;
264
265 if (g8_2 >= 0x33)
266 g8_2 -= 0x33;
267 else
268 g8_2 = 0x00;
269
270 if (b8_2 >= 0x33)
271 b8_2 -= 0x33;
272 else
273 b8_2 = 0x00;
274
275 pixel24 = RGB24(r8_2, g8_2, b8_2);
276
277 vuMeterBMP[(i * 10) + 8] = pixel24;
278 vuMeterBMP[(i * 10) + 9] = pixel24;
279 }
280 }
281
282 void updateBMPs(void)
283 {
284 updatePatternCursorBMP();
285 updateSpectrumAnalyzerBMP();
286 updateVuMeterBMP();
287 }