]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2821: 1 bit image fails when using PreloaderRawPNG
authorSimon Steiner <ssteiner@apache.org>
Thu, 11 Oct 2018 14:59:30 +0000 (14:59 +0000)
committerSimon Steiner <ssteiner@apache.org>
Thu, 11 Oct 2018 14:59:30 +0000 (14:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1843560 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java
fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java
fop/lib/xmlgraphics-commons-svn-trunk.jar

index b835de61713ead63b59226a3a2feed5e2d2cf60f..c7e516a63d459891175c10b732cc8b53793f9a17 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawPNG;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
 import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 
@@ -281,12 +282,16 @@ public abstract class AbstractImageAdapter implements PDFImage {
 
         dict.put("ColorSpace", indexed);
 
-        Raster raster = ((ImageRendered)image).getRenderedImage().getTile(0, 0);
-        if (raster.getDataBuffer() instanceof DataBufferByte) {
-            dict.put("BitsPerComponent", icm.getPixelSize());
+        int bits = 8;
+        if (image instanceof ImageRawPNG) {
+            bits = ((ImageRawPNG) image).getBitDepth();
         } else {
-            dict.put("BitsPerComponent", 8);
+            Raster raster = ((ImageRendered) image).getRenderedImage().getTile(0, 0);
+            if (raster.getDataBuffer() instanceof DataBufferByte) {
+                bits = icm.getPixelSize();
+            }
         }
+        dict.put("BitsPerComponent", bits);
 
         Integer index = getIndexOfFirstTransparentColorInPalette(icm);
         if (index != null) {
index 9577e2e018d95dca77a34e57afb0e5afb3949051..c3b262477e55e3f37a69a9f2b77283e8da5b4f6b 100644 (file)
@@ -200,4 +200,18 @@ public class ImageRawPNGAdapterTestCase {
         PDFICCStream iccStream = irpnga.getICCStream();
         assertTrue(ColorProfileUtil.isDefaultsRGB(iccStream.getICCProfile()));
     }
+
+    @Test
+    public void test1BitPNG() throws IOException {
+        ImageRawPNG imageRawPNG = new ImageRawPNG(null, null,
+                new IndexColorModel(1, 1, new byte[3], 0, false), 1, null);
+        ImageRawPNGAdapter imageRawPNGAdapter = new ImageRawPNGAdapter(imageRawPNG, null);
+        PDFDocument pdfDocument = new PDFDocument("");
+        PDFDictionary pdfDictionary = new PDFDictionary();
+        pdfDictionary.setDocument(pdfDocument);
+        imageRawPNGAdapter.populateXObjectDictionary(pdfDictionary);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        pdfDictionary.output(bos);
+        assertEquals(bos.toString(), "<< /ColorSpace [/Indexed /DeviceGray 0 <00>] /BitsPerComponent 1 >>");
+    }
 }
index df873d2a4e9114b93e09b6350a9d882350cfbae9..a9e03e1a0a54120a901d1f24cea32f0c6935ea8a 100644 (file)
Binary files a/fop/lib/xmlgraphics-commons-svn-trunk.jar and b/fop/lib/xmlgraphics-commons-svn-trunk.jar differ