Mercurial > hg > dmlib
changeset 1299:b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 19 Aug 2017 03:40:49 +0300 |
parents | f0d6aac3adc4 |
children | fd442faa705f |
files | src/libgfx.c |
diffstat | 1 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/libgfx.c Sat Aug 19 03:20:02 2017 +0300 +++ b/src/libgfx.c Sat Aug 19 03:40:49 2017 +0300 @@ -1100,6 +1100,14 @@ goto error; } + if (hdr.nplanes == 4 && hdr.bitsPerPlane == 4) + { + dmMsg(2, + "PCX: Probably invalid combination of nplanes and bpp, attempting to fix ..\n"); + + hdr.bitsPerPlane = 1; + } + isPaletted = (hdr.bitsPerPlane * hdr.nplanes) <= 8; dmMsg(2, @@ -1130,7 +1138,10 @@ // Allocate image if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, isPaletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA, - isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1)) == NULL) + // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp + // isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1 + -1 + )) == NULL) { res = dmError(DMERR_MALLOC, "PCX: Could not allocate image structure.\n"); @@ -1154,6 +1165,10 @@ goto error; } + dmMsg(2, + "PCX: bufLen=%d\n", + pcx.bufLen); + // Read image data Uint8 *dp = img->data; for (int yc = 0; yc < img->height; yc++) @@ -1196,9 +1211,8 @@ for (int xc = 0; xc < img->width; xc++) { - const int qx = xc * 2; - const int px = 7 - (qx & 7); - dp[xc] |= (sptr[qx / 8] & (1 << px)) >> (px - nplane); + const int px = 7 - (xc & 7); + dp[xc] |= ((sptr[xc / 8] & (1 << px)) >> px) << nplane; } } break; @@ -1223,7 +1237,7 @@ if (!dm_fread_byte(fp, &tmpb) || tmpb != 0x0C) { read = FALSE; - ncolors = 256; // KLUDGE + ncolors = DMPCX_PAL_COLORS; } else {