Lines 19-47
Link Here
|
19 |
|
19 |
|
20 |
package org.apache.fop.render.pdf; |
20 |
package org.apache.fop.render.pdf; |
21 |
|
21 |
|
|
|
22 |
import java.awt.color.ColorSpace; |
23 |
import java.awt.color.ICC_Profile; |
22 |
import java.awt.image.ComponentColorModel; |
24 |
import java.awt.image.ComponentColorModel; |
23 |
import java.awt.image.IndexColorModel; |
25 |
import java.awt.image.IndexColorModel; |
24 |
import java.io.ByteArrayInputStream; |
26 |
import java.io.ByteArrayInputStream; |
25 |
import java.io.ByteArrayOutputStream; |
27 |
import java.io.ByteArrayOutputStream; |
26 |
import java.io.IOException; |
28 |
import java.io.IOException; |
27 |
import java.util.zip.Deflater; |
|
|
28 |
import java.util.zip.DeflaterOutputStream; |
29 |
|
29 |
|
30 |
import org.junit.Test; |
30 |
import org.junit.Test; |
31 |
|
31 |
|
32 |
import org.apache.xmlgraphics.image.loader.ImageSize; |
32 |
import org.apache.xmlgraphics.image.loader.ImageSize; |
33 |
import org.apache.xmlgraphics.image.loader.impl.ImageRawPNG; |
33 |
import org.apache.xmlgraphics.image.loader.impl.ImageRawPNG; |
|
|
34 |
import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil; |
34 |
|
35 |
|
35 |
import org.apache.fop.pdf.FlateFilter; |
36 |
import org.apache.fop.pdf.FlateFilter; |
36 |
import org.apache.fop.pdf.PDFAMode; |
37 |
import org.apache.fop.pdf.PDFAMode; |
|
|
38 |
import org.apache.fop.pdf.PDFDictionary; |
37 |
import org.apache.fop.pdf.PDFDocument; |
39 |
import org.apache.fop.pdf.PDFDocument; |
|
|
40 |
import org.apache.fop.pdf.PDFICCBasedColorSpace; |
41 |
import org.apache.fop.pdf.PDFICCStream; |
42 |
import org.apache.fop.pdf.PDFName; |
38 |
import org.apache.fop.pdf.PDFProfile; |
43 |
import org.apache.fop.pdf.PDFProfile; |
|
|
44 |
import org.apache.fop.pdf.PDFResources; |
39 |
import org.apache.fop.render.RawPNGTestUtil; |
45 |
import org.apache.fop.render.RawPNGTestUtil; |
40 |
|
46 |
|
41 |
import static org.junit.Assert.assertArrayEquals; |
47 |
import static org.junit.Assert.assertArrayEquals; |
42 |
import static org.junit.Assert.assertEquals; |
48 |
import static org.junit.Assert.assertEquals; |
|
|
49 |
import static org.junit.Assert.assertTrue; |
43 |
|
50 |
|
44 |
import static org.mockito.Mockito.mock; |
51 |
import static org.mockito.Mockito.mock; |
|
|
52 |
import static org.mockito.Mockito.verify; |
45 |
import static org.mockito.Mockito.when; |
53 |
import static org.mockito.Mockito.when; |
46 |
|
54 |
|
47 |
public class ImageRawPNGAdapterTestCase { |
55 |
public class ImageRawPNGAdapterTestCase { |
Lines 56-61
Link Here
|
56 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
64 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
57 |
|
65 |
|
58 |
when(irpng.getColorModel()).thenReturn(cm); |
66 |
when(irpng.getColorModel()).thenReturn(cm); |
|
|
67 |
when(irpng.getRenderingIntent()).thenReturn(-1); |
59 |
// when(cm.hasAlpha()).thenReturn(false); |
68 |
// when(cm.hasAlpha()).thenReturn(false); |
60 |
when(doc.getProfile()).thenReturn(profile); |
69 |
when(doc.getProfile()).thenReturn(profile); |
61 |
when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A); |
70 |
when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A); |
Lines 75-80
Link Here
|
75 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
84 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
76 |
|
85 |
|
77 |
when(irpng.getColorModel()).thenReturn(cm); |
86 |
when(irpng.getColorModel()).thenReturn(cm); |
|
|
87 |
when(irpng.getRenderingIntent()).thenReturn(-1); |
78 |
when(cm.getNumComponents()).thenReturn(3); |
88 |
when(cm.getNumComponents()).thenReturn(3); |
79 |
// when(cm.hasAlpha()).thenReturn(false); |
89 |
// when(cm.hasAlpha()).thenReturn(false); |
80 |
when(doc.getProfile()).thenReturn(profile); |
90 |
when(doc.getProfile()).thenReturn(profile); |
Lines 117-122
Link Here
|
117 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
127 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
118 |
|
128 |
|
119 |
when(irpng.getColorModel()).thenReturn(cm); |
129 |
when(irpng.getColorModel()).thenReturn(cm); |
|
|
130 |
when(irpng.getRenderingIntent()).thenReturn(-1); |
120 |
when(cm.getNumComponents()).thenReturn(numComponents); |
131 |
when(cm.getNumComponents()).thenReturn(numComponents); |
121 |
// when(cm.hasAlpha()).thenReturn(false); |
132 |
// when(cm.hasAlpha()).thenReturn(false); |
122 |
when(doc.getProfile()).thenReturn(profile); |
133 |
when(doc.getProfile()).thenReturn(profile); |
Lines 139-142
Link Here
|
139 |
} |
150 |
} |
140 |
} |
151 |
} |
141 |
|
152 |
|
|
|
153 |
@Test |
154 |
public void testPopulateXObjectDictionaryWithComponentColorModelAndsRGB() { |
155 |
ComponentColorModel cm = mock(ComponentColorModel.class); |
156 |
ImageRawPNG irpng = mock(ImageRawPNG.class); |
157 |
PDFDictionary pdfDic = mock(PDFDictionary.class); |
158 |
ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock"); |
159 |
|
160 |
when(irpng.getColorModel()).thenReturn(cm); |
161 |
when(irpng.getRenderingIntent()).thenReturn(0); |
162 |
irpnga.populateXObjectDictionary(pdfDic); |
163 |
verify(pdfDic).put("Intent", new PDFName("Perceptual")); |
164 |
when(irpng.getRenderingIntent()).thenReturn(1); |
165 |
irpnga.populateXObjectDictionary(pdfDic); |
166 |
verify(pdfDic).put("Intent", new PDFName("RelativeColorimetric")); |
167 |
when(irpng.getRenderingIntent()).thenReturn(2); |
168 |
irpnga.populateXObjectDictionary(pdfDic); |
169 |
verify(pdfDic).put("Intent", new PDFName("Saturation")); |
170 |
when(irpng.getRenderingIntent()).thenReturn(3); |
171 |
irpnga.populateXObjectDictionary(pdfDic); |
172 |
verify(pdfDic).put("Intent", new PDFName("AbsoluteColorimetric")); |
173 |
} |
174 |
|
175 |
@Test |
176 |
public void testRenderingIntentImpliessRGBColorProfile() { |
177 |
ComponentColorModel cm = mock(ComponentColorModel.class); |
178 |
ImageRawPNG irpng = mock(ImageRawPNG.class); |
179 |
PDFDocument doc = mock(PDFDocument.class); |
180 |
PDFProfile profile = mock(PDFProfile.class); |
181 |
PDFResources resources = mock(PDFResources.class); |
182 |
PDFICCBasedColorSpace cs = mock(PDFICCBasedColorSpace.class); |
183 |
PDFICCStream stream = mock(PDFICCStream.class); |
184 |
ICC_Profile iccprof = ICC_Profile.getInstance(ColorSpace.CS_sRGB); |
185 |
ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock"); |
186 |
ImageSize is = RawPNGTestUtil.getImageSize(); |
187 |
|
188 |
when(irpng.getColorModel()).thenReturn(cm); |
189 |
when(irpng.getRenderingIntent()).thenReturn(0); |
190 |
when(cm.getNumComponents()).thenReturn(3); |
191 |
// when(cm.hasAlpha()).thenReturn(false); |
192 |
when(doc.getProfile()).thenReturn(profile); |
193 |
when(doc.getResources()).thenReturn(resources); |
194 |
when(resources.getICCColorSpaceByProfileName("sRGB")).thenReturn(cs); |
195 |
when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A); |
196 |
when(irpng.getSize()).thenReturn(is); |
197 |
when(cs.getICCStream()).thenReturn(stream); |
198 |
when(stream.getICCProfile()).thenReturn(iccprof); |
199 |
|
200 |
irpnga.setup(doc); |
201 |
PDFICCStream iccStream = irpnga.getICCStream(); |
202 |
assertTrue(ColorProfileUtil.isDefaultsRGB(iccStream.getICCProfile())); |
203 |
} |
142 |
} |
204 |
} |