You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/03/24 14:26:00 UTC

svn commit: r1827652 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java

Author: tilman
Date: Sat Mar 24 14:26:00 2018
New Revision: 1827652

URL: http://svn.apache.org/viewvc?rev=1827652&view=rev
Log:
PDFBOX-4071: don't reassign parameters

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java?rev=1827652&r1=1827651&r2=1827652&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java Sat Mar 24 14:26:00 2018
@@ -214,16 +214,17 @@ final class SampledImageReader
         return fromAny(pdImage, raster, colorKey, clipped, subsampling, width, height);
     }
 
-    private static BufferedImage from1Bit(PDImage pdImage, Rectangle clipped, int subsampling,
+    private static BufferedImage from1Bit(PDImage pdImage, Rectangle clipped, final int subsampling,
                                           final int width, final int height) throws IOException
     {
+        int currentSubsampling = subsampling;
         final PDColorSpace colorSpace = pdImage.getColorSpace();
         final float[] decode = getDecodeArray(pdImage);
         BufferedImage bim = null;
         WritableRaster raster;
         byte[] output;
 
-        DecodeOptions options = new DecodeOptions(subsampling);
+        DecodeOptions options = new DecodeOptions(currentSubsampling);
         options.setSourceRegion(clipped);
         // read bit stream
         InputStream iis = null;
@@ -242,7 +243,7 @@ final class SampledImageReader
                 starty = 0;
                 scanWidth = width;
                 scanHeight = height;
-                subsampling = 1;
+                currentSubsampling = 1;
             }
             else
             {
@@ -296,7 +297,7 @@ final class SampledImageReader
             {
                 int x = 0;
                 int readLen = iis.read(buff);
-                if (y < starty || y % subsampling > 0)
+                if (y < starty || y % currentSubsampling > 0)
                 {
                     continue;
                 }
@@ -312,7 +313,7 @@ final class SampledImageReader
                         }
                         int bit = value & mask;
                         mask >>= 1;
-                        if (x >= startx && x % subsampling == 0)
+                        if (x >= startx && x % currentSubsampling == 0)
                         {
                             output[idx++] = bit == 0 ? value0 : value1;
                         }
@@ -344,10 +345,11 @@ final class SampledImageReader
     }
 
     // faster, 8-bit non-decoded, non-colormasked image conversion
-    private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster, Rectangle clipped, int subsampling,
+    private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster, Rectangle clipped, final int subsampling,
                                           final int width, final int height) throws IOException
     {
-        DecodeOptions options = new DecodeOptions(subsampling);
+        int currentSubsampling = subsampling;
+        DecodeOptions options = new DecodeOptions(currentSubsampling);
         options.setSourceRegion(clipped);
         InputStream input = pdImage.createInputStream(options);
         try
@@ -365,7 +367,7 @@ final class SampledImageReader
                 starty = 0;
                 scanWidth = width;
                 scanHeight = height;
-                subsampling = 1;
+                currentSubsampling = 1;
             }
             else
             {
@@ -379,7 +381,7 @@ final class SampledImageReader
             final int numComponents = pdImage.getColorSpace().getNumberOfComponents();
             // get the raster's underlying byte buffer
             byte[] bank = ((DataBufferByte) raster.getDataBuffer()).getData();
-            if (startx == 0 && starty == 0 && scanWidth == width && scanHeight == height && subsampling == 1)
+            if (startx == 0 && starty == 0 && scanWidth == width && scanHeight == height && currentSubsampling == 1)
             {
                 // we just need to copy all sample data, then convert to RGB image.
                 long inputResult = input.read(bank);
@@ -400,12 +402,12 @@ final class SampledImageReader
             for (int y = 0; y < starty + scanHeight; ++y)
             {
                 input.read(tempBytes);
-                if (y < starty || y % subsampling > 0)
+                if (y < starty || y % currentSubsampling > 0)
                 {
                     continue;
                 }
 
-                if (subsampling == 1)
+                if (currentSubsampling == 1)
                 {
                     // Not the entire region was requested, but if no subsampling should
                     // be performed, we can still copy the entire part of this row
@@ -413,7 +415,7 @@ final class SampledImageReader
                 }
                 else
                 {
-                    for (int x = startx; x < startx + scanWidth; x += subsampling)
+                    for (int x = startx; x < startx + scanWidth; x += currentSubsampling)
                     {
                         for (int c = 0; c < numComponents; c++)
                         {
@@ -434,15 +436,16 @@ final class SampledImageReader
 
     // slower, general-purpose image conversion from any image format
     private static BufferedImage fromAny(PDImage pdImage, WritableRaster raster, COSArray colorKey, Rectangle clipped,
-                                         int subsampling, final int width, final int height)
+                                         final int subsampling, final int width, final int height)
             throws IOException
     {
+        int currentSubsampling = subsampling;
         final PDColorSpace colorSpace = pdImage.getColorSpace();
         final int numComponents = colorSpace.getNumberOfComponents();
         final int bitsPerComponent = pdImage.getBitsPerComponent();
         final float[] decode = getDecodeArray(pdImage);
 
-        DecodeOptions options = new DecodeOptions(subsampling);
+        DecodeOptions options = new DecodeOptions(currentSubsampling);
         options.setSourceRegion(clipped);
         // read bit stream
         ImageInputStream iis = null;
@@ -461,7 +464,7 @@ final class SampledImageReader
                 starty = 0;
                 scanWidth = width;
                 scanHeight = height;
-                subsampling = 1;
+                currentSubsampling = 1;
             }
             else
             {
@@ -536,15 +539,15 @@ final class SampledImageReader
                         }
                     }
                     // only write to output if within requested region and subsample.
-                    if (x >= startx && y >= starty && x % subsampling == 0 && y % subsampling == 0)
+                    if (x >= startx && y >= starty && x % currentSubsampling == 0 && y % currentSubsampling == 0)
                     {
-                        raster.setDataElements((x - startx) / subsampling, (y - starty) / subsampling, srcColorValues);
+                        raster.setDataElements((x - startx) / currentSubsampling, (y - starty) / currentSubsampling, srcColorValues);
 
                         // set alpha channel in color key mask, if any
                         if (colorKeyMask != null)
                         {
                             alpha[0] = (byte)(isMasked ? 255 : 0);
-                            colorKeyMask.getRaster().setDataElements((x - startx) / subsampling, (y - starty) / subsampling, alpha);
+                            colorKeyMask.getRaster().setDataElements((x - startx) / currentSubsampling, (y - starty) / currentSubsampling, alpha);
                         }
                     }
                 }