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 2015/04/30 21:07:53 UTC

svn commit: r1677043 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java

Author: tilman
Date: Thu Apr 30 19:07:53 2015
New Revision: 1677043

URL: http://svn.apache.org/r1677043
Log:
PDFBOX-2576: remove double code; avoid uneeded storage when K = 0

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java?rev=1677043&r1=1677042&r2=1677043&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java Thu Apr 30 19:07:53 2015
@@ -70,28 +70,30 @@ final class CCITTFaxFilter extends Filte
         int k = decodeParms.getInt(COSName.K, 0);
         boolean encodedByteAlign = decodeParms.getBoolean(COSName.ENCODED_BYTE_ALIGN, false);
         int arraySize = (cols + 7) / 8 * rows;
-        TIFFFaxDecoder faxDecoder = new TIFFFaxDecoder(1, cols, rows);
         // TODO possible options??
         long tiffOptions = 0;
-        byte[] compressed = IOUtils.toByteArray(encoded);
         byte[] decompressed = null;
         if (k == 0)
         {
-            InputStream in = new CCITTFaxG31DDecodeInputStream(
-                    new ByteArrayInputStream(compressed), cols, rows, encodedByteAlign);
-            in = new FillOrderChangeInputStream(in); //Decorate to change fill order
+            InputStream in = new CCITTFaxG31DDecodeInputStream(encoded, cols, rows, encodedByteAlign);
+            in = new FillOrderChangeInputStream(in);
             decompressed = IOUtils.toByteArray(in);
             in.close();
         }
-        else if (k > 0)
+        else
         {
+            TIFFFaxDecoder faxDecoder = new TIFFFaxDecoder(1, cols, rows);
+            byte[] compressed = IOUtils.toByteArray(encoded);
             decompressed = new byte[arraySize];
-            faxDecoder.decode2D(decompressed, compressed, 0, rows, tiffOptions);
-        }
-        else if (k < 0)
-        {
-            decompressed = new byte[arraySize];
-            faxDecoder.decodeT6(decompressed, compressed, 0, rows, tiffOptions, encodedByteAlign);
+            if (k > 0)
+            {
+                faxDecoder.decode2D(decompressed, compressed, 0, rows, tiffOptions);
+            }
+            else
+            {
+                // k < 0
+                faxDecoder.decodeT6(decompressed, compressed, 0, rows, tiffOptions, encodedByteAlign);
+            }
         }
 
         // invert bitmap