1616
1717#include " extern/getopt.hpp"
1818#include " file.hpp"
19- #include " helpers.hpp" // assume
2019#include " platform.hpp"
2120#include " version.hpp"
2221
@@ -354,7 +353,6 @@ static char *parseArgv(int argc, char *argv[]) {
354353 for (int ch; (ch = musl_getopt_long_only (argc, argv, optstring, longopts, nullptr )) != -1 ;) {
355354 char *arg = musl_optarg; // Make a copy for scanning
356355 uint16_t number;
357- size_t size;
358356 switch (ch) {
359357 case ' A' :
360358 localOptions.autoAttrmap = true ;
@@ -367,41 +365,7 @@ static char *parseArgv(int argc, char *argv[]) {
367365 options.attrmap = musl_optarg;
368366 break ;
369367 case ' B' :
370- if (strcasecmp (musl_optarg, " transparent" ) == 0 ) {
371- options.bgColor = Rgba (0x00 , 0x00 , 0x00 , 0x00 );
372- break ;
373- }
374- if (musl_optarg[0 ] != ' #' ) {
375- error (" Background color specification must be `#rgb`, `#rrggbb`, or `transparent`" );
376- break ;
377- }
378- size = strspn (&musl_optarg[1 ], " 0123456789ABCDEFabcdef" );
379- switch (size) {
380- case 3 :
381- options.bgColor = Rgba (
382- singleToHex (musl_optarg[1 ]),
383- singleToHex (musl_optarg[2 ]),
384- singleToHex (musl_optarg[3 ]),
385- 0xFF
386- );
387- break ;
388- case 6 :
389- options.bgColor = Rgba (
390- toHex (musl_optarg[1 ], musl_optarg[2 ]),
391- toHex (musl_optarg[3 ], musl_optarg[4 ]),
392- toHex (musl_optarg[5 ], musl_optarg[6 ]),
393- 0xFF
394- );
395- break ;
396- default :
397- error (" Unknown background color specification \" %s\" " , musl_optarg);
398- }
399- if (musl_optarg[size + 1 ] != ' \0 ' ) {
400- error (
401- " Unexpected text \" %s\" after background color specification" ,
402- &musl_optarg[size + 1 ]
403- );
404- }
368+ parseBackgroundPalSpec (musl_optarg);
405369 break ;
406370 case ' b' :
407371 number = parseNumber (arg, " Bank 0 base tile ID" , 0 );
@@ -442,18 +406,18 @@ static char *parseArgv(int argc, char *argv[]) {
442406 options.useColorCurve = true ;
443407 break ;
444408 case ' c' :
409+ localOptions.externalPalSpec = nullptr ; // Allow overriding a previous pal spec
445410 if (musl_optarg[0 ] == ' #' ) {
446411 options.palSpecType = Options::EXPLICIT;
447412 parseInlinePalSpec (musl_optarg);
448413 } else if (strcasecmp (musl_optarg, " embedded" ) == 0 ) {
449414 // Use PLTE, error out if missing
450415 options.palSpecType = Options::EMBEDDED;
416+ } else if (strncasecmp (musl_optarg, " dmg=" , literal_strlen (" dmg=" )) == 0 ) {
417+ options.palSpecType = Options::DMG;
418+ parseDmgPalSpec (&musl_optarg[literal_strlen (" dmg=" )]);
451419 } else {
452420 options.palSpecType = Options::EXPLICIT;
453- // Can't parse the file yet, as "flat" color collections need to know the palette
454- // size to be split; thus, we defer that.
455- // If a following `-c` overrides a previous one, the `fmt` part of an overridden
456- // external palette spec will not be validated, but I guess that's okay.
457421 localOptions.externalPalSpec = musl_optarg;
458422 }
459423 break ;
@@ -877,6 +841,8 @@ int main(int argc, char *argv[]) {
877841 return " Explicit" ;
878842 case Options::EMBEDDED:
879843 return " Embedded" ;
844+ case Options::DMG:
845+ return " DMG" ;
880846 }
881847 return " ???" ;
882848 }());
0 commit comments