# HG changeset patch # User Matti Hamalainen # Date 1529976684 -10800 # Node ID 50dbfc10f49f60b5e18def5a110ff40e8dc3209f # Parent 699ee626912b52068d94eeeb556a8e76b8446dfa Fix planar IFF ILBM writing. diff -r 699ee626912b -r 50dbfc10f49f tools/libgfx.c --- a/tools/libgfx.c Tue Jun 26 04:29:26 2018 +0300 +++ b/tools/libgfx.c Tue Jun 26 04:31:24 2018 +0300 @@ -2046,19 +2046,6 @@ } -static inline Uint8 dmEncodeBit(const Uint8 *buf, const int xc) -{ - return (buf[xc] >> (7 - (xc & 7))) & 1; -} - - -void dmEncodeBitPlane(Uint8 *dp, const Uint8 *src, const int width, const int nplane) -{ - for (int xc = 0; xc < width; xc++) - dp[xc / 8] |= dmEncodeBit(src, xc) << nplane; -} - - int dmEncodeILBMBody(DMResource *fp, DMIFF *iff, const DMImage *img) { Uint8 *buf; @@ -2078,12 +2065,13 @@ { const Uint8 *sp = img->data + (yc * img->pitch); - dmMemset(buf, 0, bufLen); - for (int plane = 0; plane < nplanes; plane++) { // Encode bitplane - dmEncodeBitPlane(buf, sp, img->width, plane); + dmMemset(buf, 0, bufLen); + + for (int xc = 0; xc < img->width; xc++) + buf[xc / 8] |= ((sp[xc] >> plane) & 1) << (7 - (xc & 7)); // Compress / write data if (!dmIFFWriteOneRow(fp, iff, buf, bufLen)) @@ -2094,6 +2082,23 @@ goto error; } } + + // Write mask data + if (iff->bmhd.masking == IFF_MASK_HAS_MASK) + { + // Encode bitplane + dmMemset(buf, 0, bufLen); + + for (int xc = 0; xc < img->width; xc++) + buf[xc / 8] |= (sp[xc] == img->ctransp) << (7 - (xc & 7)); + + if (!dmIFFWriteOneRow(fp, iff, buf, bufLen)) + { + res = dmError(DMERR_FWRITE, + "IFF: Error in writing mask plane.\n"); + goto error; + } + } } error: