-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaletteTest.cpp
272 lines (228 loc) · 8.26 KB
/
paletteTest.cpp
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
//
// paletteTest.cpp
//
// Created by massimo on 9/27/20.
//
#include "palette.h"
#include "paletteTest.h"
#include <unordered_set>
////////////////////////////////////////////////////////////////////////////////
namespace sg::paletteTest {
[[maybe_unused]]
void testPalette_Full_RGB()
{
palette::Palette p {};
p.allRGBColors();
std::cout << "palette size: " << p.size() << std::endl;
std::cout << "numColors: " << p.numColors();
p.saveRGBHexPalette("../palettes/generated/rgb/");
}
[[maybe_unused]]
void testPalette_00()
{
const uint32_t numColors {256 * 256 * 256};
float saturation {1.0f};
float brightness {1.0f};
palette::Palette p {};
while (saturation >= 0.0f)
{
p.makeCustomPalette(numColors, saturation, brightness);
std::cout << "\nnumColors, saturation, brightness: "
<< numColors << ", "
<< saturation << ", "
<< brightness
<< " -> palette size: " << p.size();
std::cout << "\n";
const std::string fileName {"../palettes/generated/tp00/s-" +
std::to_string(saturation) +
"-b-" + std::to_string(brightness) +"-"};
p.makePaletteImage<sg::bmp>(fileName);
p.saveRGBHexPalette(fileName);
// brightness = brightness - 0.1f;
saturation = saturation - 0.1f;
}
}
[[maybe_unused]]
void testPalette_0()
{
const uint32_t numColors {256 * 256 * 256};
const float saturation {1.0f};
const float brightness {1.0f};
palette::Palette p {numColors, saturation, brightness};
std::unordered_set<sg::rgb::RGB_t> colorSet(numColors);
for (const rgb::RGB& RGBColor : p())
{
// insert unique color elements (no copies)
colorSet.insert(RGBColor);
}
// create the palette
pixels_t colorV(colorSet.begin(), colorSet.end());
std::cout << "\nnumColors: " << numColors;
std::cout << "\npalette p size before replacement: " << p.size();
std::cout << "\ncolorSet size: " << colorSet.size();
std::cout << "\ncolorV size: " << colorV.size();
// replace the palette
p.setPalette(colorV);
std::cout << "\npalette p size after palette replacement: " << p.size();
std::cout << "\n";
p.makePaletteImage("../palettes/generated/tp0/");
p.saveRGBHexPalette("../palettes/generated/tp0/");
} // testPalette_0
[[maybe_unused]]
void testPalette_1()
{
auto pl = [] (const palette::Palette& p,
palette::Palette& q,
const uint32_t numColors)
{
auto i {0};
auto counter {0};
rgb::RGB previousRGBColor {};
for (const rgb::RGB& RGBColor : p())
{
if (RGBColor != previousRGBColor) {
std::cout << i << "/" << numColors << ": " << RGBColor << "\n";
q.addRGBColor(RGBColor);
previousRGBColor = RGBColor;
++counter;
}
++i;
}
std::cout << "\nnumColors: " << numColors;
std::cout << "\ncounter: " << counter;
std::cout << "\n";
};
const uint32_t numColors {256 * 256 * 256};
const float saturation {0.9f};
const float brightness {0.9f};
const palette::Palette p {numColors, saturation, brightness};
palette::Palette q {};
pl(p, q, numColors);
std::cout << "palette p size: " << p.size() << std::endl;
std::cout << "palette q size: " << q.size() << std::endl;
// palette image saved in a png file by default
q.makePaletteImage("../palettes/generated/tp1/");
q.saveRGBHexPalette("../palettes/generated/tp1/");
// grayscale palette
palette::Palette grayScale {};
grayScale.setGrayScalePalette();
// palette image saved in a png file by default
grayScale.makePaletteImage("../palettes/generated/tp1/");
} // testPalette_1
[[maybe_unused]]
void testPalette_2()
{
auto pl = [] (const palette::Palette& p, const uint32_t numColors)
{
auto i {0};
for (auto &&item : p())
{
std::cout << ++i << "/" << numColors << ": " << item << "\n";
}
std::cout << "\n\n";
};
const std::vector<uint32_t> numColors {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4196};
for (auto&& nc : numColors)
{
palette::Palette p {nc};
// palette image saved in a png file by default
p.makePaletteImage("../palettes/generated/tp2/");
p.saveRGBHexPalette("../palettes/generated/tp2/");
pl(p, nc);
}
} // testPalette_2
[[maybe_unused]]
void testPalette_3()
{
palette::Palette p40 {40};
palette::Palette p1280 {1280};
palette::Palette p2560 {2560};
p1280.savePalettes("../palettes/generated/tp3/",
"../palettes/generated/tp3/",
"../palettes/generated/tp3/");
p2560.saveRGBHexPalette("../palettes/generated/tp3/");
p2560.saveRGBPalette("../palettes/generated/tp3/");
p2560.saveHSBPalette("../palettes/generated/tp3/");
p40.savePalettes("../palettes/generated/tp3/",
"../palettes/generated/tp3/",
"../palettes/generated/tp3/");
p40.shufflePalette().savePalettes("../palettes/generated/tp3/p40-shuffled-",
"../palettes/generated/tp3/p40-shuffled-",
"../palettes/generated/tp3/p40-shuffled-");
} // testPalette_3
[[maybe_unused]]
void testPalette_4()
{
const std::vector<uint32_t> numColors {5, 10, 25, 50, 100, 500, 1000, 2000};
for (auto &&nc : numColors)
{
palette::Palette p {nc};
// palette image saved in a png file by default
p.makePaletteImage("../palettes/generated/tp4/");
// p.makePaletteImage<sg::ppm>("../palettes/generated/");
// p.makePaletteImage<sg::bmp>("../palettes/generated/");
// p.makePaletteImage<sg::png>("../palettes/generated/");
p.shufflePalette().makePaletteImage<sg::ppm>("../palettes/generated/tp4/p-shuffled-");
}
} // testPalette_4
[[maybe_unused]]
void testPalette_5()
{
palette::Palette p {"../palettes/0330-stage-1.2-palette.txt"};
p.sortPalette();
p.savePalettes("../palettes/generated/tp5/0330-stage-1.2-",
"../palettes/generated/tp5/0330-stage-1.2-",
"../palettes/generated/tp5/0330-stage-1.2-");
// palette image saved in a png file by default
p.makePaletteImage("../palettes/generated/tp5/0330-stage-1.2-");
// p.makePaletteImage<sg::ppm>("../palettes/generated/tp5/");
// p.makePaletteImage<sg::bmp>("../palettes/generated/tp5/");
// p.makePaletteImage<sg::png>("../palettes/generated/tp5/");
p.shufflePalette();
p.saveRGBHexPalette("../palettes/generated/tp5/0330-stage-1.2-shuffled-");
// palette image saved in a png file
p.makePaletteImage<sg::png>("../palettes/generated/tp5/0330-stage-1.2-shuffled-");
} // testPalette_5
[[maybe_unused]]
void testPalette_6()
{
palette::Palette p {"../palettes/c20-sorted.txt"};
p.saveRGBHexPalette("../palettes/generated/tp6/c20-sorted-");
// palette image saved in a png file
p.makePaletteImage<sg::png>("../palettes/generated/tp6/c20-sorted-");
p.shufflePalette();
p.saveRGBHexPalette("../palettes/generated/tp6/c20-shuffled-");
// palette image saved in a png file
p.makePaletteImage<sg::png>("../palettes/generated/tp6/c20-shuffled-");
} // testPalette_6
[[maybe_unused]]
void testPalette_7()
{
palette::Palette p {"../palettes/c20-sorted-2.txt"};
p.saveRGBHexPalette("../palettes/generated/tp7/c20-sorted-2-");
// palette image saved in a png file
p.makePaletteImage<sg::png>("../palettes/generated/tp7/c20-sorted-2-");
p.shufflePalette();
p.saveRGBHexPalette("../palettes/generated/tp7/c20-shuffled-2-");
// palette image saved in a png file
p.makePaletteImage<sg::png>("../palettes/generated/tp7/c20-shuffled-2-");
} // testPalette_7
[[maybe_unused]]
void testPalette_8()
{
uint32_t numColors {256};
float saturation {0.925f};
float brightness {0.935f};
palette::Palette p {numColors, saturation, brightness};
p.saveRGBHexPalette("../palettes/generated/tp8/");
p.saveRGBPalette("../palettes/generated/tp8/");
p.saveHSBPalette("../palettes/generated/tp8/");
// palette image saved in a png file by default
p.makePaletteImage("../palettes/generated/tp8/");
p.shufflePalette().savePalettes("../palettes/generated/tp8/p256-shuffled-",
"../palettes/generated/tp8/p256-shuffled-",
"../palettes/generated/tp8/p256-shuffled-");
// palette image saved in a png file
p.makePaletteImage<sg::png>("../palettes/generated/tp8/p256-shuffled-");
} // testPalette_8
} // namespace sg::PaletteTest