/** {@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
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);
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;
}
import org.apache.fop.pdf.PDFFilter;\r
import org.apache.fop.pdf.PDFFilterException;\r
import org.apache.fop.pdf.PDFFilterList;\r
-import org.apache.fop.pdf.PDFICCStream;\r
+import org.apache.fop.pdf.PDFName;\r
import org.apache.fop.pdf.PDFReference;\r
\r
public class ImageRawPNGAdapter extends AbstractImageAdapter {\r
/** logging instance */\r
private static Log log = LogFactory.getLog(ImageRawPNGAdapter.class);\r
\r
- private PDFICCStream pdfICCStream;\r
+ private static final PDFName RI_PERCEPTUAL = new PDFName("Perceptual");\r
+ private static final PDFName RI_RELATIVE_COLORIMETRIC = new PDFName("RelativeColorimetric");\r
+ private static final PDFName RI_SATURATION = new PDFName("Saturation");\r
+ private static final PDFName RI_ABSOLUTE_COLORIMETRIC = new PDFName("AbsoluteColorimetric");\r
+\r
private PDFFilter pdfFilter;\r
private String maskRef;\r
private PDFReference softMask;\r
}\r
}\r
\r
- /** {@inheritDoc} */\r
- public PDFICCStream getICCStream() {\r
- return pdfICCStream;\r
- }\r
-\r
/** {@inheritDoc} */\r
public String getFilterHint() {\r
return PDFFilterList.PRECOMPRESSED_FILTER;\r
}\r
\r
public void populateXObjectDictionary(PDFDictionary dict) {\r
+ int renderingIntent = ((ImageRawPNG) image).getRenderingIntent();\r
+ if (renderingIntent != -1) {\r
+ switch (renderingIntent) {\r
+ case 0:\r
+ dict.put("Intent", RI_PERCEPTUAL);\r
+ break;\r
+ case 1:\r
+ dict.put("Intent", RI_RELATIVE_COLORIMETRIC);\r
+ break;\r
+ case 2:\r
+ dict.put("Intent", RI_SATURATION);\r
+ break;\r
+ case 3:\r
+ dict.put("Intent", RI_ABSOLUTE_COLORIMETRIC);\r
+ break;\r
+ default:\r
+ // ignore\r
+ }\r
+ }\r
ColorModel cm = ((ImageRawPNG) image).getColorModel();\r
if (cm instanceof IndexColorModel) {\r
IndexColorModel icm = (IndexColorModel) cm;\r
super.populateXObjectDictionaryForIndexColorModel(dict, icm);\r
}\r
}\r
+\r
+ protected boolean issRGB() {\r
+ if (((ImageRawPNG) image).getRenderingIntent() != -1) {\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
}\r
package org.apache.fop.render.pdf;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_Profile;
import java.awt.image.ComponentColorModel;
import java.awt.image.IndexColorModel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import org.apache.xmlgraphics.image.loader.ImageSize;
import org.apache.xmlgraphics.image.loader.impl.ImageRawPNG;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
import org.apache.fop.pdf.FlateFilter;
import org.apache.fop.pdf.PDFAMode;
+import org.apache.fop.pdf.PDFDictionary;
import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFICCBasedColorSpace;
+import org.apache.fop.pdf.PDFICCStream;
+import org.apache.fop.pdf.PDFName;
import org.apache.fop.pdf.PDFProfile;
+import org.apache.fop.pdf.PDFResources;
import org.apache.fop.render.RawPNGTestUtil;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class ImageRawPNGAdapterTestCase {
@Test
ImageSize is = RawPNGTestUtil.getImageSize();
when(irpng.getColorModel()).thenReturn(cm);
+ when(irpng.getRenderingIntent()).thenReturn(-1);
// when(cm.hasAlpha()).thenReturn(false);
when(doc.getProfile()).thenReturn(profile);
when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
ImageSize is = RawPNGTestUtil.getImageSize();
when(irpng.getColorModel()).thenReturn(cm);
+ when(irpng.getRenderingIntent()).thenReturn(-1);
when(cm.getNumComponents()).thenReturn(3);
// when(cm.hasAlpha()).thenReturn(false);
when(doc.getProfile()).thenReturn(profile);
ImageSize is = RawPNGTestUtil.getImageSize();
when(irpng.getColorModel()).thenReturn(cm);
+ when(irpng.getRenderingIntent()).thenReturn(-1);
when(cm.getNumComponents()).thenReturn(numComponents);
// when(cm.hasAlpha()).thenReturn(false);
when(doc.getProfile()).thenReturn(profile);
}
}
+ @Test
+ public void testPopulateXObjectDictionaryWithComponentColorModelAndsRGB() {
+ ComponentColorModel cm = mock(ComponentColorModel.class);
+ ImageRawPNG irpng = mock(ImageRawPNG.class);
+ PDFDictionary pdfDic = mock(PDFDictionary.class);
+ ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
+
+ when(irpng.getColorModel()).thenReturn(cm);
+ when(irpng.getRenderingIntent()).thenReturn(0);
+ irpnga.populateXObjectDictionary(pdfDic);
+ verify(pdfDic).put("Intent", new PDFName("Perceptual"));
+ when(irpng.getRenderingIntent()).thenReturn(1);
+ irpnga.populateXObjectDictionary(pdfDic);
+ verify(pdfDic).put("Intent", new PDFName("RelativeColorimetric"));
+ when(irpng.getRenderingIntent()).thenReturn(2);
+ irpnga.populateXObjectDictionary(pdfDic);
+ verify(pdfDic).put("Intent", new PDFName("Saturation"));
+ when(irpng.getRenderingIntent()).thenReturn(3);
+ irpnga.populateXObjectDictionary(pdfDic);
+ verify(pdfDic).put("Intent", new PDFName("AbsoluteColorimetric"));
+ }
+
+ @Test
+ public void testRenderingIntentImpliessRGBColorProfile() {
+ ComponentColorModel cm = mock(ComponentColorModel.class);
+ ImageRawPNG irpng = mock(ImageRawPNG.class);
+ PDFDocument doc = mock(PDFDocument.class);
+ PDFProfile profile = mock(PDFProfile.class);
+ PDFResources resources = mock(PDFResources.class);
+ PDFICCBasedColorSpace cs = mock(PDFICCBasedColorSpace.class);
+ PDFICCStream stream = mock(PDFICCStream.class);
+ ICC_Profile iccprof = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
+ ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
+ ImageSize is = RawPNGTestUtil.getImageSize();
+
+ when(irpng.getColorModel()).thenReturn(cm);
+ when(irpng.getRenderingIntent()).thenReturn(0);
+ when(cm.getNumComponents()).thenReturn(3);
+ // when(cm.hasAlpha()).thenReturn(false);
+ when(doc.getProfile()).thenReturn(profile);
+ when(doc.getResources()).thenReturn(resources);
+ when(resources.getICCColorSpaceByProfileName("sRGB")).thenReturn(cs);
+ when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
+ when(irpng.getSize()).thenReturn(is);
+ when(cs.getICCStream()).thenReturn(stream);
+ when(stream.getICCProfile()).thenReturn(iccprof);
+
+ irpnga.setup(doc);
+ PDFICCStream iccStream = irpnga.getICCStream();
+ assertTrue(ColorProfileUtil.isDefaultsRGB(iccStream.getICCProfile()));
+ }
}