Author: tilman
Date: Thu Feb 13 09:19:22 2025
New Revision: 1923773

URL: http://svn.apache.org/viewvc?rev=1923773&view=rev
Log:
PDFBOX-5952: pass resources to be able to use resource cache during creation of 
ICC colorspace, as suggested by Andreas Lehmkühler

Modified:
    
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
    
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
    
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
    
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java?rev=1923773&r1=1923772&r2=1923773&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
 (original)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
 Thu Feb 13 09:19:22 2025
@@ -181,7 +181,7 @@ public abstract class PDColorSpace imple
             }
             else if (name == COSName.DEVICEN)
             {
-                return new PDDeviceN(array);
+                return new PDDeviceN(array, resources);
             }
             else if (name == COSName.INDEXED)
             {
@@ -189,7 +189,7 @@ public abstract class PDColorSpace imple
             }
             else if (name == COSName.SEPARATION)
             {
-                return new PDSeparation(array);
+                return new PDSeparation(array, resources);
             }
             else if (name == COSName.ICCBASED)
             {

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java?rev=1923773&r1=1923772&r2=1923773&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
 (original)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
 Thu Feb 13 09:19:22 2025
@@ -34,6 +34,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNull;
+import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
 
 /**
@@ -83,20 +84,21 @@ public class PDDeviceN extends PDSpecial
      * Creates a new DeviceN color space from the given COS array.
      * 
      * @param deviceN an array containing the color space information
+     * @param resources resources, can be null.
      * 
      * @throws IOException if the colorspace could not be created
      */
-    public PDDeviceN(COSArray deviceN) throws IOException
+    public PDDeviceN(COSArray deviceN, PDResources resources) throws 
IOException
     {
         array = deviceN;
-        alternateColorSpace = 
PDColorSpace.create(array.getObject(ALTERNATE_CS));
+        alternateColorSpace = 
PDColorSpace.create(array.getObject(ALTERNATE_CS), resources);
         tintTransform = PDFunction.create(array.getObject(TINT_TRANSFORM));
 
         if (array.size() > DEVICEN_ATTRIBUTES)
         {
             attributes = new 
PDDeviceNAttributes((COSDictionary)array.getObject(DEVICEN_ATTRIBUTES));
         }
-        initColorConversionCache();
+        initColorConversionCache(resources);
 
         // set initial color space
         int n = getNumberOfComponents();
@@ -105,8 +107,20 @@ public class PDDeviceN extends PDSpecial
         initialColor = new PDColor(initial, this);
     }
 
+    /**
+     * Creates a new DeviceN color space from the given COS array.
+     * 
+     * @param deviceN an array containing the color space information
+     * 
+     * @throws IOException if the colorspace could not be created
+     */
+    public PDDeviceN(COSArray deviceN) throws IOException
+    {
+        this(deviceN, null);
+    }
+
     // initializes the color conversion cache
-    private void initColorConversionCache() throws IOException
+    private void initColorConversionCache(PDResources resources) throws 
IOException
     {
         // there's nothing to cache for non-attribute spaces
         if (attributes == null)
@@ -124,7 +138,7 @@ public class PDDeviceN extends PDSpecial
         {
             List<String> components = attributes.getProcess().getComponents();
 
-            // map each colorant to the corresponding process component (if 
any)
+            // map each colorant name to the corresponding process component 
name (if any)
             for (int c = 0; c < numColorants; c++)
             {
                 colorantToComponent[c] = 
components.indexOf(colorantNames.get(c));
@@ -145,7 +159,7 @@ public class PDDeviceN extends PDSpecial
         spotColorSpaces = new PDSeparation[numColorants];
 
         // spot color spaces
-        Map<String, PDSeparation> spotColorants = attributes.getColorants();
+        Map<String, PDSeparation> spotColorants = 
attributes.getColorants(resources);
 
         // map each colorant to the corresponding spot color space
         for (int c = 0; c < numColorants; c++)

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java?rev=1923773&r1=1923772&r2=1923773&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
 (original)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
 Thu Feb 13 09:19:22 2025
@@ -27,6 +27,7 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.pdmodel.PDResources;
 
 /**
  * Contains additional information about the components of colour space.
@@ -72,10 +73,11 @@ public final class PDDeviceNAttributes
 
     /**
      * Returns a map of colorants and their associated Separation color space.
+     * @param resources resources, can be null.
      * @return map of colorants to color spaces, never null.
      * @throws IOException If there is an error reading a color space
      */
-    public Map<String, PDSeparation> getColorants() throws IOException
+    public Map<String, PDSeparation> getColorants(PDResources resources) 
throws IOException
     {
         Map<String,PDSeparation> actuals = new HashMap<>();
         COSDictionary colorants = 
dictionary.getCOSDictionary(COSName.COLORANTS);
@@ -89,13 +91,23 @@ public final class PDDeviceNAttributes
             for (COSName name : colorants.keySet())
             {
                 COSBase value = colorants.getDictionaryObject(name);
-                actuals.put(name.getName(), (PDSeparation) 
PDColorSpace.create(value));
+                actuals.put(name.getName(), (PDSeparation) 
PDColorSpace.create(value, resources));
             }
         }
         return new COSDictionaryMap<>(actuals, colorants);
     }
 
     /**
+     * Returns a map of colorants and their associated Separation color space.
+     * @return map of colorants to color spaces, never null.
+     * @throws IOException If there is an error reading a color space
+     */
+    public Map<String, PDSeparation> getColorants() throws IOException
+    {
+        return getColorants(null);
+    }
+
+    /**
      * Returns the DeviceN Process Dictionary, or null if it is missing.
      * @return the DeviceN Process Dictionary, or null if it is missing.
      */

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java?rev=1923773&r1=1923772&r2=1923773&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
 (original)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
 Thu Feb 13 09:19:22 2025
@@ -30,6 +30,7 @@ import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNull;
+import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.function.PDFunction;
 
 /**
@@ -78,12 +79,13 @@ public class PDSeparation extends PDSpec
     /**
      * Creates a new Separation color space from a PDF color space array.
      * @param separation an array containing all separation information.
+     * @param resources resources, can be null.
      * @throws IOException if the color space or the function could not be 
created.
      */
-    public PDSeparation(COSArray separation) throws IOException
+    public PDSeparation(COSArray separation, PDResources resources) throws 
IOException
     {
         array = separation;
-        alternateColorSpace = 
PDColorSpace.create(array.getObject(ALTERNATE_CS));
+        alternateColorSpace = 
PDColorSpace.create(array.getObject(ALTERNATE_CS), resources);
         tintTransform = PDFunction.create(array.getObject(TINT_TRANSFORM));
         int numberOfOutputParameters = 
tintTransform.getNumberOfOutputParameters();
         if (numberOfOutputParameters > 0 &&
@@ -95,6 +97,16 @@ public class PDSeparation extends PDSpec
         }
     }
 
+    /**
+     * Creates a new Separation color space from a PDF color space array.
+     * @param separation an array containing all separation information.
+     * @throws IOException if the color space or the function could not be 
created.
+     */
+    public PDSeparation(COSArray separation) throws IOException
+    {
+        this(separation, null);
+    }
+
     @Override
     public String getName()
     {


Reply via email to