diff options
author | Luis Bernardo <lbernardo@apache.org> | 2012-10-20 23:50:15 +0000 |
---|---|---|
committer | Luis Bernardo <lbernardo@apache.org> | 2012-10-20 23:50:15 +0000 |
commit | 7627afcc96a1cdf5726e69d559a57b82dac8f0d4 (patch) | |
tree | 697df38c8de9628b2e51aa090901f55b31f97214 /src/java | |
parent | 9772267c98b4996a889fb8bb2e8b628e2026dd09 (diff) | |
download | xmlgraphics-fop-7627afcc96a1cdf5726e69d559a57b82dac8f0d4.tar.gz xmlgraphics-fop-7627afcc96a1cdf5726e69d559a57b82dac8f0d4.zip |
bugzilla #40676: patch 29132 with changes, support for sRGB and iCCP chunks
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1400536 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java | 48 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java | 39 |
2 files changed, 63 insertions, 24 deletions
diff --git a/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java b/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java index 46e8ebe95..2840ea1e3 100644 --- a/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java +++ b/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java @@ -88,11 +88,12 @@ public abstract class AbstractImageAdapter implements PDFImage { /** {@inheritDoc} */ public void setup(PDFDocument doc) { - ICC_Profile prof = getEffectiveICCProfile(); PDFDeviceColorSpace pdfCS = toPDFColorSpace(getImageColorSpace()); if (prof != null) { pdfICCStream = setupColorProfile(doc, prof, pdfCS); + } else if (issRGB()) { + pdfICCStream = setupsRGBColorProfile(doc); } if (doc.getProfile().getPDFAMode().isPDFA1LevelB()) { if (pdfCS != null @@ -116,6 +117,34 @@ public abstract class AbstractImageAdapter implements PDFImage { return image.getICCProfile(); } + protected boolean issRGB() { + return false; + } + + private static PDFICCStream getDefaultsRGBICCStream(PDFICCBasedColorSpace cs, PDFDocument doc, + String profileDesc) { + if (cs == null) { + if (profileDesc == null || !profileDesc.startsWith("sRGB")) { + log.warn("The default sRGB profile was indicated," + + " but the profile description does not match what was expected: " + + profileDesc); + } + //It's the default sRGB profile which we mapped to DefaultRGB in PDFRenderer + cs = (PDFICCBasedColorSpace)doc.getResources().getColorSpace(new PDFName("DefaultRGB")); + } + if (cs == null) { + // sRGB hasn't been set up for the PDF document + // so install but don't set to DefaultRGB + cs = PDFICCBasedColorSpace.setupsRGBColorSpace(doc); + } + return cs.getICCStream(); + } + + private static PDFICCStream setupsRGBColorProfile(PDFDocument doc) { + PDFICCBasedColorSpace cs = doc.getResources().getICCColorSpaceByProfileName("sRGB"); + return getDefaultsRGBICCStream(cs, doc, "sRGB"); + } + private static PDFICCStream setupColorProfile(PDFDocument doc, ICC_Profile prof, PDFDeviceColorSpace pdfCS) { boolean defaultsRGB = ColorProfileUtil.isDefaultsRGB(prof); @@ -134,22 +163,7 @@ public abstract class AbstractImageAdapter implements PDFImage { pdfICCStream = cs.getICCStream(); } } else { - if (cs == null) { - if (desc == null || !desc.startsWith("sRGB")) { - log.warn("The default sRGB profile was indicated," - + " but the profile description does not match what was expected: " - + desc); - } - //It's the default sRGB profile which we mapped to DefaultRGB in PDFRenderer - cs = (PDFICCBasedColorSpace)doc.getResources().getColorSpace( - new PDFName("DefaultRGB")); - } - if (cs == null) { - // sRGB hasn't been set up for the PDF document - // so install but don't set to DefaultRGB - cs = PDFICCBasedColorSpace.setupsRGBColorSpace(doc); - } - pdfICCStream = cs.getICCStream(); + pdfICCStream = getDefaultsRGBICCStream(cs, doc, desc); } return pdfICCStream; } diff --git a/src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java b/src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java index b9f5e1d28..9742036b7 100644 --- a/src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java +++ b/src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java @@ -49,7 +49,7 @@ import org.apache.fop.pdf.PDFDocument; import org.apache.fop.pdf.PDFFilter;
import org.apache.fop.pdf.PDFFilterException;
import org.apache.fop.pdf.PDFFilterList;
-import org.apache.fop.pdf.PDFICCStream;
+import org.apache.fop.pdf.PDFName;
import org.apache.fop.pdf.PDFReference;
public class ImageRawPNGAdapter extends AbstractImageAdapter {
@@ -57,7 +57,11 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter { /** logging instance */
private static Log log = LogFactory.getLog(ImageRawPNGAdapter.class);
- private PDFICCStream pdfICCStream;
+ private static final PDFName RI_PERCEPTUAL = new PDFName("Perceptual");
+ private static final PDFName RI_RELATIVE_COLORIMETRIC = new PDFName("RelativeColorimetric");
+ private static final PDFName RI_SATURATION = new PDFName("Saturation");
+ private static final PDFName RI_ABSOLUTE_COLORIMETRIC = new PDFName("AbsoluteColorimetric");
+
private PDFFilter pdfFilter;
private String maskRef;
private PDFReference softMask;
@@ -241,20 +245,41 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter { }
/** {@inheritDoc} */
- public PDFICCStream getICCStream() {
- return pdfICCStream;
- }
-
- /** {@inheritDoc} */
public String getFilterHint() {
return PDFFilterList.PRECOMPRESSED_FILTER;
}
public void populateXObjectDictionary(PDFDictionary dict) {
+ int renderingIntent = ((ImageRawPNG) image).getRenderingIntent();
+ if (renderingIntent != -1) {
+ switch (renderingIntent) {
+ case 0:
+ dict.put("Intent", RI_PERCEPTUAL);
+ break;
+ case 1:
+ dict.put("Intent", RI_RELATIVE_COLORIMETRIC);
+ break;
+ case 2:
+ dict.put("Intent", RI_SATURATION);
+ break;
+ case 3:
+ dict.put("Intent", RI_ABSOLUTE_COLORIMETRIC);
+ break;
+ default:
+ // ignore
+ }
+ }
ColorModel cm = ((ImageRawPNG) image).getColorModel();
if (cm instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel) cm;
super.populateXObjectDictionaryForIndexColorModel(dict, icm);
}
}
+
+ protected boolean issRGB() {
+ if (((ImageRawPNG) image).getRenderingIntent() != -1) {
+ return true;
+ }
+ return false;
+ }
}
|