Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 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 | f3d9cdb0a295 |
children | 79e3f824a2d0 |
comparison
equal
deleted
inserted
replaced
2482:7151597d8ec6 | 2483:2d60e112255e |
---|---|
2677 else | 2677 else |
2678 dmErrorMsg("Unsupported input palette format.\n"); | 2678 dmErrorMsg("Unsupported input palette format.\n"); |
2679 | 2679 |
2680 dmf_close(fp); | 2680 dmf_close(fp); |
2681 | 2681 |
2682 if (res != DMERR_OK || optPaletteData == NULL) | 2682 if (res != DMERR_OK) |
2683 { | |
2684 dmErrorMsg("Palette could not be read.\n"); | |
2683 goto exit; | 2685 goto exit; |
2684 | 2686 } |
2685 res = dmWritePalette(optOutFilename, optPaletteData, &dmPaletteFormatList[optOutFormat]); | 2687 } |
2688 | |
2689 if (optPaletteData == NULL) | |
2690 goto exit; | |
2691 | |
2692 switch (optOutType) | |
2693 { | |
2694 case FFMT_PALETTE: | |
2695 res = dmWritePalette(optOutFilename, optPaletteData, &dmPaletteFormatList[optOutFormat]); | |
2696 break; | |
2697 | |
2698 case FFMT_IMAGE: | |
2699 // Allocate image | |
2700 if ((inImage = dmImageAlloc(16, 16, DM_PIXFMT_PALETTE, | |
2701 dmGetNPlanesFromNColors(optPaletteData->ncolors))) == NULL) | |
2702 { | |
2703 res = dmError(DMERR_MALLOC, | |
2704 "Could not allocate memory for image.\n"); | |
2705 goto exit; | |
2706 } | |
2707 | |
2708 if ((res = dmPaletteCopy(&inImage->pal, optPaletteData)) != DMERR_OK) | |
2709 { | |
2710 dmErrorMsg("Could not allocate image palette: %s\n", | |
2711 dmErrorStr(res)); | |
2712 goto exit; | |
2713 } | |
2714 | |
2715 res = dmWriteImage(optOutFilename, inImage, &optSpec, | |
2716 &dmImageFormatList[optOutFormat]); | |
2717 break; | |
2718 | |
2719 default: | |
2720 dmErrorMsg("Unsupported output format for palette conversion.\n"); | |
2721 break; | |
2686 } | 2722 } |
2687 break; | 2723 break; |
2688 | 2724 |
2689 case FFMT_BITMAP: | 2725 case FFMT_BITMAP: |
2690 if (optOutFilename == NULL) | 2726 if (optOutFilename == NULL) |