Fix parsing of GPL files

Can you tell this was *not* tested whatsoever?
This commit is contained in:
ISSOtm
2024-07-26 19:37:02 +02:00
committed by Sylvie
parent 1f8f28cac8
commit 3d1f5386c2
4 changed files with 49 additions and 6 deletions

View File

@@ -352,24 +352,30 @@ static void parseGPLFile(std::filebuf &file) {
} }
uint16_t nbColors = 0; uint16_t nbColors = 0;
uint16_t maxNbColors = options.nbColorsPerPal * options.nbPalettes; uint16_t const maxNbColors = options.nbColorsPerPal * options.nbPalettes;
for (;;) { for (;;) {
line.clear(); line.clear();
requireLine("GPL", file, line); if (!readLine(file, line)) {
if (!line.length()) {
break; break;
} }
if (line.starts_with("Name:") || line.starts_with("Columns:")) {
if (line.starts_with("#") || line.starts_with("Name:") || line.starts_with("Column:")) {
continue; continue;
} }
std::string::size_type n = 0; std::string::size_type n = 0;
skipWhitespace(line, n);
// Skip empty lines, or lines that contain just a comment.
if (line.length() == n || line[n] == '#') {
continue;
}
std::optional<Rgba> color = parseColor(line, n, nbColors + 1); std::optional<Rgba> color = parseColor(line, n, nbColors + 1);
if (!color) { if (!color) {
return; return;
} }
// Ignore anything following the three components
// (sometimes it's a comment, sometimes it's the color in CSS hex format, sometimes there's nothing...).
if (nbColors < maxNbColors) { if (nbColors < maxNbColors) {
if (nbColors % options.nbColorsPerPal == 0) { if (nbColors % options.nbColorsPerPal == 0) {
@@ -394,7 +400,7 @@ static void parseHEXFile(std::filebuf &file) {
// https://lospec.com/palette-list/tag/gbc // https://lospec.com/palette-list/tag/gbc
uint16_t nbColors = 0; uint16_t nbColors = 0;
uint16_t maxNbColors = options.nbColorsPerPal * options.nbPalettes; uint16_t const maxNbColors = options.nbColorsPerPal * options.nbPalettes;
for (;;) { for (;;) {
std::string line; std::string line;

1
test/gfx/full_gpl.flags Normal file
View File

@@ -0,0 +1 @@
-c gpl:full_gpl.gpl

36
test/gfx/full_gpl.gpl Normal file
View File

@@ -0,0 +1,36 @@
GIMP Palette
#Palette Name: AxulArt 32 color Palette
#Description: 32-color palette, intended to be similar to that used in arcade and Game Boy Advance games; You can see more of my art at: https://axulart.tumblr.com/ and https://axulart.itch.io/
#Colors: 32
0 0 0 000000
252 252 252 fcfcfc
196 199 238 c4c7ee
154 143 224 9a8fe0
99 93 150 635d96
41 47 101 292f65
27 29 52 1b1d34
255 227 174 ffe3ae
205 187 171 cdbbab
166 133 143 a6858f
207 93 139 cf5d8b
150 73 104 964968
255 180 130 ffb482
221 134 125 dd867d
178 105 111 b2696f
246 198 94 f6c65e
228 144 87 e49057
196 104 51 c46833
176 208 126 b0d07e
102 170 93 66aa5d
82 181 171 52b5ab
42 131 121 2a8379
28 86 89 1c5659
123 225 246 7be1f6
88 159 252 589ffc
80 105 228 5069e4
46 68 174 2e44ae
128 86 212 8056d4
90 59 150 5a3b96
255 186 225 ffbae1
230 135 197 e687c5
167 89 185 a759b9

BIN
test/gfx/full_gpl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 927 B