Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 1867:15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 24 Jun 2018 17:35:02 +0300 |
parents | 734234e7ca95 |
children | 1067df067f28 |
comparison
equal
deleted
inserted
replaced
1866:734234e7ca95 | 1867:15cbf17a8ea6 |
---|---|
87 optOutFormat = FFMT_ASCII, | 87 optOutFormat = FFMT_ASCII, |
88 optInSubFormat = -1, | 88 optInSubFormat = -1, |
89 optOutSubFormat = -1, | 89 optOutSubFormat = -1, |
90 optItemCount = -1, | 90 optItemCount = -1, |
91 optPlanedWidth = 1, | 91 optPlanedWidth = 1, |
92 optForcedFormat = -1; | 92 optForcedInSubFormat = -1; |
93 unsigned int optInSkip = 0; | 93 unsigned int optInSkip = 0; |
94 | 94 |
95 int optCropMode = CROP_NONE, | 95 int optCropMode = CROP_NONE, |
96 optCropX0, optCropY0, | 96 optCropX0, optCropY0, |
97 optCropW, optCropH; | 97 optCropW, optCropH; |
120 { 0, '?', "help", "Show this help", OPT_NONE }, | 120 { 0, '?', "help", "Show this help", OPT_NONE }, |
121 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE }, | 121 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE }, |
122 { 3, 'o', "output", "Output filename", OPT_ARGREQ }, | 122 { 3, 'o', "output", "Output filename", OPT_ARGREQ }, |
123 { 1, 'i', "informat", "Set input format (spr[:mc:sc], chr[:mc|sc] or any supported image or C64 bitmap format)", OPT_ARGREQ }, | 123 { 1, 'i', "informat", "Set input format (spr[:mc:sc], chr[:mc|sc] or any supported image or C64 bitmap format)", OPT_ARGREQ }, |
124 { 4, 's', "skip", "Skip N bytes in input from start", OPT_ARGREQ }, | 124 { 4, 's', "skip", "Skip N bytes in input from start", OPT_ARGREQ }, |
125 { 5, 'f', "format", "Output format (see --formats)", OPT_ARGREQ }, | 125 { 5, 'f', "format", "Output format (see --formats and --informat/-i for spr/chr formats)", OPT_ARGREQ }, |
126 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE }, | 126 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE }, |
127 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE }, | 127 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE }, |
128 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ }, | 128 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ }, |
129 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, | 129 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, |
130 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, | 130 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, |
495 fclose(fp); | 495 fclose(fp); |
496 return res; | 496 return res; |
497 } | 497 } |
498 | 498 |
499 | 499 |
500 BOOL dmParseFormatOption(const char *msg1, const char *msg2, char *optArg, int *format, int *subFormat) | |
501 { | |
502 char *flags = strchr(optArg, ':'); | |
503 if (flags != NULL) | |
504 *flags++ = 0; | |
505 | |
506 if (!dmGetFormatByExt(optArg, format, subFormat) && | |
507 !dmGetC64FormatByExt(optArg, format, subFormat)) | |
508 { | |
509 dmErrorMsg("Invalid %s format '%s', see -F / --formats for format list.\n", | |
510 msg1, optArg); | |
511 return FALSE; | |
512 } | |
513 | |
514 if (flags != NULL) | |
515 { | |
516 switch (*format) | |
517 { | |
518 case FFMT_SPRITE: | |
519 case FFMT_CHAR: | |
520 if (strcasecmp(flags, "mc") == 0) | |
521 optInMulticolor = TRUE; | |
522 else | |
523 if (strcasecmp(flags, "sc") == 0) | |
524 optInMulticolor = FALSE; | |
525 else | |
526 { | |
527 dmErrorMsg("Invalid %s format flags for sprite/char '%s', should be 'mc' or 'sc'.\n", | |
528 msg1, flags); | |
529 return FALSE; | |
530 } | |
531 break; | |
532 | |
533 default: | |
534 dmErrorMsg("%s format '%s' does not support any flags ('%s').\n", | |
535 msg2, optArg, flags); | |
536 return FALSE; | |
537 } | |
538 } | |
539 | |
540 return TRUE; | |
541 } | |
542 | |
543 | |
500 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | 544 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
501 { | 545 { |
502 switch (optN) | 546 switch (optN) |
503 { | 547 { |
504 case 0: | 548 case 0: |
514 case 15: | 558 case 15: |
515 dmVerbosity++; | 559 dmVerbosity++; |
516 break; | 560 break; |
517 | 561 |
518 case 1: | 562 case 1: |
519 { | 563 if (!dmParseFormatOption("input", "Input", optArg, &optInFormat, &optForcedInSubFormat)) |
520 char *flags = strchr(optArg, ':'); | 564 return FALSE; |
521 if (flags != NULL) | |
522 *flags++ = 0; | |
523 | |
524 if (!dmGetFormatByExt(optArg, &optInFormat, &optInSubFormat) && | |
525 !dmGetC64FormatByExt(optArg, &optInFormat, &optInSubFormat)) | |
526 { | |
527 dmErrorMsg("Invalid input format '%s', see -F / --formats for format list.\n", optArg); | |
528 return FALSE; | |
529 } | |
530 | |
531 if (flags != NULL) | |
532 { | |
533 switch (optInFormat) | |
534 { | |
535 case FFMT_SPRITE: | |
536 case FFMT_CHAR: | |
537 if (strcasecmp(flags, "mc") == 0) | |
538 optInMulticolor = TRUE; | |
539 else | |
540 if (strcasecmp(flags, "sc") == 0) | |
541 optInMulticolor = FALSE; | |
542 else | |
543 { | |
544 dmErrorMsg("Invalid input format flags for sprite/char '%s', should be 'mc' or 'sc'.\n", | |
545 flags); | |
546 return FALSE; | |
547 } | |
548 break; | |
549 | |
550 default: | |
551 dmErrorMsg("Input format '%s' does not support any flags ('%s').\n", | |
552 optArg, flags); | |
553 return FALSE; | |
554 } | |
555 } | |
556 } | |
557 break; | 565 break; |
558 | 566 |
559 case 3: | 567 case 3: |
560 optOutFilename = optArg; | 568 optOutFilename = optArg; |
561 break; | 569 break; |
567 return FALSE; | 575 return FALSE; |
568 } | 576 } |
569 break; | 577 break; |
570 | 578 |
571 case 5: | 579 case 5: |
572 if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) && | 580 if (!dmParseFormatOption("output", "Output", optArg, &optOutFormat, &optOutSubFormat)) |
573 !dmGetC64FormatByExt(optArg, &optOutFormat, &optOutSubFormat)) | |
574 { | |
575 dmErrorMsg("Invalid output format '%s'.\n", optArg); | |
576 return FALSE; | 581 return FALSE; |
577 } | |
578 break; | 582 break; |
579 | 583 |
580 case 6: | 584 case 6: |
581 { | 585 { |
582 int index, ncolors; | 586 int index, ncolors; |
1757 // Probe for format | 1761 // Probe for format |
1758 const DMC64ImageFormat *forced = NULL; | 1762 const DMC64ImageFormat *forced = NULL; |
1759 DMGrowBuf tbuf; | 1763 DMGrowBuf tbuf; |
1760 int res; | 1764 int res; |
1761 | 1765 |
1762 if (optForcedFormat >= 0) | 1766 if (optForcedInSubFormat >= 0) |
1763 { | 1767 { |
1764 forced = &dmC64ImageFormats[optForcedFormat]; | 1768 forced = &dmC64ImageFormats[optForcedInSubFormat]; |
1765 dmMsg(0, "Forced %s format image, type %d, %s\n", | 1769 dmMsg(0, "Forced %s format image, type %d, %s\n", |
1766 forced->name, forced->format->type, forced->fext); | 1770 forced->name, forced->format->type, forced->fext); |
1767 } | 1771 } |
1768 | 1772 |
1769 res = dmC64DecodeBMP(&inC64Image, | 1773 res = dmC64DecodeBMP(&inC64Image, |