Author: ssteiner Date: Thu Oct 11 14:59:30 2018 New Revision: 1843560 URL: http://svn.apache.org/viewvc?rev=1843560&view=rev Log: FOP-2821: 1 bit image fails when using PreloaderRawPNG
Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java xmlgraphics/fop/trunk/fop/lib/xmlgraphics-commons-svn-trunk.jar Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java?rev=1843560&r1=1843559&r2=1843560&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/AbstractImageAdapter.java Thu Oct 11 14:59:30 2018 @@ -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 AbstractImageAdapt 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) { Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java?rev=1843560&r1=1843559&r2=1843560&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/ImageRawPNGAdapterTestCase.java Thu Oct 11 14:59:30 2018 @@ -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 >>"); + } } Modified: xmlgraphics/fop/trunk/fop/lib/xmlgraphics-commons-svn-trunk.jar URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/lib/xmlgraphics-commons-svn-trunk.jar?rev=1843560&r1=1843559&r2=1843560&view=diff ============================================================================== Binary files - no diff available. --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org