comparison tools/gfxconv.c @ 2123:47ddbedf5b56

Add initial support to 64vw and gfxconv for viewing and converting character map / mode (PETSCII and custom charset stuff etc. basically.)
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 May 2019 06:01:32 +0300
parents 88d37ec1b4d6
children a17b37872d8e
comparison
equal deleted inserted replaced
2122:59bde9a7220d 2123:47ddbedf5b56
132 optUsePalette = FALSE; 132 optUsePalette = FALSE;
133 int optNRemapTable = 0, 133 int optNRemapTable = 0,
134 optScaleMode = SCALE_AUTO; 134 optScaleMode = SCALE_AUTO;
135 DMMapValue optRemapTable[DM_MAX_COLORS]; 135 DMMapValue optRemapTable[DM_MAX_COLORS];
136 int optColorMap[C64_NCOLORS]; 136 int optColorMap[C64_NCOLORS];
137 char *optCharROMFilename = NULL;
138
137 139
138 DMImageConvSpec optSpec = 140 DMImageConvSpec optSpec =
139 { 141 {
140 .scaleX = 1, 142 .scaleX = 1,
141 .scaleY = 1, 143 .scaleY = 1,
164 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, 166 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ },
165 { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ }, 167 { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ },
166 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE }, 168 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE },
167 { 20, 'C', "compress", "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ }, 169 { 20, 'C', "compress", "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ },
168 { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ }, 170 { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ },
171 { 21, 'G', "char-rom", "Set character ROM file to be used.", OPT_ARGREQ },
169 }; 172 };
170 173
171 static const int optListN = sizeof(optList) / sizeof(optList[0]); 174 static const int optListN = sizeof(optList) / sizeof(optList[0]);
172 175
173 176
948 return FALSE; 951 return FALSE;
949 } 952 }
950 optSpec.compression = tmpUInt; 953 optSpec.compression = tmpUInt;
951 break; 954 break;
952 955
956 case 21:
957 optCharROMFilename = optArg;
958 break;
959
953 default: 960 default:
954 dmErrorMsg("Unknown option '%s'.\n", currArg); 961 dmErrorMsg("Unknown option '%s'.\n", currArg);
955 return FALSE; 962 return FALSE;
956 } 963 }
957 964
1924 1931
1925 if (!dmArgsProcess(argc, argv, optList, optListN, 1932 if (!dmArgsProcess(argc, argv, optList, optListN,
1926 argHandleOpt, argHandleFile, OPTH_BAILOUT)) 1933 argHandleOpt, argHandleFile, OPTH_BAILOUT))
1927 exit(1); 1934 exit(1);
1928 1935
1936 // Check character ROM filename
1937 if (optCharROMFilename == NULL)
1938 optCharROMFilename = DM_DEF_CHARGEN;
1939
1929 // Determine input format, if not specified 1940 // Determine input format, if not specified
1930 if (optInType == FFMT_AUTO && optInFilename != NULL) 1941 if (optInType == FFMT_AUTO && optInFilename != NULL)
1931 { 1942 {
1932 char *dext = strrchr(optInFilename, '.'); 1943 char *dext = strrchr(optInFilename, '.');
1933 if (dext) 1944 if (dext)
2125 switch (optOutType) 2136 switch (optOutType)
2126 { 2137 {
2127 case FFMT_IMAGE: 2138 case FFMT_IMAGE:
2128 case FFMT_CHAR: 2139 case FFMT_CHAR:
2129 case FFMT_SPRITE: 2140 case FFMT_SPRITE:
2141 // Set character data if required
2142 if ((inC64Fmt->format->type & D64_FMT_CHAR) &&
2143 inC64Image->charData->data == NULL)
2144 {
2145 // Attempt to read character ROM
2146 dmMsg(1, "Using character ROM file '%s'.\n",
2147 optCharROMFilename);
2148
2149 if ((res = dmReadDataFile(NULL, optCharROMFilename,
2150 &inC64Image->charData->data,
2151 &inC64Image->charData->size)) != DMERR_OK)
2152 {
2153 dmErrorMsg("Could not read character ROM from '%s'.\n",
2154 optCharROMFilename);
2155 goto error;
2156 }
2157 }
2158
2159 // Convert the image
2130 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64); 2160 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64);
2131 2161
2132 if (res != DMERR_OK || outImage == NULL) 2162 if (res != DMERR_OK || outImage == NULL)
2133 { 2163 {
2134 dmErrorMsg("Error in bitmap to image conversion.\n"); 2164 dmErrorMsg("Error in bitmap to image conversion.\n");