Mercurial > hg > dmlib
comparison 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 |
comparison
equal
deleted
inserted
replaced
2064:3617ef01c1de | 2065:451980580189 |
---|---|
125 optCropW, optCropH; | 125 optCropW, optCropH; |
126 | 126 |
127 BOOL optInMulticolor = FALSE, | 127 BOOL optInMulticolor = FALSE, |
128 optSequential = FALSE, | 128 optSequential = FALSE, |
129 optRemapColors = FALSE, | 129 optRemapColors = FALSE, |
130 optRemapRemove = FALSE; | 130 optRemapRemove = FALSE, |
131 optUsePalette = FALSE; | |
131 int optNRemapTable = 0, | 132 int optNRemapTable = 0, |
132 optScaleMode = SCALE_AUTO; | 133 optScaleMode = SCALE_AUTO; |
133 DMMapValue optRemapTable[DM_MAX_COLORS]; | 134 DMMapValue optRemapTable[DM_MAX_COLORS]; |
134 int optColorMap[C64_NCOLORS]; | 135 int optColorMap[C64_NCOLORS]; |
135 | 136 |
138 .scaleX = 1, | 139 .scaleX = 1, |
139 .scaleY = 1, | 140 .scaleY = 1, |
140 .nplanes = 4, | 141 .nplanes = 4, |
141 .bpp = 8, | 142 .bpp = 8, |
142 .planar = FALSE, | 143 .planar = FALSE, |
143 .paletted = FALSE, | |
144 .format = 0, | 144 .format = 0, |
145 .compression = FCMP_BEST, | 145 .compression = FCMP_BEST, |
146 }; | 146 }; |
147 | 147 |
148 static const DMOptArg optList[] = | 148 static const DMOptArg optList[] = |
814 } | 814 } |
815 optPlanedWidth = tmpUInt; | 815 optPlanedWidth = tmpUInt; |
816 break; | 816 break; |
817 | 817 |
818 case 12: | 818 case 12: |
819 optSpec.paletted = TRUE; | 819 optUsePalette = TRUE; |
820 break; | 820 break; |
821 | 821 |
822 case 13: | 822 case 13: |
823 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || | 823 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
824 tmpUInt < 1 || tmpUInt > 8) | 824 tmpUInt < 1 || tmpUInt > 8) |
1325 | 1325 |
1326 | 1326 |
1327 int dmWriteIFFMasterRAWHeaderFile( | 1327 int dmWriteIFFMasterRAWHeaderFile( |
1328 const char *hdrFilename, const char *dataFilename, | 1328 const char *hdrFilename, const char *dataFilename, |
1329 const char *prefix, const DMImage *img, | 1329 const char *prefix, const DMImage *img, |
1330 const DMImageConvSpec *spec, const int fmtid) | 1330 const DMImageConvSpec *spec) |
1331 { | 1331 { |
1332 DMResource *fp; | 1332 DMResource *fp; |
1333 int res; | 1333 int res; |
1334 | 1334 |
1335 if ((res = dmf_open_stdio(hdrFilename, "wb", &fp)) != DMERR_OK) | 1335 if ((res = dmf_open_stdio(hdrFilename, "wb", &fp)) != DMERR_OK) |
1337 return dmError(res, | 1337 return dmError(res, |
1338 "RAW: Could not open file '%s' for writing.\n", | 1338 "RAW: Could not open file '%s' for writing.\n", |
1339 hdrFilename); | 1339 hdrFilename); |
1340 } | 1340 } |
1341 | 1341 |
1342 res = dmWriteIFFMasterRAWHeader(fp, dataFilename, prefix, img, spec, fmtid); | 1342 res = dmWriteIFFMasterRAWHeader(fp, dataFilename, prefix, img, spec); |
1343 | 1343 |
1344 dmf_close(fp); | 1344 dmf_close(fp); |
1345 return res; | 1345 return res; |
1346 } | 1346 } |
1347 | 1347 |
1376 return res; | 1376 return res; |
1377 | 1377 |
1378 allocated = TRUE; | 1378 allocated = TRUE; |
1379 } | 1379 } |
1380 | 1380 |
1381 // Determine number of planes, if paletted | |
1382 if (spec->format == DM_COLFMT_PALETTE) | |
1383 { | |
1384 spec->nplanes = 0; | |
1385 for (int n = 8; n >= 0;) | |
1386 { | |
1387 if ((image->ncolors - 1) & (1 << n)) | |
1388 { | |
1389 spec->nplanes = n + 1; | |
1390 break; | |
1391 } | |
1392 else | |
1393 n--; | |
1394 } | |
1395 } | |
1396 | |
1397 spec->fmtid = fmt->fmtid; | |
1398 | |
1381 // Do some format-specific adjustments and other things | 1399 // Do some format-specific adjustments and other things |
1382 switch (fmt->fmtid) | 1400 switch (fmt->fmtid) |
1383 { | 1401 { |
1384 case DM_IMGFMT_PNG: | 1402 case DM_IMGFMT_PNG: |
1385 spec->format = spec->paletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA; | 1403 spec->format = optUsePalette ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA; |
1386 break; | 1404 break; |
1387 | 1405 |
1388 case DM_IMGFMT_PPM: | 1406 case DM_IMGFMT_PPM: |
1389 spec->format = DM_COLFMT_RGB; | 1407 spec->format = DM_COLFMT_RGB; |
1390 break; | 1408 break; |
1414 fmt->fmtid == DM_IMGFMT_ARAW ? "ARAW" : "RAW", | 1432 fmt->fmtid == DM_IMGFMT_ARAW ? "ARAW" : "RAW", |
1415 hdrFilename, prefix); | 1433 hdrFilename, prefix); |
1416 } | 1434 } |
1417 | 1435 |
1418 res = dmWriteIFFMasterRAWHeaderFile( | 1436 res = dmWriteIFFMasterRAWHeaderFile( |
1419 hdrFilename, filename, prefix, image, spec, fmt->fmtid); | 1437 hdrFilename, filename, prefix, image, spec); |
1420 | 1438 |
1421 dmFree(prefix); | 1439 dmFree(prefix); |
1422 dmFree(hdrFilename); | 1440 dmFree(hdrFilename); |
1423 } | 1441 } |
1424 break; | 1442 break; |
1425 | 1443 |
1426 case DM_IMGFMT_IFF: | |
1427 spec->nplanes = 0; | |
1428 for (int n = 8; n >= 0;) | |
1429 { | |
1430 if ((image->ncolors - 1) & (1 << n)) | |
1431 { | |
1432 spec->nplanes = n + 1; | |
1433 break; | |
1434 } | |
1435 else | |
1436 n--; | |
1437 } | |
1438 break; | |
1439 | |
1440 default: | 1444 default: |
1441 spec->format = spec->paletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGB; | 1445 spec->format = optUsePalette ? DM_COLFMT_PALETTE : DM_COLFMT_RGB; |
1446 break; | |
1442 } | 1447 } |
1443 | 1448 |
1444 // If no error has occured thus far, write the image | 1449 // If no error has occured thus far, write the image |
1445 if (res == DMERR_OK) | 1450 if (res == DMERR_OK) |
1446 { | 1451 { |