comparison tools/gfxconv.c @ 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 78a9140f02b1
comparison
equal deleted inserted replaced
2099:dac89484f143 2100:81fb21dd3265
1422 allocated = TRUE; 1422 allocated = TRUE;
1423 } 1423 }
1424 1424
1425 // Determine number of planes, if paletted 1425 // Determine number of planes, if paletted
1426 if (spec->format == DM_COLFMT_PALETTE && 1426 if (spec->format == DM_COLFMT_PALETTE &&
1427 spec->nplanes == 0) 1427 spec->nplanes == 0 && image->pal != NULL)
1428 { 1428 spec->nplanes = dmGetNPlanesFromNColors(image->pal->ncolors);
1429 for (int n = 8; n >= 0;) 1429 else
1430 { 1430 if (image->format == DM_COLFMT_GRAYSCALE)
1431 if ((image->pal->ncolors - 1) & (1 << n)) 1431 spec->nplanes = 8;
1432 { 1432
1433 spec->nplanes = n + 1; 1433 if (spec->nplanes <= 0)
1434 break;
1435 }
1436 else
1437 n--;
1438 }
1439 }
1440
1441 if (spec->nplanes == 0)
1442 spec->nplanes = 4; 1434 spec->nplanes = 4;
1443 1435
1444 spec->fmtid = fmt->fmtid; 1436 spec->fmtid = fmt->fmtid;
1445 1437
1446 // Do some format-specific adjustments and other things 1438 // Do some format-specific adjustments and other things