Here's another fix for the bug, this time against the unstable
version.

Only in netpbm-free-10.0.fixed/: lib
diff -U3 -r netpbm-free-10.0/pnm/giftopnm.c 
netpbm-free-10.0.fixed/pnm/giftopnm.c
--- netpbm-free-10.0/pnm/giftopnm.c     2003-08-15 14:30:17.000000000 +0000
+++ netpbm-free-10.0.fixed/pnm/giftopnm.c       2006-08-17 06:04:41.000000000 
+0000
@@ -554,10 +554,12 @@
 static void
 readImageData(FILE * const ifP, 
               xel ** const xels, 
+              bit ** const alphabits, 
               int    const len, 
               int    const height, 
               gifColorMap  cmap, 
-              bool   const interlace) {
+              bool   const interlace,
+             int    const transparent_index) {
 
     unsigned char lzwMinCodeSize;      
     int v;
@@ -587,6 +589,12 @@
     while ((v = lzwReadByte(ifP,FALSE,lzwMinCodeSize)) >= 0 ) {
         PPM_ASSIGN(xels[ypos][xpos], 
                    cmap[CM_RED][v], cmap[CM_GRN][v], cmap[CM_BLU][v]);
+       if (transparent_index != -1 &&
+           v == transparent_index) {
+           alphabits[ypos][xpos] = PBM_BLACK;
+       } else {
+           alphabits[ypos][xpos] = PBM_WHITE;
+       }
 
         ++xpos;
         if (xpos == len) {
@@ -685,9 +693,8 @@
 
 
 static void
-outputAlpha(FILE *alpha_file, pixel ** const xels, 
-            const int cols, const int rows, const int transparent_index,
-            unsigned char cmap[3][MAXCOLORMAPSIZE]) {
+outputAlpha(FILE *alpha_file, pixel ** const alphabits, 
+            const int cols, const int rows) {
 /*----------------------------------------------------------------------------
    Output to file 'alpha_file' (unless it is NULL) the alpha mask for the
    image 'xels', given that the color whose index in the color map 'cmap' is
@@ -698,35 +705,13 @@
 -----------------------------------------------------------------------------*/
 
     if (alpha_file) {
-        bit *alpha_row;  /* malloc'ed */
-        xel transparent_color;
-
-        if (transparent_index != -1) 
-            PPM_ASSIGN(transparent_color, 
-                       cmap[CM_RED][transparent_index],
-                       cmap[CM_GRN][transparent_index],
-                       cmap[CM_BLU][transparent_index]
-                );
-        
-        alpha_row = pbm_allocrow(cols);
-
         pbm_writepbminit(alpha_file, cols, rows, FALSE);
-
         {
             int row;
             for (row = 0; row < rows; row++) {
-                int col;
-                for (col = 0; col < cols; col++) {
-                    if (transparent_index != -1 && 
-                        PNM_EQUAL(xels[row][col], transparent_color))
-                        alpha_row[col] = PBM_BLACK;
-                    else 
-                        alpha_row[col] = PBM_WHITE;
-                }
-                pbm_writepbmrow(alpha_file, alpha_row, cols, FALSE);
+                pbm_writepbmrow(alpha_file, alphabits[row], cols, FALSE);
             }
         }
-        pbm_freerow(alpha_row);
     }
 }
 
@@ -860,6 +845,7 @@
     unsigned char buf[16];
     bool useGlobalColormap;
     xel **xels;  /* The image raster, in libpnm format */
+    bit **alphabits;  /* The image raster, in libpnm format */
     int cols, rows;  /* Dimensions of the image */
     gifColorMap localColorMap;
     int localColorMapSize;
@@ -878,29 +864,31 @@
     if (!xels)
         pm_error("couldn't alloc space for image" );
 
+    alphabits = pbm_allocarray(cols, rows);
+    if (!alphabits)
+        pm_error("couldn't alloc space for alpha map" );
+
     if (! useGlobalColormap) {
         int hasGray, hasColor;
 
         readColorMap(ifP, localColorMapSize, localColorMap, 
                      &hasGray, &hasColor);
         transparencyMessage(gif89.transparent, localColorMap);
-        readImageData(ifP, xels, cols, rows, localColorMap, 
-                      BitSet(buf[8], INTERLACE));
+        readImageData(ifP, xels, alphabits, cols, rows, localColorMap, 
+                      BitSet(buf[8], INTERLACE), gif89.transparent);
         if (!skipIt) {
             writePnm(imageout_file, xels, cols, rows,
                      hasGray, hasColor);
-            outputAlpha(alphafile, xels, cols, rows, 
-                        gif89.transparent, localColorMap);
+            outputAlpha(alphafile, alphabits, cols, rows);
         }
     } else {
         transparencyMessage(gif89.transparent, gifScreen.ColorMap);
-        readImageData(ifP, xels, cols, rows, gifScreen.ColorMap, 
-                      BitSet(buf[8], INTERLACE));
+        readImageData(ifP, xels, alphabits, cols, rows, gifScreen.ColorMap, 
+                      BitSet(buf[8], INTERLACE), gif89.transparent);
         if (!skipIt) {
             writePnm(imageout_file, xels, cols, rows,
                      gifScreen.hasGray, gifScreen.hasColor);
-            outputAlpha(alphafile, xels, cols, rows, 
-                        gif89.transparent, gifScreen.ColorMap);
+            outputAlpha(alphafile, alphabits, cols, rows);
         }
     }
     pnm_freearray(xels, rows);

Reply via email to