# HG changeset patch # User Matti Hamalainen # Date 1588027231 -10800 # Node ID 2d60e112255ecddb6b539bc44aeec3086c899bc6 # Parent 7151597d8ec6f3384ff913772bec540fcbcf6de6 Add support for converting palette to another palette format, or to a supported image format. diff -r 7151597d8ec6 -r 2d60e112255e tools/gfxconv.c --- a/tools/gfxconv.c Tue Apr 28 01:39:29 2020 +0300 +++ b/tools/gfxconv.c Tue Apr 28 01:40:31 2020 +0300 @@ -2679,10 +2679,46 @@ dmf_close(fp); - if (res != DMERR_OK || optPaletteData == NULL) + if (res != DMERR_OK) + { + dmErrorMsg("Palette could not be read.\n"); goto exit; - - res = dmWritePalette(optOutFilename, optPaletteData, &dmPaletteFormatList[optOutFormat]); + } + } + + if (optPaletteData == NULL) + goto exit; + + switch (optOutType) + { + case FFMT_PALETTE: + res = dmWritePalette(optOutFilename, optPaletteData, &dmPaletteFormatList[optOutFormat]); + break; + + case FFMT_IMAGE: + // Allocate image + if ((inImage = dmImageAlloc(16, 16, DM_PIXFMT_PALETTE, + dmGetNPlanesFromNColors(optPaletteData->ncolors))) == NULL) + { + res = dmError(DMERR_MALLOC, + "Could not allocate memory for image.\n"); + goto exit; + } + + if ((res = dmPaletteCopy(&inImage->pal, optPaletteData)) != DMERR_OK) + { + dmErrorMsg("Could not allocate image palette: %s\n", + dmErrorStr(res)); + goto exit; + } + + res = dmWriteImage(optOutFilename, inImage, &optSpec, + &dmImageFormatList[optOutFormat]); + break; + + default: + dmErrorMsg("Unsupported output format for palette conversion.\n"); + break; } break;