about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--converter/other/pnmtopng.c67
-rw-r--r--doc/HISTORY7
2 files changed, 50 insertions, 24 deletions
diff --git a/converter/other/pnmtopng.c b/converter/other/pnmtopng.c
index ffdabc87..a0890e22 100644
--- a/converter/other/pnmtopng.c
+++ b/converter/other/pnmtopng.c
@@ -911,17 +911,17 @@ tryTransparentColor(FILE *     const ifp,
 
 
 static void
-analyzeAlpha(FILE *     const ifp, 
-             pm_filepos const rasterPos, 
-             int        const cols, 
-             int        const rows, 
-             xelval     const maxval,
-             int        const format, 
-             gray **    const alphaMask,
-             gray       const alphaMaxval,
-             bool *     const allOpaqueP,
-             bool *     const singleColorIsTransP, 
-             pixel *    const alphaTranscolorP) {
+analyzeAlpha(FILE *       const ifP,
+             pm_filepos   const rasterPos, 
+             unsigned int const cols, 
+             unsigned int const rows, 
+             xelval       const maxval,
+             int          const format, 
+             gray **      const alphaMask,
+             gray         const alphaMaxval,
+             bool *       const allOpaqueP,
+             bool *       const singleColorIsTransP, 
+             pixel *      const alphaTranscolorP) {
 /*----------------------------------------------------------------------------
   Get information about the alpha mask, in combination with the masked
   image, that Caller can use to choose the most efficient way to
@@ -942,19 +942,38 @@ analyzeAlpha(FILE *     const ifp,
         */
     pixel transcolor;
         /* Color of the transparent pixel mentioned above. */
+    bool foundNonOpaquePixel;
+        /* We found a pixel in the image where the alpha mask says it is
+           not fully opaque.
+        */
     
     xelrow = pnm_allocrow(cols);
 
     {
-        int row;
+        unsigned int row;
+        /* See if the mask says every pixel is opaque. */
+        foundNonOpaquePixel = false;  /* initial assumption */
+        pm_seek2(ifP, &rasterPos, sizeof(rasterPos));
+        for (row = 0; row < rows && !foundNonOpaquePixel; ++row) {
+            unsigned int col;
+            pnm_readpnmrow(ifP, xelrow, cols, maxval, format);
+            for (col = 0; col < cols && !foundNonOpaquePixel; ++col) {
+                if (alphaMask[row][col] != maxval)
+                    foundNonOpaquePixel = true;
+            }
+        }
+    }
+
+    if (foundNonOpaquePixel) {
+        unsigned int row;
         /* Find a candidate transparent color -- the color of any pixel in the
            image that the alpha mask says should be transparent.
         */
-        foundTransparentPixel = FALSE;  /* initial assumption */
-        pm_seek2(ifp, &rasterPos, sizeof(rasterPos));
+        foundTransparentPixel = false;  /* initial assumption */
+        pm_seek2(ifP, &rasterPos, sizeof(rasterPos));
         for (row = 0; row < rows && !foundTransparentPixel; ++row) {
-            int col;
-            pnm_readpnmrow(ifp, xelrow, cols, maxval, format);
+            unsigned int col;
+            pnm_readpnmrow(ifP, xelrow, cols, maxval, format);
             for (col = 0; col < cols && !foundTransparentPixel; ++col) {
                 if (alphaMask[row][col] == 0) {
                     foundTransparentPixel = TRUE;
@@ -962,20 +981,20 @@ analyzeAlpha(FILE *     const ifp,
                 }
             }
         }
-    }
+    } else
+        foundTransparentPixel = false;
 
     pnm_freerow(xelrow);
 
+    *allOpaqueP = !foundNonOpaquePixel;
+
     if (foundTransparentPixel) {
-        *allOpaqueP = FALSE;
-        tryTransparentColor(ifp, rasterPos, cols, rows, maxval, format,
+        tryTransparentColor(ifP, rasterPos, cols, rows, maxval, format,
                             alphaMask, alphaMaxval, transcolor,
                             singleColorIsTransP);
         *alphaTranscolorP = transcolor;
-    } else {
-        *allOpaqueP   = TRUE;
-        *singleColorIsTransP = FALSE;
-    }
+    } else
+        *singleColorIsTransP = false;
 }
 
 
@@ -1042,6 +1061,8 @@ determineTransparency(struct cmdlineInfo const cmdline,
             *transparentP = 2;
             *transColorP  = alphaTranscolor;
         } else if (allOpaque) {
+            if (verbose)
+                pm_message("Skipping alpha because mask is all opaque");
             *alphaP       = FALSE;
             *transparentP = -1;
         } else {
diff --git a/doc/HISTORY b/doc/HISTORY
index 981f676f..fcb3ff70 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,12 +4,17 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
+not yet  BJH  Release 10.56.00
+
+              pnmtopng: fix bug: with -alpha specifying a mask which contains
+              no fully transparent area, output PNG is fully opaque.
+
 11.06.29 BJH  Release 10.55.00
 
               Add pamtosrf, srftopam.  Thanks Mike Frysinger
               (vapier@gentoo.org).
 
-              pgmtexure: fix wrong sum variance result.  Wrong since the
+              pgmtexture: fix wrong sum variance result.  Wrong since the
               beginning.  Thanks Francois P. S. Luus <fpsluus@gmail.com>.
 
               pamrubber: fix crash.  Introduced in 10.54.