Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 2097:f43011ea9b9f
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Mar 2019 10:54:47 +0200 |
parents | 4276b8c0fef0 |
children | dac89484f143 |
comparison
equal
deleted
inserted
replaced
2096:6b2bac1e3445 | 2097:f43011ea9b9f |
---|---|
1892 DMConvFormat inFormat, outFormat; | 1892 DMConvFormat inFormat, outFormat; |
1893 DMC64Image *inC64Image = NULL, *outC64Image = NULL; | 1893 DMC64Image *inC64Image = NULL, *outC64Image = NULL; |
1894 DMImage *inImage = NULL, *outImage = NULL; | 1894 DMImage *inImage = NULL, *outImage = NULL; |
1895 Uint8 *dataBuf = NULL, *dataBufOrig = NULL; | 1895 Uint8 *dataBuf = NULL, *dataBufOrig = NULL; |
1896 size_t dataSize, dataSizeOrig, dataRealOffs; | 1896 size_t dataSize, dataSizeOrig, dataRealOffs; |
1897 int i, n; | 1897 int i, n, res; |
1898 | 1898 |
1899 // Default color mapping | 1899 // Default color mapping |
1900 for (i = 0; i < C64_NCOLORS; i++) | 1900 for (i = 0; i < C64_NCOLORS; i++) |
1901 optColorMap[i] = i; | 1901 optColorMap[i] = i; |
1902 | 1902 |
1956 optInFilename = "stdin"; | 1956 optInFilename = "stdin"; |
1957 } | 1957 } |
1958 else | 1958 else |
1959 if ((inFile = fopen(optInFilename, "rb")) == NULL) | 1959 if ((inFile = fopen(optInFilename, "rb")) == NULL) |
1960 { | 1960 { |
1961 int res = dmGetErrno(); | 1961 res = dmGetErrno(); |
1962 dmErrorMsg("Error opening input file '%s', %d: %s\n", | 1962 dmErrorMsg("Error opening input file '%s', %d: %s\n", |
1963 optInFilename, res, dmErrorStr(res)); | 1963 optInFilename, res, dmErrorStr(res)); |
1964 goto error; | 1964 goto error; |
1965 } | 1965 } |
1966 | 1966 |
1983 optOutType = FFMT_ASCII; | 1983 optOutType = FFMT_ASCII; |
1984 | 1984 |
1985 // Read the input .. | 1985 // Read the input .. |
1986 dmMsg(1, "Reading input from '%s'.\n", optInFilename); | 1986 dmMsg(1, "Reading input from '%s'.\n", optInFilename); |
1987 | 1987 |
1988 if (dmReadDataFile(inFile, NULL, &dataBufOrig, &dataSizeOrig) != 0) | 1988 if ((res = dmReadDataFile(inFile, NULL, &dataBufOrig, &dataSizeOrig)) != DMERR_OK) |
1989 { | |
1990 dmErrorMsg("Could not read input: %s.\n", dmErrorStr(res)); | |
1989 goto error; | 1991 goto error; |
1992 } | |
1990 | 1993 |
1991 fclose(inFile); | 1994 fclose(inFile); |
1992 | 1995 |
1993 // Check and compute the input skip | 1996 // Check and compute the input skip |
1994 if (optInSkip > dataSizeOrig) | 1997 if (optInSkip > dataSizeOrig) |
2029 if (optInType == FFMT_AUTO || optInType == FFMT_BITMAP) | 2032 if (optInType == FFMT_AUTO || optInType == FFMT_BITMAP) |
2030 { | 2033 { |
2031 // Probe for format | 2034 // Probe for format |
2032 const DMC64ImageFormat *forced = NULL; | 2035 const DMC64ImageFormat *forced = NULL; |
2033 DMGrowBuf tbuf; | 2036 DMGrowBuf tbuf; |
2034 int res; | |
2035 | 2037 |
2036 if (optForcedInSubFormat >= 0) | 2038 if (optForcedInSubFormat >= 0) |
2037 { | 2039 { |
2038 forced = &dmC64ImageFormats[optForcedInSubFormat]; | 2040 forced = &dmC64ImageFormats[optForcedInSubFormat]; |
2039 dmMsg(0, "Forced '%s' format image, type %d, %s\n", | 2041 dmMsg(0, "Forced '%s' format image, type %d, %s\n", |
2115 case FFMT_CHAR: | 2117 case FFMT_CHAR: |
2116 dmDumpSpritesAndChars(dataBuf, dataSize, dataRealOffs); | 2118 dmDumpSpritesAndChars(dataBuf, dataSize, dataRealOffs); |
2117 break; | 2119 break; |
2118 | 2120 |
2119 case FFMT_BITMAP: | 2121 case FFMT_BITMAP: |
2120 { | 2122 if (optOutFilename == NULL) |
2121 int res = DMERR_OK; | 2123 { |
2122 | 2124 dmErrorMsg("Output filename not set, required for bitmap formats.\n"); |
2123 if (optOutFilename == NULL) | 2125 goto error; |
2124 { | 2126 } |
2125 dmErrorMsg("Output filename not set, required for bitmap formats.\n"); | 2127 |
2126 goto error; | 2128 switch (optOutType) |
2127 } | 2129 { |
2128 | 2130 case FFMT_IMAGE: |
2129 switch (optOutType) | 2131 case FFMT_CHAR: |
2130 { | 2132 case FFMT_SPRITE: |
2131 case FFMT_IMAGE: | 2133 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64); |
2132 case FFMT_CHAR: | 2134 |
2133 case FFMT_SPRITE: | 2135 if (res != DMERR_OK || outImage == NULL) |
2134 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64); | 2136 { |
2135 | 2137 dmErrorMsg("Error in bitmap to image conversion.\n"); |
2136 if (res != DMERR_OK || outImage == NULL) | 2138 goto error; |
2137 { | 2139 } |
2138 dmErrorMsg("Error in bitmap to image conversion.\n"); | 2140 |
2139 goto error; | 2141 switch (optOutType) |
2140 } | 2142 { |
2141 | 2143 case FFMT_IMAGE: |
2142 switch (optOutType) | 2144 res = dmWriteImage(optOutFilename, outImage, &optSpec, |
2143 { | 2145 &dmImageFormatList[optOutFormat], TRUE); |
2144 case FFMT_IMAGE: | 2146 break; |
2145 res = dmWriteImage(optOutFilename, outImage, &optSpec, | 2147 |
2146 &dmImageFormatList[optOutFormat], TRUE); | 2148 case FFMT_CHAR: |
2147 break; | 2149 case FFMT_SPRITE: |
2148 | 2150 res = dmWriteSpritesAndChars(optOutFilename, outImage, |
2149 case FFMT_CHAR: | 2151 optOutType, optInMulticolor); |
2150 case FFMT_SPRITE: | 2152 break; |
2151 res = dmWriteSpritesAndChars(optOutFilename, outImage, | 2153 } |
2152 optOutType, optInMulticolor); | 2154 break; |
2153 break; | 2155 |
2154 } | 2156 case FFMT_BITMAP: |
2155 break; | 2157 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, |
2156 | 2158 &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK) |
2157 case FFMT_BITMAP: | 2159 { |
2158 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, | 2160 dmErrorMsg("Error in bitmap format conversion.\n"); |
2159 &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK) | 2161 goto error; |
2160 { | 2162 } |
2161 dmErrorMsg("Error in bitmap format conversion.\n"); | 2163 if (dmVerbosity >= 2) |
2162 goto error; | 2164 { |
2163 } | 2165 dmPrint(0, "INPUT:\n"); dmC64ImageDump(stderr, inC64Image, inC64Fmt, " "); |
2164 if (dmVerbosity >= 2) | 2166 dmPrint(0, "OUTPUT:\n"); dmC64ImageDump(stderr, outC64Image, &dmC64ImageFormats[optOutFormat], " "); |
2165 { | 2167 } |
2166 dmPrint(0, "INPUT:\n"); dmC64ImageDump(stderr, inC64Image, inC64Fmt, " "); | 2168 res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); |
2167 dmPrint(0, "OUTPUT:\n"); dmC64ImageDump(stderr, outC64Image, &dmC64ImageFormats[optOutFormat], " "); | 2169 break; |
2168 } | 2170 |
2169 res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); | 2171 default: |
2170 break; | 2172 dmErrorMsg("Unsupported output format for bitmap conversion.\n"); |
2171 | 2173 break; |
2172 default: | |
2173 dmErrorMsg("Unsupported output format for bitmap conversion.\n"); | |
2174 break; | |
2175 } | |
2176 | |
2177 } | 2174 } |
2178 break; | 2175 break; |
2179 | 2176 |
2180 case FFMT_IMAGE: | 2177 case FFMT_IMAGE: |
2181 { | 2178 { |
2182 const DMImageFormat *ifmt = &dmImageFormatList[optInFormat]; | 2179 const DMImageFormat *ifmt = &dmImageFormatList[optInFormat]; |
2183 int res = DMERR_OK; | |
2184 DMResource *fp; | 2180 DMResource *fp; |
2185 | 2181 |
2186 if (optOutFilename == NULL) | 2182 if (optOutFilename == NULL) |
2187 { | 2183 { |
2188 dmErrorMsg("Output filename not set, required for image formats.\n"); | 2184 dmErrorMsg("Output filename not set, required for image formats.\n"); |