pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1853029 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color: PDColorSpace.java PDICCBased.java
Date Tue, 05 Feb 2019 19:28:03 GMT
Author: tilman
Date: Tue Feb  5 19:28:03 2019
New Revision: 1853029

URL: http://svn.apache.org/viewvc?rev=1853029&view=rev
Log:
PDFBOX-4411: Support caching of ICC based color spaces, by Itai Shaked

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java?rev=1853029&r1=1853028&r2=1853029&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
Tue Feb  5 19:28:03 2019
@@ -189,7 +189,7 @@ public abstract class PDColorSpace imple
             }
             else if (name == COSName.ICCBASED)
             {
-                return new PDICCBased(array);
+                return PDICCBased.create(array, resources);
             }
             else if (name == COSName.LAB)
             {

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java?rev=1853029&r1=1853028&r2=1853029&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
Tue Feb  5 19:28:03 2019
@@ -38,9 +38,11 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSFloat;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.PDRange;
 import org.apache.pdfbox.pdmodel.common.PDStream;
@@ -91,12 +93,61 @@ public final class PDICCBased extends PD
     /**
      * Creates a new ICC color space using the PDF array.
      *
-     * @param iccArray the ICC stream object
+     * @param iccArray the ICC stream object.
      * @throws IOException if there is an error reading the ICC profile or if the parameter
is
      * invalid.
+     *
+     * @deprecated This will be private in 3.0. Please use
+     * {@link PDICCBased#create(org.apache.pdfbox.cos.COSArray, org.apache.pdfbox.pdmodel.PDResources)}
+     * instead, which supports caching.
      */
+    @Deprecated
     public PDICCBased(COSArray iccArray) throws IOException
     {
+        checkArray(iccArray);
+        useOnlyAlternateColorSpace = System
+                .getProperty("org.apache.pdfbox.rendering.UseAlternateInsteadOfICCColorSpace")
!= null;
+        array = iccArray;
+        stream = new PDStream((COSStream) iccArray.getObject(1));
+        loadICCProfile();
+    }
+
+    /**
+     * Creates a new ICC color space using the PDF array, optionally using a resource cache.
+     *
+     * @param iccArray the ICC stream object.
+     * @param resources resources to use as cache, or null for no caching.
+     * @return an ICC color space.
+     * @throws IOException if there is an error reading the ICC profile or if the parameter
is
+     * invalid.
+     */
+    public static PDICCBased create(COSArray iccArray, PDResources resources) throws IOException
+    {
+        checkArray(iccArray);
+        COSBase base = iccArray.get(1);
+        COSObject indirect = null;
+        if (base instanceof COSObject)
+        {
+            indirect = (COSObject) base;
+        }
+        if (indirect != null && resources != null && resources.getResourceCache()
!= null)
+        {
+            PDColorSpace space = resources.getResourceCache().getColorSpace(indirect);
+            if (space != null && space instanceof PDICCBased)
+            {
+                return (PDICCBased) space;
+            }
+        }
+        PDICCBased space = new PDICCBased(iccArray);
+        if (indirect != null && resources != null && resources.getResourceCache()
!= null)
+        {
+            resources.getResourceCache().put(indirect, space);
+        }
+        return space;
+    }
+
+    private static void checkArray(COSArray iccArray) throws IOException
+    {
         if (iccArray.size() < 2)
         {
             throw new IOException("ICCBased colorspace array must have two elements");
@@ -105,11 +156,6 @@ public final class PDICCBased extends PD
         {
             throw new IOException("ICCBased colorspace array must have a stream as second
element");
         }
-        useOnlyAlternateColorSpace = System
-            .getProperty("org.apache.pdfbox.rendering.UseAlternateInsteadOfICCColorSpace")
!= null;
-        array = iccArray;
-        stream = new PDStream((COSStream) iccArray.getObject(1));
-        loadICCProfile();
     }
 
     @Override



Mime
View raw message