aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorMehdi Houshmand <mehdi@apache.org>2012-08-28 15:08:23 +0000
committerMehdi Houshmand <mehdi@apache.org>2012-08-28 15:08:23 +0000
commit008bf019ad96ab80f1b8b1897180e30dd3c56925 (patch)
treeca349d363132404b2e823bbb0361e7d5422d972a /src/java/org
parent488c642a7a872f15bf0ae2b5d29f0746e181eca6 (diff)
downloadxmlgraphics-fop-008bf019ad96ab80f1b8b1897180e30dd3c56925.tar.gz
xmlgraphics-fop-008bf019ad96ab80f1b8b1897180e30dd3c56925.zip
Bugzilla#53790: Prevented the TIFF configurator from overriding the Bitmap configurator unless CCITT compression is enabled.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1378163 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java2
-rw-r--r--src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java23
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFCompressionValue.java98
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFCompressionValues.java61
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFRenderer.java40
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFRendererConfig.java11
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java37
7 files changed, 157 insertions, 115 deletions
diff --git a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
index 262caa53b..8d0ce14ac 100644
--- a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
+++ b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
@@ -84,7 +84,7 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin
super(context);
//Set target resolution
int dpi = Math.round(context.getUserAgent().getTargetResolution());
- getSettings().getWriterParams().setResolution(dpi);
+ getSettings().setResolution(dpi);
Map renderingOptions = getUserAgent().getRendererOptions();
setTargetBitmapSize((Dimension)renderingOptions.get(TARGET_BITMAP_SIZE));
diff --git a/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java b/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
index d239fe0fd..4363f1d5e 100644
--- a/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
+++ b/src/java/org/apache/fop/render/bitmap/BitmapRenderingSettings.java
@@ -107,4 +107,27 @@ public class BitmapRenderingSettings extends Java2DRenderingSettings {
return this.qualityRendering;
}
+ /**
+ * Sets the compression method for the image writer.
+ * @param compressionMethod the compression method name
+ */
+ public void setCompressionMethod(String compressionMethod) {
+ writerParams.setCompressionMethod(compressionMethod);
+ }
+
+ /**
+ * Returns the compression method being used by the image writer.
+ * @return the compression method in use
+ */
+ public String getCompressionMethod() {
+ return writerParams.getCompressionMethod();
+ }
+
+ /**
+ * Sets the resolution of the output image.
+ * @param dpi the dots-per-inch of the image
+ */
+ public void setResolution(int dpi) {
+ writerParams.setResolution(dpi);
+ }
}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFCompressionValue.java b/src/java/org/apache/fop/render/bitmap/TIFFCompressionValue.java
new file mode 100644
index 000000000..4e9c3bd26
--- /dev/null
+++ b/src/java/org/apache/fop/render/bitmap/TIFFCompressionValue.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.bitmap;
+
+import java.awt.image.BufferedImage;
+
+/**
+ * Compression constants for TIFF image output.
+ */
+public enum TIFFCompressionValue {
+ /** No compression */
+ NONE("NONE"),
+ /** JPEG compression */
+ JPEG("JPEG"),
+ /** Packbits (RLE) compression */
+ PACKBITS("PackBits"),
+ /** Deflate compression */
+ DEFLATE("Deflate"),
+ /** LZW compression */
+ LZW("LZW"),
+ /** ZLib compression */
+ ZLIB("ZLib"),
+ /** CCITT Group 3 (T.4) compression */
+ CCITT_T4("CCITT T.4", BufferedImage.TYPE_BYTE_BINARY, true),
+ /** CCITT Group 4 (T.6) compression */
+ CCITT_T6("CCITT T.6", BufferedImage.TYPE_BYTE_BINARY, true);
+
+ private final String name;
+ private final int imageType;
+ private boolean isCcitt;
+
+ private TIFFCompressionValue(String name, int imageType, boolean isCcitt) {
+ this.name = name;
+ this.imageType = imageType;
+ this.isCcitt = isCcitt;
+ }
+
+ private TIFFCompressionValue(String name) {
+ this(name, BufferedImage.TYPE_INT_ARGB, false);
+ }
+
+ /**
+ * Returns the name of this compression type.
+ * @return the compression name
+ */
+ String getName() {
+ return name;
+ }
+
+ /**
+ * Returns an image type for this compression type, a constant from {@link BufferedImage} e.g.
+ * {@link BufferedImage#TYPE_INT_ARGB} for {@link #ZLIB}
+ * @return the image type
+ */
+ int getImageType() {
+ return imageType;
+ }
+
+ /**
+ * Returns whether or not this compression type is a CCITT type.
+ * @return true if the compression type is CCITT
+ */
+ boolean hasCCITTCompression() {
+ return isCcitt;
+ }
+
+ /**
+ * Return the TIFF compression constant given the string representing the type. In the case that
+ * the name doesn't match any of the compression values, <code>null</code> is returned.
+ * @param name the compression type name
+ * @return the compression constant
+ */
+ static TIFFCompressionValue getType(String name) {
+ for (TIFFCompressionValue tiffConst : TIFFCompressionValue.values()) {
+ if (tiffConst.name.equalsIgnoreCase(name)) {
+ return tiffConst;
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFCompressionValues.java b/src/java/org/apache/fop/render/bitmap/TIFFCompressionValues.java
deleted file mode 100644
index 71649022e..000000000
--- a/src/java/org/apache/fop/render/bitmap/TIFFCompressionValues.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.bitmap;
-
-/**
- * Constants for TIFF output.
- */
-public enum TIFFCompressionValues {
- /** No compression */
- NONE("NONE"),
- /** JPEG compression */
- JPEG("JPEG"),
- /** Packbits (RLE) compression */
- PACKBITS("PackBits"),
- /** Deflate compression */
- DEFLATE("Deflate"),
- /** LZW compression */
- LZW("LZW"),
- /** ZLib compression */
- ZLIB("ZLib"),
- /** CCITT Group 4 (T.6) compression */
- CCITT_T6("CCITT T.6"), //CCITT Group 4
- /** CCITT Group 3 (T.4) compression */
- CCITT_T4("CCITT T.4"); //CCITT Group 3
-
- private final String name;
-
- private TIFFCompressionValues(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public static TIFFCompressionValues getValue(String name) {
- for (TIFFCompressionValues tiffConst : TIFFCompressionValues.values()) {
- if (tiffConst.name.equalsIgnoreCase(name)) {
- return tiffConst;
- }
- }
- return null;
- }
-}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
index 5b75a372c..48da62ef7 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
@@ -38,7 +38,6 @@ import org.apache.commons.logging.Log;
import org.apache.xmlgraphics.image.GraphicsUtil;
import org.apache.xmlgraphics.image.rendered.FormatRed;
import org.apache.xmlgraphics.image.writer.ImageWriter;
-import org.apache.xmlgraphics.image.writer.ImageWriterParams;
import org.apache.xmlgraphics.image.writer.ImageWriterRegistry;
import org.apache.xmlgraphics.image.writer.MultiImageWriter;
@@ -47,9 +46,9 @@ import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.java2d.Java2DRenderer;
-import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T4;
-import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T6;
-import static org.apache.fop.render.bitmap.TIFFCompressionValues.PACKBITS;
+import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T4;
+import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T6;
+import static org.apache.fop.render.bitmap.TIFFCompressionValue.PACKBITS;
/**
* <p>
@@ -74,11 +73,7 @@ import static org.apache.fop.render.bitmap.TIFFCompressionValues.PACKBITS;
*/
public class TIFFRenderer extends Java2DRenderer {
- /** ImageWriter parameters */
- private ImageWriterParams writerParams;
-
- /** Image Type as parameter for the BufferedImage constructor (see BufferedImage.TYPE_*) */
- private int bufferedImageType = BufferedImage.TYPE_INT_ARGB;
+ private BitmapRenderingSettings imageSettings;
private OutputStream outputStream;
@@ -94,11 +89,11 @@ public class TIFFRenderer extends Java2DRenderer {
*/
public TIFFRenderer(FOUserAgent userAgent) {
super(userAgent);
- writerParams = new ImageWriterParams();
- writerParams.setCompressionMethod(PACKBITS.getName());
-
+ imageSettings = new BitmapRenderingSettings();
+ imageSettings.setCompressionMethod(PACKBITS.getName());
+ imageSettings.setBufferedImageType(BufferedImage.TYPE_INT_ARGB);
int dpi = Math.round(userAgent.getTargetResolution());
- writerParams.setResolution(dpi);
+ imageSettings.setResolution(dpi);
}
/** {@inheritDoc} */
@@ -129,7 +124,7 @@ public class TIFFRenderer extends Java2DRenderer {
// Write all pages/images
while (pageImagesItr.hasNext()) {
RenderedImage img = (RenderedImage) pageImagesItr.next();
- multiWriter.writeImage(img, writerParams);
+ multiWriter.writeImage(img, imageSettings.getWriterParams());
}
} finally {
multiWriter.close();
@@ -139,7 +134,7 @@ public class TIFFRenderer extends Java2DRenderer {
if (pageImagesItr.hasNext()) {
renderedImage = (RenderedImage) pageImagesItr.next();
}
- writer.writeImage(renderedImage, outputStream, writerParams);
+ writer.writeImage(renderedImage, outputStream, imageSettings.getWriterParams());
if (pageImagesItr.hasNext()) {
BitmapRendererEventProducer eventProducer
= BitmapRendererEventProducer.Provider.get(
@@ -156,7 +151,7 @@ public class TIFFRenderer extends Java2DRenderer {
/** {@inheritDoc} */
protected BufferedImage getBufferedImage(int bitmapWidth, int bitmapHeight) {
- return new BufferedImage(bitmapWidth, bitmapHeight, bufferedImageType);
+ return new BufferedImage(bitmapWidth, bitmapHeight, imageSettings.getBufferedImageType());
}
/** Private inner class to lazy page rendering. */
@@ -195,7 +190,7 @@ public class TIFFRenderer extends Java2DRenderer {
throw new NoSuchElementException(e.getMessage());
}
- TIFFCompressionValues compression = TIFFCompressionValues.getValue(writerParams.getCompressionMethod());
+ TIFFCompressionValue compression = TIFFCompressionValue.getType(imageSettings.getCompressionMethod());
if (compression == CCITT_T4 || compression == CCITT_T6) {
return pageImage;
} else {
@@ -226,11 +221,14 @@ public class TIFFRenderer extends Java2DRenderer {
/** @param bufferedImageType an image type */
public void setBufferedImageType(int bufferedImageType) {
- this.bufferedImageType = bufferedImageType;
+ imageSettings.setBufferedImageType(bufferedImageType);
}
- /** @return image writer parameters */
- public ImageWriterParams getWriterParams() {
- return writerParams;
+ /**
+ * Returns the settings for the image rendering.
+ * @return the image rendering settings
+ */
+ public BitmapRenderingSettings getRenderingSettings() {
+ return imageSettings;
}
}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRendererConfig.java b/src/java/org/apache/fop/render/bitmap/TIFFRendererConfig.java
index 5417ecc1e..3c833d3b0 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRendererConfig.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRendererConfig.java
@@ -37,7 +37,7 @@ import org.apache.fop.render.RendererConfigOption;
public final class TIFFRendererConfig extends BitmapRendererConfig {
public enum TIFFRendererOption implements RendererConfigOption {
- COMPRESSION("compression", TIFFCompressionValues.PACKBITS);
+ COMPRESSION("compression", TIFFCompressionValue.PACKBITS);
private final String name;
private final Object defaultValue;
@@ -63,8 +63,8 @@ public final class TIFFRendererConfig extends BitmapRendererConfig {
super(fontConfig);
}
- public TIFFCompressionValues getCompressionType() {
- return (TIFFCompressionValues) params.get(TIFFRendererOption.COMPRESSION);
+ public TIFFCompressionValue getCompressionType() {
+ return (TIFFCompressionValue) params.get(TIFFRendererOption.COMPRESSION);
}
/**
@@ -92,9 +92,8 @@ public final class TIFFRendererConfig extends BitmapRendererConfig {
.parse(cfg, userAgent.validateStrictly()));
super.build(config, userAgent, cfg);
if (cfg != null) {
- setParam(TIFFRendererOption.COMPRESSION,
- TIFFCompressionValues.getValue(getValue(cfg,
- TIFFRendererOption.COMPRESSION)));
+ setParam(TIFFRendererOption.COMPRESSION,
+ TIFFCompressionValue.getType(getValue(cfg, TIFFRendererOption.COMPRESSION)));
}
return config;
}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java b/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
index b10f2a381..593934b45 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
@@ -19,13 +19,9 @@
package org.apache.fop.render.bitmap;
-import java.awt.image.BufferedImage;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.xmlgraphics.image.writer.ImageWriterParams;
-
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.Renderer;
@@ -33,9 +29,7 @@ import org.apache.fop.render.RendererConfig.RendererConfigParser;
import org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigParser;
import org.apache.fop.render.intermediate.IFDocumentHandler;
-import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T4;
-import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T6;
-import static org.apache.fop.render.bitmap.TIFFCompressionValues.NONE;
+import static org.apache.fop.render.bitmap.TIFFCompressionValue.NONE;
/**
* TIFF Renderer configurator
@@ -62,43 +56,34 @@ public class TIFFRendererConfigurator extends BitmapRendererConfigurator {
final TIFFRendererConfig config = (TIFFRendererConfig) getRendererConfig(renderer);
if (config != null) {
TIFFRenderer tiffRenderer = (TIFFRenderer) renderer;
- //set compression
- tiffRenderer.setBufferedImageType(getCompressionType(config, tiffRenderer.getWriterParams()));
+ setCompressionMethod(config.getCompressionType(), tiffRenderer.getRenderingSettings());
}
super.configure(renderer);
}
- private int getCompressionType(TIFFRendererConfig config, ImageWriterParams writerParms)
- throws FOPException {
- //Some compression formats need a special image format:
- TIFFCompressionValues compression = config.getCompressionType();
+ private void setCompressionMethod(TIFFCompressionValue compression,
+ BitmapRenderingSettings settings) throws FOPException {
if (compression != null) {
if (compression != NONE) {
- writerParms.setCompressionMethod(compression.getName());
+ settings.setCompressionMethod(compression.getName());
}
if (LOG.isInfoEnabled()) {
LOG.info("TIFF compression set to " + compression.getName());
}
- }
- return getBufferedImageTypeFor(compression);
- }
-
- private int getBufferedImageTypeFor(TIFFCompressionValues compressionType) {
- if (compressionType == CCITT_T6 || compressionType == CCITT_T4) {
- return BufferedImage.TYPE_BYTE_BINARY;
- } else {
- return BufferedImage.TYPE_INT_ARGB;
+ if (compression.hasCCITTCompression()) {
+ settings.setBufferedImageType(compression.getImageType());
+ }
}
}
/** {@inheritDoc} */
public void configure(IFDocumentHandler documentHandler) throws FOPException {
- final TIFFRendererConfig tiffConfig = (TIFFRendererConfig) getRendererConfig(documentHandler);
- if (tiffConfig != null) {
+ final TIFFRendererConfig config = (TIFFRendererConfig) getRendererConfig(documentHandler);
+ if (config != null) {
TIFFDocumentHandler tiffHandler = (TIFFDocumentHandler) documentHandler;
BitmapRenderingSettings settings = tiffHandler.getSettings();
configure(documentHandler, settings, new TIFFRendererConfigParser());
- settings.setBufferedImageType(getCompressionType(tiffConfig, settings.getWriterParams()));
+ setCompressionMethod(config.getCompressionType(), settings);
}
}