Author: jeremias
Date: Fri Feb 1 08:02:33 2008
New Revision: 617531
URL: http://svn.apache.org/viewvc?rev=617531&view=rev
Log:
Move sRGB installation into the PDF library. That way it can be used in
PDFDocumentGraphics2D, too (via AbstractImageAdapter).
Ensures correct handling of sRGB images in PDFTranscoder.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java?rev=617531&r1=617530&r2=617531&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
Fri Feb 1 08:02:33 2008
@@ -19,6 +19,13 @@
package org.apache.fop.pdf;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+
/**
* Represents an ICCBased color space in PDF.
*/
@@ -93,4 +100,56 @@
return sb.toString();
}
+ /**
+ * Sets sRGB as the DefaultRGB color space in the PDF document.
+ * @param pdfDoc the PDF document
+ * @return the newly installed color space object
+ */
+ public static PDFICCBasedColorSpace
setupsRGBAsDefaultRGBColorSpace(PDFDocument pdfDoc) {
+ PDFICCStream sRGBProfile = setupsRGBColorProfile(pdfDoc);
+
+ //Map sRGB as default RGB profile for DeviceRGB
+ return pdfDoc.getFactory().makeICCBasedColorSpace(null, "DefaultRGB",
sRGBProfile);
+ }
+
+ /**
+ * Installs the sRGB color space in the PDF document.
+ * @param pdfDoc the PDF document
+ * @return the newly installed color space object
+ */
+ public static PDFICCBasedColorSpace setupsRGBColorSpace(PDFDocument
pdfDoc) {
+ PDFICCStream sRGBProfile = setupsRGBColorProfile(pdfDoc);
+
+ //Map sRGB as default RGB profile for DeviceRGB
+ return pdfDoc.getFactory().makeICCBasedColorSpace(null, null,
sRGBProfile);
+ }
+
+ /**
+ * Sets up the sRGB color profile in the PDF document. It does so by
trying to
+ * install a very small ICC profile (~4KB) instead of the very big one
(~140KB)
+ * the Sun JVM uses.
+ * @param pdfDoc the PDF document
+ * @return the ICC stream with the sRGB profile
+ */
+ public static PDFICCStream setupsRGBColorProfile(PDFDocument pdfDoc) {
+ ICC_Profile profile;
+ PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
+ InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color
Space Profile.icm");
+ if (in != null) {
+ try {
+ profile = ICC_Profile.getInstance(in);
+ } catch (IOException ioe) {
+ throw new RuntimeException(
+ "Unexpected IOException loading the sRGB profile: " +
ioe.getMessage());
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ } else {
+ // Fallback: Use the sRGB profile from the JRE (about 140KB)
+ profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
+ }
+ sRGBProfile.setColorSpace(profile, null);
+ return sRGBProfile;
+ }
+
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java?rev=617531&r1=617530&r2=617531&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
Fri Feb 1 08:02:33 2008
@@ -84,32 +84,7 @@
ICC_Profile prof = image.getICCProfile();
PDFDeviceColorSpace pdfCS = toPDFColorSpace(getImageColorSpace());
if (prof != null) {
- boolean defaultsRGB = ColorProfileUtil.isDefaultsRGB(prof);
- String desc = ColorProfileUtil.getICCProfileDescription(prof);
- if (log.isDebugEnabled()) {
- log.debug("Image returns ICC profile: " + desc + ", default
sRGB=" + defaultsRGB);
- }
- PDFICCBasedColorSpace cs =
doc.getResources().getICCColorSpaceByProfileName(desc);
- if (!defaultsRGB) {
- if (cs == null) {
- pdfICCStream = doc.getFactory().makePDFICCStream();
- pdfICCStream.setColorSpace(prof, pdfCS);
- cs = doc.getFactory().makeICCBasedColorSpace(null, null,
pdfICCStream);
- } else {
- pdfICCStream = cs.getICCStream();
- }
- } else {
- if (cs == null && desc.startsWith("sRGB")) {
- //It's the default sRGB profile which we mapped to
DefaultRGB in PDFRenderer
- cs = doc.getResources().getColorSpace("DefaultRGB");
- }
- if (cs != null) {
- pdfICCStream = cs.getICCStream();
- } else {
- //DefaultRGB hasn't been mapped to sRGB
- //(that's the case with a plain PDFGraphics2D)
- }
- }
+ pdfICCStream = setupColorProfile(doc, prof, pdfCS);
}
if (doc.getProfile().getPDFAMode().isPDFA1LevelB()) {
if (pdfCS != null
@@ -119,10 +94,42 @@
//See PDF/A-1, ISO 19005:1:2005(E), 6.2.3.3
//FOP is currently restricted to DeviceRGB if PDF/A-1 is
active.
throw new PDFConformanceException(
- "PDF/A-1 does not allow mixing DeviceRGB and
DeviceCMYK: "
- + image.getInfo());
+ "PDF/A-1 does not allow mixing DeviceRGB and
DeviceCMYK: "
+ + image.getInfo());
+ }
+ }
+ }
+
+ private static PDFICCStream setupColorProfile(PDFDocument doc,
+ ICC_Profile prof, PDFDeviceColorSpace pdfCS) {
+ boolean defaultsRGB = ColorProfileUtil.isDefaultsRGB(prof);
+ String desc = ColorProfileUtil.getICCProfileDescription(prof);
+ if (log.isDebugEnabled()) {
+ log.debug("Image returns ICC profile: " + desc + ", default sRGB="
+ defaultsRGB);
+ }
+ PDFICCBasedColorSpace cs =
doc.getResources().getICCColorSpaceByProfileName(desc);
+ PDFICCStream pdfICCStream;
+ if (!defaultsRGB) {
+ if (cs == null) {
+ pdfICCStream = doc.getFactory().makePDFICCStream();
+ pdfICCStream.setColorSpace(prof, pdfCS);
+ cs = doc.getFactory().makeICCBasedColorSpace(null, null,
pdfICCStream);
+ } else {
+ pdfICCStream = cs.getICCStream();
+ }
+ } else {
+ if (cs == null && desc.startsWith("sRGB")) {
+ //It's the default sRGB profile which we mapped to DefaultRGB
in PDFRenderer
+ cs = doc.getResources().getColorSpace("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();
}
+ return pdfICCStream;
}
/** [EMAIL PROTECTED] */
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=617531&r1=617530&r2=617531&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
Fri Feb 1 08:02:33 2008
@@ -23,7 +23,6 @@
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
-import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
@@ -391,24 +390,8 @@
if (this.sRGBColorSpace != null) {
return;
}
- ICC_Profile profile;
- PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
- InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color
Space Profile.icm");
- if (in != null) {
- try {
- profile = ICC_Profile.getInstance(in);
- } finally {
- IOUtils.closeQuietly(in);
- }
- } else {
- //Fallback: Use the sRGB profile from the JRE (about 140KB)
- profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
- }
- sRGBProfile.setColorSpace(profile, null);
-
//Map sRGB as default RGB profile for DeviceRGB
- this.sRGBColorSpace = pdfDoc.getFactory().makeICCBasedColorSpace(
- null, "DefaultRGB", sRGBProfile);
+ this.sRGBColorSpace =
PDFICCBasedColorSpace.setupsRGBAsDefaultRGBColorSpace(pdfDoc);
}
private void addDefaultOutputProfile() throws IOException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]