Mercurial > hg > dmlib
diff tools/gfxconv.c @ 2208:90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
lib64util for handling external palette file options and add support for
specifying one of the "internal" palettes or external (.act) palette file to
gfxconv and 64vw.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 05:01:12 +0300 |
parents | cbac4912992c |
children | f8bba7a82ec2 |
line wrap: on
line diff
--- a/tools/gfxconv.c Fri Jun 14 03:28:46 2019 +0300 +++ b/tools/gfxconv.c Fri Jun 14 05:01:12 2019 +0300 @@ -136,6 +136,8 @@ DMMapValue optRemapTable[DM_MAX_COLORS]; int optColorMap[D64_NCOLORS]; char *optCharROMFilename = NULL; +DMC64Palette *optC64Palette = NULL; +char *optC64PaletteFile = NULL; DMImageWriteSpec optSpec = @@ -149,6 +151,9 @@ .compression = FCMP_BEST, }; +DMC64ImageConvSpec optC64Spec; + + static const DMOptArg optList[] = { { 0, '?', "help", "Show this help", OPT_NONE }, @@ -170,6 +175,7 @@ { 20, 'C', "compress", "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ }, { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ }, { 21, 0, "char-rom", "Set character ROM file to be used.", OPT_ARGREQ }, + { 22, 'p', "palette" , "Set C64 palette to be used (see list with -p help).", OPT_ARGREQ }, }; static const int optListN = sizeof(optList) / sizeof(optList[0]); @@ -958,6 +964,9 @@ optCharROMFilename = optArg; break; + case 22: + return argHandleC64PaletteOption(optArg, &optC64Palette, &optC64PaletteFile); + default: dmErrorMsg("Unimplemented option argument '%s'.\n", currArg); return FALSE; @@ -1831,7 +1840,7 @@ outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight, DM_PIXFMT_PALETTE, -1); } - if ((err = dmC64SetImagePalette(outImage, NULL, FALSE)) != DMERR_OK) + if ((err = dmC64SetImagePalette(outImage, &optC64Spec, FALSE)) != DMERR_OK) { dmErrorMsg("Could not allocate C64 palette for output image: %d\n", err); goto error; @@ -1914,7 +1923,6 @@ int main(int argc, char *argv[]) { FILE *inFile = NULL; - DMC64ImageConvSpec imageSpecC64; const DMC64ImageFormat *inC64Fmt = NULL; DMConvFormat inFormat, outFormat; DMC64Image *inC64Image = NULL, *outC64Image = NULL; @@ -1928,7 +1936,7 @@ optColorMap[i] = i; // Initialize c64 image conversion spec - memset(&imageSpecC64, 0, sizeof(imageSpecC64)); + memset(&optC64Spec, 0, sizeof(optC64Spec)); // Initialize list of additional conversion formats if ((res = dmLib64GFXInit()) != DMERR_OK) @@ -2144,6 +2152,30 @@ } } + if (optC64PaletteFile != NULL) + { + if ((res = dmHandleExternalPalette(optC64PaletteFile, &optC64Spec.pal)) != DMERR_OK) + goto exit; + } + else + { + // No palette file specified, use internal palette + if (optC64Palette == NULL) + optC64Palette = &dmC64DefaultPalettes[0]; + + dmMsg(1, "Using internal palette '%s' (%s).\n", + optC64Palette->name, optC64Palette->desc); + + optC64Spec.cpal = optC64Palette; + + if ((res = dmC64PaletteFromC64Palette(&optC64Spec.pal, optC64Palette, FALSE)) != DMERR_OK) + { + dmErrorMsg("Could not setup palette: %s\n", + dmErrorStr(res)); + goto exit; + } + } + switch (optInType) { case FFMT_SPRITE: @@ -2186,7 +2218,7 @@ } // Convert the image - res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64); + res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &optC64Spec); if (res != DMERR_OK || outImage == NULL) { @@ -2275,7 +2307,7 @@ { DMC64Image *tmpC64Image = NULL; res = dmC64ConvertImage2BMP(&tmpC64Image, inImage, - &dmC64ImageFormats[optOutFormat], &imageSpecC64); + &dmC64ImageFormats[optOutFormat], &optC64Spec); if (res != DMERR_OK || tmpC64Image == NULL) {