comparison src/libgfx.c @ 1300:fd442faa705f

"Fix" the PNG/ILBM decoding to not use actual bitdepths for indexed images, but force 8bits.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 19 Aug 2017 03:57:15 +0300
parents b0c0be4c76f9
children e03f20d0f785
comparison
equal deleted inserted replaced
1299:b0c0be4c76f9 1300:fd442faa705f
599 599
600 // Allocate image 600 // Allocate image
601 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n", 601 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n",
602 width, height, bit_depth, color_type); 602 width, height, bit_depth, color_type);
603 603
604 if ((*pimg = img = dmImageAlloc(width, height, DM_IFMT_PALETTE, bit_depth)) == NULL) 604 if ((*pimg = img = dmImageAlloc(width, height,
605 DM_IFMT_PALETTE,
606 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp
607 -1 /* bit_depth */)) == NULL)
605 { 608 {
606 res = dmError(DMERR_MALLOC, 609 res = dmError(DMERR_MALLOC,
607 "PNG: Could not allocate image data.\n"); 610 "PNG: Could not allocate image data.\n");
608 goto error; 611 goto error;
609 } 612 }
1492 1495
1493 *read = 0; 1496 *read = 0;
1494 1497
1495 // Allocate image 1498 // Allocate image
1496 if ((*pimg = img = dmImageAlloc(iff->bmhd.w, iff->bmhd.h, 1499 if ((*pimg = img = dmImageAlloc(iff->bmhd.w, iff->bmhd.h,
1497 iff->bmhd.nplanes < 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA, 1500 iff->bmhd.nplanes <= 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA,
1498 iff->bmhd.nplanes < 8 ? iff->bmhd.nplanes : -1)) == NULL) 1501 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp
1502 //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1
1503 -1
1504 )) == NULL)
1499 return DMERR_MALLOC; 1505 return DMERR_MALLOC;
1500 1506
1501 // Allocate planar decoding buffer 1507 // Allocate planar decoding buffer
1502 bufLen = ((img->width + 15) / 16) * 2; 1508 bufLen = ((img->width + 15) / 16) * 2;
1503 if ((buf = dmMalloc(bufLen)) == NULL) 1509 if ((buf = dmMalloc(bufLen)) == NULL)
1571 1577
1572 *read = 0; 1578 *read = 0;
1573 1579
1574 // Allocate image 1580 // Allocate image
1575 if ((*pimg = img = dmImageAlloc(iff->bmhd.w, iff->bmhd.h, 1581 if ((*pimg = img = dmImageAlloc(iff->bmhd.w, iff->bmhd.h,
1576 iff->bmhd.nplanes < 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA, 1582 iff->bmhd.nplanes <= 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA,
1577 iff->bmhd.nplanes < 8 ? iff->bmhd.nplanes : -1)) == NULL) 1583 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp
1584 //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1
1585 -1
1586 )) == NULL)
1578 return DMERR_MALLOC; 1587 return DMERR_MALLOC;
1579 1588
1580 // Decode the chunk 1589 // Decode the chunk
1581 for (yc = 0; yc < img->height; yc++) 1590 for (yc = 0; yc < img->height; yc++)
1582 { 1591 {