diff options
author | Simon Steiner <ssteiner@apache.org> | 2018-10-11 14:59:30 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2018-10-11 14:59:30 +0000 |
commit | 73f73dd5b1f4a9693d44d9b975dff293f92823ce (patch) | |
tree | 498deceb35591187bfcd39af17a9f3af6df3597e /fop-core | |
parent | c00d547a3828783284e3ca81ce90f62f5313d4ca (diff) | |
download | xmlgraphics-fop-73f73dd5b1f4a9693d44d9b975dff293f92823ce.tar.gz xmlgraphics-fop-73f73dd5b1f4a9693d44d9b975dff293f92823ce.zip |
FOP-2821: 1 bit image fails when using PreloaderRawPNG
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1843560 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r-- | fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java | 13 | ||||
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java | 14 |
2 files changed, 23 insertions, 4 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java index b835de617..c7e516a63 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java @@ -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) { diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java index 9577e2e01..c3b262477 100644 --- a/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java @@ -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 >>"); + } } |