Skip to content

Commit 2af67b8

Browse files
committed
PDFBOX-5952: pass resources to be able to use resource cache during creation of ICC colorspace, as suggested by Andreas Lehmkühler
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1923774 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6eafc4e commit 2af67b8

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ else if (name == COSName.CALRGB)
181181
}
182182
else if (name == COSName.DEVICEN)
183183
{
184-
return new PDDeviceN(array);
184+
return new PDDeviceN(array, resources);
185185
}
186186
else if (name == COSName.INDEXED)
187187
{
188188
return new PDIndexed(array, resources);
189189
}
190190
else if (name == COSName.SEPARATION)
191191
{
192-
return new PDSeparation(array);
192+
return new PDSeparation(array, resources);
193193
}
194194
else if (name == COSName.ICCBASED)
195195
{

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceN.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.pdfbox.cos.COSDictionary;
3535
import org.apache.pdfbox.cos.COSName;
3636
import org.apache.pdfbox.cos.COSNull;
37+
import org.apache.pdfbox.pdmodel.PDResources;
3738
import org.apache.pdfbox.pdmodel.common.function.PDFunction;
3839

3940
/**
@@ -83,20 +84,21 @@ public PDDeviceN()
8384
* Creates a new DeviceN color space from the given COS array.
8485
*
8586
* @param deviceN an array containing the color space information
87+
* @param resources resources, can be null.
8688
*
8789
* @throws IOException if the colorspace could not be created
8890
*/
89-
public PDDeviceN(COSArray deviceN) throws IOException
91+
public PDDeviceN(COSArray deviceN, PDResources resources) throws IOException
9092
{
9193
array = deviceN;
92-
alternateColorSpace = PDColorSpace.create(array.getObject(ALTERNATE_CS));
94+
alternateColorSpace = PDColorSpace.create(array.getObject(ALTERNATE_CS), resources);
9395
tintTransform = PDFunction.create(array.getObject(TINT_TRANSFORM));
9496

9597
if (array.size() > DEVICEN_ATTRIBUTES)
9698
{
9799
attributes = new PDDeviceNAttributes((COSDictionary)array.getObject(DEVICEN_ATTRIBUTES));
98100
}
99-
initColorConversionCache();
101+
initColorConversionCache(resources);
100102

101103
// set initial color space
102104
int n = getNumberOfComponents();
@@ -105,8 +107,20 @@ public PDDeviceN(COSArray deviceN) throws IOException
105107
initialColor = new PDColor(initial, this);
106108
}
107109

110+
/**
111+
* Creates a new DeviceN color space from the given COS array.
112+
*
113+
* @param deviceN an array containing the color space information
114+
*
115+
* @throws IOException if the colorspace could not be created
116+
*/
117+
public PDDeviceN(COSArray deviceN) throws IOException
118+
{
119+
this(deviceN, null);
120+
}
121+
108122
// initializes the color conversion cache
109-
private void initColorConversionCache() throws IOException
123+
private void initColorConversionCache(PDResources resources) throws IOException
110124
{
111125
// there's nothing to cache for non-attribute spaces
112126
if (attributes == null)
@@ -124,7 +138,7 @@ private void initColorConversionCache() throws IOException
124138
{
125139
List<String> components = attributes.getProcess().getComponents();
126140

127-
// map each colorant to the corresponding process component (if any)
141+
// map each colorant name to the corresponding process component name (if any)
128142
for (int c = 0; c < numColorants; c++)
129143
{
130144
colorantToComponent[c] = components.indexOf(colorantNames.get(c));
@@ -145,7 +159,7 @@ private void initColorConversionCache() throws IOException
145159
spotColorSpaces = new PDSeparation[numColorants];
146160

147161
// spot color spaces
148-
Map<String, PDSeparation> spotColorants = attributes.getColorants();
162+
Map<String, PDSeparation> spotColorants = attributes.getColorants(resources);
149163

150164
// map each colorant to the corresponding spot color space
151165
for (int c = 0; c < numColorants; c++)

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceNAttributes.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.apache.logging.log4j.Logger;
2929
import org.apache.logging.log4j.LogManager;
30+
import org.apache.pdfbox.pdmodel.PDResources;
3031

3132
/**
3233
* Contains additional information about the components of colour space.
@@ -72,10 +73,11 @@ public COSDictionary getCOSDictionary()
7273

7374
/**
7475
* Returns a map of colorants and their associated Separation color space.
76+
* @param resources resources, can be null.
7577
* @return map of colorants to color spaces, never null.
7678
* @throws IOException If there is an error reading a color space
7779
*/
78-
public Map<String, PDSeparation> getColorants() throws IOException
80+
public Map<String, PDSeparation> getColorants(PDResources resources) throws IOException
7981
{
8082
Map<String,PDSeparation> actuals = new HashMap<>();
8183
COSDictionary colorants = dictionary.getCOSDictionary(COSName.COLORANTS);
@@ -89,12 +91,22 @@ public Map<String, PDSeparation> getColorants() throws IOException
8991
for (COSName name : colorants.keySet())
9092
{
9193
COSBase value = colorants.getDictionaryObject(name);
92-
actuals.put(name.getName(), (PDSeparation) PDColorSpace.create(value));
94+
actuals.put(name.getName(), (PDSeparation) PDColorSpace.create(value, resources));
9395
}
9496
}
9597
return new COSDictionaryMap<>(actuals, colorants);
9698
}
9799

100+
/**
101+
* Returns a map of colorants and their associated Separation color space.
102+
* @return map of colorants to color spaces, never null.
103+
* @throws IOException If there is an error reading a color space
104+
*/
105+
public Map<String, PDSeparation> getColorants() throws IOException
106+
{
107+
return getColorants(null);
108+
}
109+
98110
/**
99111
* Returns the DeviceN Process Dictionary, or null if it is missing.
100112
* @return the DeviceN Process Dictionary, or null if it is missing.

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDSeparation.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.pdfbox.cos.COSBase;
3131
import org.apache.pdfbox.cos.COSName;
3232
import org.apache.pdfbox.cos.COSNull;
33+
import org.apache.pdfbox.pdmodel.PDResources;
3334
import org.apache.pdfbox.pdmodel.common.function.PDFunction;
3435

3536
/**
@@ -78,12 +79,13 @@ public PDSeparation()
7879
/**
7980
* Creates a new Separation color space from a PDF color space array.
8081
* @param separation an array containing all separation information.
82+
* @param resources resources, can be null.
8183
* @throws IOException if the color space or the function could not be created.
8284
*/
83-
public PDSeparation(COSArray separation) throws IOException
85+
public PDSeparation(COSArray separation, PDResources resources) throws IOException
8486
{
8587
array = separation;
86-
alternateColorSpace = PDColorSpace.create(array.getObject(ALTERNATE_CS));
88+
alternateColorSpace = PDColorSpace.create(array.getObject(ALTERNATE_CS), resources);
8789
tintTransform = PDFunction.create(array.getObject(TINT_TRANSFORM));
8890
int numberOfOutputParameters = tintTransform.getNumberOfOutputParameters();
8991
if (numberOfOutputParameters > 0 &&
@@ -95,6 +97,16 @@ public PDSeparation(COSArray separation) throws IOException
9597
}
9698
}
9799

100+
/**
101+
* Creates a new Separation color space from a PDF color space array.
102+
* @param separation an array containing all separation information.
103+
* @throws IOException if the color space or the function could not be created.
104+
*/
105+
public PDSeparation(COSArray separation) throws IOException
106+
{
107+
this(separation, null);
108+
}
109+
98110
@Override
99111
public String getName()
100112
{

0 commit comments

Comments
 (0)