Mercurial > hg > dmlib
changeset 2483:2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 28 Apr 2020 01:40:31 +0300 |
parents | 7151597d8ec6 |
children | 79e3f824a2d0 |
files | tools/gfxconv.c |
diffstat | 1 files changed, 39 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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;