# HG changeset patch # User Matti Hamalainen # Date 1503103249 -10800 # Node ID b0c0be4c76f90da26fa24b51156beac3ab0629d8 # Parent f0d6aac3adc414f166c79d10bab902219177141f Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now. diff -r f0d6aac3adc4 -r b0c0be4c76f9 src/libgfx.c --- 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 {