Mercurial > hg > dmlib
changeset 2100:81fb21dd3265
Add dmGetNPlanesFromNColors() and use it.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Mar 2019 15:09:18 +0200 |
parents | dac89484f143 |
children | da886b8cbb09 |
files | tools/gfxconv.c tools/libgfx.c tools/libgfx.h |
diffstat | 3 files changed, 24 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/gfxconv.c Tue Mar 05 14:51:02 2019 +0200 +++ b/tools/gfxconv.c Tue Mar 05 15:09:18 2019 +0200 @@ -1424,21 +1424,13 @@ // Determine number of planes, if paletted if (spec->format == DM_COLFMT_PALETTE && - spec->nplanes == 0) - { - for (int n = 8; n >= 0;) - { - if ((image->pal->ncolors - 1) & (1 << n)) - { - spec->nplanes = n + 1; - break; - } - else - n--; - } - } + spec->nplanes == 0 && image->pal != NULL) + spec->nplanes = dmGetNPlanesFromNColors(image->pal->ncolors); + else + if (image->format == DM_COLFMT_GRAYSCALE) + spec->nplanes = 8; - if (spec->nplanes == 0) + if (spec->nplanes <= 0) spec->nplanes = 4; spec->fmtid = fmt->fmtid;
--- a/tools/libgfx.c Tue Mar 05 14:51:02 2019 +0200 +++ b/tools/libgfx.c Tue Mar 05 15:09:18 2019 +0200 @@ -91,6 +91,23 @@ } +int dmGetNPlanesFromNColors(const int ncolors) +{ + if (ncolors <= 0) + return -1; + + for (int n = 8; n >= 0;) + { + if ((ncolors - 1) & (1 << n)) + return n + 1; + else + n--; + } + + return -2; +} + + BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha) { if (c1->r == c2->r &&
--- a/tools/libgfx.h Tue Mar 05 14:51:02 2019 +0200 +++ b/tools/libgfx.h Tue Mar 05 15:09:18 2019 +0200 @@ -132,6 +132,7 @@ int dmImageGetBytesPerPixel(const int format); int dmImageGetBitsPerPixel(const int format); int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **fmt, int *index); +int dmGetNPlanesFromNColors(const int ncolors); BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha); int dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp);