changeset 1898:50dbfc10f49f

Fix planar IFF ILBM writing.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 26 Jun 2018 04:31:24 +0300
parents 699ee626912b
children 54baa688425b
files tools/libgfx.c
diffstat 1 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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: