From 514b49fd422e6b85164faa8c7cc169444b4ddab6 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 7 Feb 2011 08:28:41 +0000 Subject: [PATCH] Bugfix: Avoid directly encoding if the sample model is not exactly right. For example, monochrome image generated by JAI (error-diffusion rasterization) use a non-packed sample model which caused badly encoded images. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067878 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/afp/AFPImageHandlerRenderedImage.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java index ca0544542..c38af8fac 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java +++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java @@ -24,8 +24,10 @@ import java.awt.Rectangle; import java.awt.image.ColorModel; import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; +import java.awt.image.MultiPixelPackedSampleModel; import java.awt.image.Raster; import java.awt.image.RenderedImage; +import java.awt.image.SampleModel; import java.io.IOException; import java.io.OutputStream; @@ -254,6 +256,12 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima if (tiles > 1) { return false; } + SampleModel sampleModel = renderedImage.getSampleModel(); + SampleModel expectedSampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, + renderedImage.getWidth(), renderedImage.getHeight(), 1); + if (!expectedSampleModel.equals(sampleModel)) { + return false; //Pixels are not packed + } imageObjectInfo.setBitsPerPixel(1); @@ -290,6 +298,7 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler implements Ima } /** {@inheritDoc} */ + @Override protected AFPDataObjectInfo createDataObjectInfo() { return new AFPImageObjectInfo(); } -- 2.39.5