Author: tilman
Date: Thu Feb 13 09:19:34 2025
New Revision: 1923775
URL: http://svn.apache.org/viewvc?rev=1923775&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/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/PDDeviceN.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.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=1923775&r1=1923774&r2=1923775&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
Thu Feb 13 09:19:34 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/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java?rev=1923775&r1=1923774&r2=1923775&view=diff
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
(original)
+++
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java
Thu Feb 13 09:19:34 2025
@@ -33,6 +33,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.COSArrayList;
import org.apache.pdfbox.pdmodel.common.function.PDFunction;
@@ -81,12 +82,16 @@ 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)
@@ -94,7 +99,7 @@ public class PDDeviceN extends PDSpecial
attributes = new
PDDeviceNAttributes((COSDictionary)array.getObject(DEVICEN_ATTRIBUTES));
}
List<String> colorantNames = getColorantNames();
- initColorConversionCache(colorantNames);
+ initColorConversionCache(colorantNames, resources);
// set initial color space
int n = colorantNames.size();
@@ -106,8 +111,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(List<String> colorantNames) throws
IOException
+ private void initColorConversionCache(List<String> colorantNames,
PDResources resources) throws IOException
{
// there's nothing to cache for non-attribute spaces
if (attributes == null)
@@ -124,7 +141,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 +162,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/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java?rev=1923775&r1=1923774&r2=1923775&view=diff
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
(original)
+++
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java
Thu Feb 13 09:19:34 2025
@@ -24,6 +24,7 @@ import org.apache.pdfbox.pdmodel.common.
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.pdfbox.pdmodel.PDResources;
/**
* Contains additional information about the components of colour space.
@@ -64,10 +65,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<String, PDSeparation>();
COSDictionary colorants =
dictionary.getCOSDictionary(COSName.COLORANTS);
@@ -81,13 +83,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<String, PDSeparation>(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/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
URL:
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java?rev=1923775&r1=1923774&r2=1923775&view=diff
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
(original)
+++
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java
Thu Feb 13 09:19:34 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()
{