comparison tools/gfxconv.c @ 2408:60e119262c67

Option index re-ordering cleanup work.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 13 Jan 2020 21:21:25 +0200
parents b7cd5dd0b82e
children bc05bcfc4598
comparison
equal deleted inserted replaced
2407:c5a32812dd97 2408:60e119262c67
157 DMC64ImageConvSpec optC64Spec; 157 DMC64ImageConvSpec optC64Spec;
158 158
159 159
160 static const DMOptArg optList[] = 160 static const DMOptArg optList[] =
161 { 161 {
162 { 0, '?', "help", "Show this help", OPT_NONE }, 162 { 0, '?', "help" , "Show this help", OPT_NONE },
163 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE }, 163 { 2, 'v', "verbose" , "Be more verbose", OPT_NONE },
164 { 3, 'o', "output", "Output filename", OPT_ARGREQ }, 164
165 { 4, 's', "skip", "Skip N bytes in input from start (negative value will be offset from input end)", OPT_ARGREQ }, 165 { 10, 'o', "output" , "Output filename", OPT_ARGREQ },
166 { 1, 'i', "informat", "Set input format (see --formats)", OPT_ARGREQ }, 166 { 12, 's', "skip" , "Skip N bytes in input from start (negative value will be offset from input end)", OPT_ARGREQ },
167 { 5, 'f', "format", "Set output format (see --formats)", OPT_ARGREQ }, 167 { 14, 'i', "informat" , "Set input format (see --formats)", OPT_ARGREQ },
168 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE }, 168 { 16, 'f', "format" , "Set output format (see --formats)", OPT_ARGREQ },
169 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE }, 169 { 18, 'F', "formats" , "List supported input/output formats", OPT_NONE },
170 { 6, 'm', "colormap", "Set color index mapping (see below for information)", OPT_ARGREQ }, 170 { 20, 'q', "sequential" , "Output sequential files (image output only)", OPT_NONE },
171 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, 171 { 22, 'm', "colormap" , "Set color index mapping (see below for information)", OPT_ARGREQ },
172 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, 172 { 24, 'n', "numitems" , "How many 'items' to output (default: all)", OPT_ARGREQ },
173 { 9, 'S', "scale", "Scale output image by specified value(s) (see below)", OPT_ARGREQ }, 173 { 26, 'w', "width" , "Item width (number of items per row, min 1)", OPT_ARGREQ },
174 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE }, 174 { 28, 'S', "scale" , "Scale output image by specified value(s) (see below)", OPT_ARGREQ },
175 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, 175 { 30, 'P', "paletted" , "Use indexed/paletted output IF possible.", OPT_NONE },
176 { 18, 'B', "bpp", "Bits per plane (some output formats)", OPT_ARGREQ }, 176 { 32, 'N', "nplanes" , "# of bitplanes (some output formats)", OPT_ARGREQ },
177 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE }, 177 { 34, 'B', "bpp" , "Bits per plane (some output formats)", OPT_ARGREQ },
178 { 20, 'C', "compress", "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ }, 178 { 36, 'I', "interleave" , "Interleaved/planar output (some output formats)", OPT_NONE },
179 { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ }, 179 { 38, 'C', "compress" , "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ },
180 { 21, 0, "char-rom", "Set character ROM file to be used.", OPT_ARGREQ }, 180 { 40, 'R', "remap" , "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ },
181 { 22, 'p', "palette" , "Set C64 palette to be used (see list with -p help).", OPT_ARGREQ }, 181 { 42, 0, "char-rom" , "Set character ROM file to be used.", OPT_ARGREQ },
182 { 44, 'p', "palette" , "Set C64 palette to be used (see list with -p help).", OPT_ARGREQ },
182 }; 183 };
183 184
184 static const int optListN = sizeof(optList) / sizeof(optList[0]); 185 static const int optListN = sizeof(optList) / sizeof(optList[0]);
185 186
186 187
679 case 0: 680 case 0:
680 argShowHelp(); 681 argShowHelp();
681 exit(0); 682 exit(0);
682 break; 683 break;
683 684
684 case 17: 685 case 2:
685 argShowFormats();
686 exit(0);
687 break;
688
689 case 15:
690 dmVerbosity++; 686 dmVerbosity++;
691 break; 687 break;
692 688
693 case 1: 689 case 10:
690 optOutFilename = optArg;
691 break;
692
693 case 12:
694 if (!dmGetIntVal(optArg, &optInSkip, &optInSkipNeg))
695 {
696 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg);
697 return FALSE;
698 }
699 break;
700
701 case 14:
694 { 702 {
695 DMConvFormat fmt; 703 DMConvFormat fmt;
696 704
697 if (!dmParseFormatOption("input", "Input", optArg, &optInType, &optForcedInSubFormat)) 705 if (!dmParseFormatOption("input", "Input", optArg, &optInType, &optForcedInSubFormat))
698 return FALSE; 706 return FALSE;
705 return FALSE; 713 return FALSE;
706 } 714 }
707 } 715 }
708 break; 716 break;
709 717
710 case 3: 718 case 16:
711 optOutFilename = optArg;
712 break;
713
714 case 4:
715 if (!dmGetIntVal(optArg, &optInSkip, &optInSkipNeg))
716 {
717 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg);
718 return FALSE;
719 }
720 break;
721
722 case 5:
723 { 719 {
724 DMConvFormat fmt; 720 DMConvFormat fmt;
725 721
726 if (!dmParseFormatOption("output", "Output", optArg, &optOutType, &optOutFormat)) 722 if (!dmParseFormatOption("output", "Output", optArg, &optOutType, &optOutFormat))
727 return FALSE; 723 return FALSE;
734 return FALSE; 730 return FALSE;
735 } 731 }
736 } 732 }
737 break; 733 break;
738 734
739 case 6: 735 case 18:
740 { 736 argShowFormats();
741 int index, ncolors; 737 exit(0);
738 break;
739
740 case 20:
741 optSequential = TRUE;
742 break;
743
744 case 22:
745 {
746 int ncolors;
742 if (!dmParseMapOptionString(optArg, optColorMap, 747 if (!dmParseMapOptionString(optArg, optColorMap,
743 &ncolors, D64_NCOLORS, FALSE, "color index option")) 748 &ncolors, D64_NCOLORS, FALSE, "color index option"))
744 return FALSE; 749 return FALSE;
745 750
746 dmMsg(1, "Set color index mapping: "); 751 dmMsg(1, "Set color index mapping: ");
747 for (index = 0; index < ncolors; index++) 752 for (int index = 0; index < ncolors; index++)
748 { 753 {
749 dmPrint(1, "[%d:%d]%s", 754 dmPrint(1, "[%d:%d]%s",
750 index, optColorMap[index], 755 index, optColorMap[index],
751 (index < ncolors) ? ", " : ""); 756 (index < ncolors) ? ", " : "");
752 } 757 }
753 dmPrint(1, "\n"); 758 dmPrint(1, "\n");
754 } 759 }
755 break; 760 break;
756 761
757 case 7: 762 case 24:
758 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || 763 if (!dmGetIntVal(optArg, &tmpUInt, NULL) ||
759 tmpUInt < 1) 764 tmpUInt < 1)
760 { 765 {
761 dmErrorMsg("Invalid count value argument '%s' [1 .. MAXINT]\n", 766 dmErrorMsg("Invalid count value argument '%s' [1 .. MAXINT]\n",
762 optArg); 767 optArg);
763 return FALSE; 768 return FALSE;
764 } 769 }
765 optItemCount = tmpUInt; 770 optItemCount = tmpUInt;
766 break; 771 break;
767 772
768 case 8: 773 case 26:
769 optSequential = TRUE; 774 if (!dmGetIntVal(optArg, &tmpUInt, NULL) ||
770 break; 775 tmpUInt < 1 || tmpUInt > 512)
771 776 {
772 case 9: 777 dmErrorMsg("Invalid planed width value '%s' [1 .. 512]\n",
778 optArg);
779 return FALSE;
780 }
781 optPlanedWidth = tmpUInt;
782 break;
783
784 case 28:
773 { 785 {
774 BOOL error = FALSE; 786 BOOL error = FALSE;
775 unsigned int tmpUInt2; 787 unsigned int tmpUInt2;
776 char *tmpStr = dm_strdup(optArg), 788 char *tmpStr = dm_strdup(optArg),
777 *tmpOpt = tmpStr, sep; 789 *tmpOpt = tmpStr, sep;
834 return FALSE; 846 return FALSE;
835 } 847 }
836 } 848 }
837 break; 849 break;
838 850
839 case 11: 851 case 30:
840 if (!dmGetIntVal(optArg, &tmpUInt, NULL) ||
841 tmpUInt < 1 || tmpUInt > 512)
842 {
843 dmErrorMsg("Invalid planed width value '%s' [1 .. 512]\n",
844 optArg);
845 return FALSE;
846 }
847 optPlanedWidth = tmpUInt;
848 break;
849
850 case 12:
851 optUsePalette = TRUE; 852 optUsePalette = TRUE;
852 break; 853 break;
853 854
854 case 13: 855 case 32:
855 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || 856 if (!dmGetIntVal(optArg, &tmpUInt, NULL) ||
856 tmpUInt < 1 || tmpUInt > 8) 857 tmpUInt < 1 || tmpUInt > 8)
857 { 858 {
858 dmErrorMsg("Invalid number of bitplanes value '%s' [1 .. 8]\n", 859 dmErrorMsg("Invalid number of bitplanes value '%s' [1 .. 8]\n",
859 optArg); 860 optArg);
860 return FALSE; 861 return FALSE;
861 } 862 }
862 optSpec.nplanes = tmpUInt; 863 optSpec.nplanes = tmpUInt;
863 break; 864 break;
864 865
865 case 18: 866 case 34:
866 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || 867 if (!dmGetIntVal(optArg, &tmpUInt, NULL) ||
867 tmpUInt < 1 || tmpUInt > 32) 868 tmpUInt < 1 || tmpUInt > 32)
868 { 869 {
869 dmErrorMsg("Invalid number of bits per plane value '%s' [1 .. 32]\n", 870 dmErrorMsg("Invalid number of bits per plane value '%s' [1 .. 32]\n",
870 optArg); 871 optArg);
871 return FALSE; 872 return FALSE;
872 } 873 }
873 optSpec.bpp = tmpUInt; 874 optSpec.bpp = tmpUInt;
874 break; 875 break;
875 876
876 case 14: 877 case 36:
877 optSpec.planar = TRUE; 878 optSpec.planar = TRUE;
878 break; 879 break;
879 880
880 case 16: 881 case 38:
881 if ((tmpStr = dm_strrcasecmp(optArg, "+remove")) != NULL) 882 if (!dmGetIntVal(optArg, &tmpUInt, NULL) ||
882 { 883 tmpUInt > FCMP_BEST)
883 optRemapRemove = TRUE; 884 {
884 *tmpStr = 0; 885 dmErrorMsg("Invalid compression setting '%s' [%d .. %d]\n",
885 } 886 optArg, FCMP_NONE, FCMP_BEST);
886 887 return FALSE;
887 if (optArg[0] == '@') 888 }
888 { 889 optSpec.compression = tmpUInt;
889 if (optArg[1] != 0) 890 break;
890 { 891
891 int res; 892 case 39:
892 if ((res = dmParseColorRemapFile(optArg + 1,
893 optRemapTable, &optNRemapTable, DM_MAX_COLORS)) != DMERR_OK)
894 return FALSE;
895 }
896 else
897 {
898 dmErrorMsg("No remap filename given.\n");
899 return FALSE;
900 }
901 }
902 else
903 {
904 if (!dmParseMapOptionString(optArg, optRemapTable,
905 &optNRemapTable, DM_MAX_COLORS, TRUE, "color remap option"))
906 return FALSE;
907 }
908
909 optRemapColors = TRUE;
910 break;
911
912 case 19:
913 { 893 {
914 int tx0, ty0, tx1, ty1; 894 int tx0, ty0, tx1, ty1;
915 if (strcasecmp(optArg, "auto") == 0) 895 if (strcasecmp(optArg, "auto") == 0)
916 { 896 {
917 optCropMode = CROP_AUTO; 897 optCropMode = CROP_AUTO;
940 return FALSE; 920 return FALSE;
941 } 921 }
942 } 922 }
943 break; 923 break;
944 924
945 case 20: 925 case 40:
946 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || 926 if ((tmpStr = dm_strrcasecmp(optArg, "+remove")) != NULL)
947 tmpUInt > FCMP_BEST) 927 {
948 { 928 optRemapRemove = TRUE;
949 dmErrorMsg("Invalid compression setting '%s' [%d .. %d]\n", 929 *tmpStr = 0;
950 optArg, FCMP_NONE, FCMP_BEST); 930 }
951 return FALSE; 931
952 } 932 if (optArg[0] == '@')
953 optSpec.compression = tmpUInt; 933 {
954 break; 934 if (optArg[1] != 0)
955 935 {
956 case 21: 936 int res;
937 if ((res = dmParseColorRemapFile(optArg + 1,
938 optRemapTable, &optNRemapTable, DM_MAX_COLORS)) != DMERR_OK)
939 return FALSE;
940 }
941 else
942 {
943 dmErrorMsg("No remap filename given.\n");
944 return FALSE;
945 }
946 }
947 else
948 {
949 if (!dmParseMapOptionString(optArg, optRemapTable,
950 &optNRemapTable, DM_MAX_COLORS, TRUE, "color remap option"))
951 return FALSE;
952 }
953
954 optRemapColors = TRUE;
955 break;
956
957 case 42:
957 optCharROMFilename = optArg; 958 optCharROMFilename = optArg;
958 break; 959 break;
959 960
960 case 22: 961 case 44:
961 return argHandleC64PaletteOption(optArg, &optC64Palette, &optPaletteFile); 962 return argHandleC64PaletteOption(optArg, &optC64Palette, &optPaletteFile);
962 963
963 default: 964 default:
964 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg); 965 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg);
965 return FALSE; 966 return FALSE;