Mercurial > hg > dmlib
diff tools/gfxconv.c @ 2065:451980580189
Refactor how paletted/indexed formats are handled in libgfx.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 05 Dec 2018 13:33:03 +0200 |
parents | f11fad2dc3b5 |
children | 41df24d1dfb6 |
line wrap: on
line diff
--- a/tools/gfxconv.c Wed Dec 05 13:31:59 2018 +0200 +++ b/tools/gfxconv.c Wed Dec 05 13:33:03 2018 +0200 @@ -127,7 +127,8 @@ BOOL optInMulticolor = FALSE, optSequential = FALSE, optRemapColors = FALSE, - optRemapRemove = FALSE; + optRemapRemove = FALSE, + optUsePalette = FALSE; int optNRemapTable = 0, optScaleMode = SCALE_AUTO; DMMapValue optRemapTable[DM_MAX_COLORS]; @@ -140,7 +141,6 @@ .nplanes = 4, .bpp = 8, .planar = FALSE, - .paletted = FALSE, .format = 0, .compression = FCMP_BEST, }; @@ -816,7 +816,7 @@ break; case 12: - optSpec.paletted = TRUE; + optUsePalette = TRUE; break; case 13: @@ -1327,7 +1327,7 @@ int dmWriteIFFMasterRAWHeaderFile( const char *hdrFilename, const char *dataFilename, const char *prefix, const DMImage *img, - const DMImageConvSpec *spec, const int fmtid) + const DMImageConvSpec *spec) { DMResource *fp; int res; @@ -1339,7 +1339,7 @@ hdrFilename); } - res = dmWriteIFFMasterRAWHeader(fp, dataFilename, prefix, img, spec, fmtid); + res = dmWriteIFFMasterRAWHeader(fp, dataFilename, prefix, img, spec); dmf_close(fp); return res; @@ -1378,11 +1378,29 @@ allocated = TRUE; } + // Determine number of planes, if paletted + if (spec->format == DM_COLFMT_PALETTE) + { + spec->nplanes = 0; + for (int n = 8; n >= 0;) + { + if ((image->ncolors - 1) & (1 << n)) + { + spec->nplanes = n + 1; + break; + } + else + n--; + } + } + + spec->fmtid = fmt->fmtid; + // Do some format-specific adjustments and other things switch (fmt->fmtid) { case DM_IMGFMT_PNG: - spec->format = spec->paletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA; + spec->format = optUsePalette ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA; break; case DM_IMGFMT_PPM: @@ -1416,29 +1434,16 @@ } res = dmWriteIFFMasterRAWHeaderFile( - hdrFilename, filename, prefix, image, spec, fmt->fmtid); + hdrFilename, filename, prefix, image, spec); dmFree(prefix); dmFree(hdrFilename); } break; - case DM_IMGFMT_IFF: - spec->nplanes = 0; - for (int n = 8; n >= 0;) - { - if ((image->ncolors - 1) & (1 << n)) - { - spec->nplanes = n + 1; - break; - } - else - n--; - } + default: + spec->format = optUsePalette ? DM_COLFMT_PALETTE : DM_COLFMT_RGB; break; - - default: - spec->format = spec->paletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGB; } // If no error has occured thus far, write the image