< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java

Print this page

        

@@ -1157,15 +1157,23 @@
                                               imRas.getHeight(),
                                               0, 0,
                                               destinationBands);
         }
 
+        boolean tRNSTransparentPixelPresent =
+                theImage.getSampleModel().getNumBands() == inputBands + 1 &&
+                metadata.hasTransparentColor();
         // Determine if all of the relevant output bands have the
         // same bit depth as the source data
         boolean adjustBitDepths = false;
         int[] outputSampleSize = imRas.getSampleModel().getSampleSize();
-        int numBands = outputSampleSize.length;
+        int numBands;
+        if (tRNSTransparentPixelPresent) {
+            numBands = outputSampleSize.length - 1;
+        } else {
+            numBands = outputSampleSize.length;
+        }
         for (int b = 0; b < numBands; b++) {
             if (outputSampleSize[b] != bitDepth) {
                 adjustBitDepths = true;
                 break;
             }

@@ -1281,13 +1289,10 @@
                 * For PNG images of color type PNG_COLOR_RGB or PNG_COLOR_GRAY
                 * that contain a specific transparent color (given by tRNS
                 * chunk), we compare the decoded pixel color with the color
                 * given by tRNS chunk to set the alpha on the destination.
                 */
-                boolean tRNSTransparentPixelPresent =
-                    theImage.getSampleModel().getNumBands() == inputBands + 1 &&
-                    metadata.hasTransparentColor();
                 if (useSetRect &&
                     !tRNSTransparentPixelPresent) {
                     imRas.setRect(updateMinX, dstY, passRow);
                 } else {
                     int newSrcX = srcX;
< prev index next >