pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1825808 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Date Sun, 04 Mar 2018 12:06:53 GMT
Author: tilman
Date: Sun Mar  4 12:06:53 2018
New Revision: 1825808

URL: http://svn.apache.org/viewvc?rev=1825808&view=rev
Log:
PDFBOX-3340: optimize repair process by decoding only if JPX filter, inspired by Itai Shaked

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java?rev=1825808&r1=1825807&r2=1825808&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Sun Mar  4 12:06:53 2018
@@ -39,6 +39,7 @@ import org.apache.pdfbox.cos.COSInputStr
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.filter.DecodeResult;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDResources;
@@ -123,15 +124,18 @@ public final class PDImageXObject extend
      */
     public PDImageXObject(PDStream stream, PDResources resources) throws IOException
     {
-        this(stream, resources, stream.createInputStream());
-    }
-    
-    // repairs parameters using decode result
-    private PDImageXObject(PDStream stream, PDResources resources, COSInputStream input)
-    {
-        super(repair(stream, input), COSName.IMAGE);
+        super(stream, COSName.IMAGE);
         this.resources = resources;
-        this.colorSpace = input.getDecodeResult().getJPXColorSpace();
+        List<COSName> filters = stream.getFilters();
+        if (filters != null && filters.size() > 0 && COSName.JPX_DECODE.equals(filters.get(filters.size()-1)))
+        {
+            try (COSInputStream is = stream.createInputStream())
+            {
+                DecodeResult decodeResult = is.getDecodeResult();
+                stream.getCOSObject().addAll(decodeResult.getParameters());
+                this.colorSpace = decodeResult.getJPXColorSpace();
+            }
+        }
     }
 
     /**
@@ -318,13 +322,6 @@ public final class PDImageXObject extend
         throw new IllegalArgumentException("Image type not supported: " + name);
     }
 
-    // repairs parameters using decode result
-    private static PDStream repair(PDStream stream, COSInputStream input)
-    {
-        stream.getCOSObject().addAll(input.getDecodeResult().getParameters());
-        return stream;
-    }
-
     /**
      * Returns the metadata associated with this XObject, or null if there is none.
      * @return the metadata associated with this object.



Mime
View raw message