git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1378163 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
@@ -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)); |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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; | |||
} |
@@ -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); | |||
} | |||
} | |||
@@ -62,6 +62,10 @@ | |||
documents. Example: the fix of marks layering will be such a case when it's done. | |||
--> | |||
<release version="FOP Trunk" date="TBD"> | |||
<action context="Renderers" dev="MH" type="fix" fixes-bug="53790"> | |||
Prevented the TIFF configurator from overriding the Bitmap configurator unless CCITT | |||
compression is enabled. | |||
</action> | |||
<action context="Renderers" dev="MH" type="fix" fixes-bug="53786"> | |||
Removed the Attribute Qualifier on TLEs as they aren't used. | |||
</action> |
@@ -0,0 +1,77 @@ | |||
/* | |||
* 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. | |||
*/ | |||
package org.apache.fop.render.bitmap; | |||
import java.awt.image.BufferedImage; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
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.DEFLATE; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.JPEG; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.LZW; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.NONE; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.PACKBITS; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.ZLIB; | |||
public class TIFFCompressionValueTestCase { | |||
@Test | |||
public void testGetName() { | |||
testCompressionName("NONE", NONE); | |||
testCompressionName("JPEG", JPEG); | |||
testCompressionName("PackBits", PACKBITS); | |||
testCompressionName("Deflate", DEFLATE); | |||
testCompressionName("LZW", LZW); | |||
testCompressionName("ZLib", ZLIB); | |||
testCompressionName("CCITT T.4", CCITT_T4); | |||
testCompressionName("CCITT T.6", CCITT_T6); | |||
} | |||
private void testCompressionName(String name, TIFFCompressionValue expected) { | |||
assertEquals(name, expected.getName()); | |||
assertEquals(expected, TIFFCompressionValue.getType(name)); | |||
} | |||
@Test | |||
public void testGetImageType() { | |||
for (TIFFCompressionValue value : TIFFCompressionValue.values()) { | |||
if (value == CCITT_T4 || value == CCITT_T6) { | |||
assertEquals(BufferedImage.TYPE_BYTE_BINARY, value.getImageType()); | |||
} else { | |||
assertEquals(BufferedImage.TYPE_INT_ARGB, value.getImageType()); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testHasCCITTCompression() { | |||
for (TIFFCompressionValue value : TIFFCompressionValue.values()) { | |||
if (value == CCITT_T4 || value == CCITT_T6) { | |||
assertTrue(value.hasCCITTCompression()); | |||
} else { | |||
assertFalse(value.hasCCITTCompression()); | |||
} | |||
} | |||
} | |||
} |
@@ -47,7 +47,7 @@ public class TIFFRendererConfigParserTestCase | |||
@Test | |||
public void testCompression() throws Exception { | |||
for (TIFFCompressionValues value : TIFFCompressionValues.values()) { | |||
for (TIFFCompressionValue value : TIFFCompressionValue.values()) { | |||
parseConfig(createRenderer().setCompressionMode(value.getName())); | |||
assertEquals(value, getConfig().getCompressionType()); | |||
} |
@@ -23,14 +23,15 @@ import java.awt.image.BufferedImage; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import org.apache.fop.apps.FopConfBuilder; | |||
import org.apache.fop.apps.MimeConstants; | |||
import org.apache.fop.apps.TIFFRendererConfBuilder; | |||
import org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigParser; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T4; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValues.CCITT_T6; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T4; | |||
import static org.apache.fop.render.bitmap.TIFFCompressionValue.CCITT_T6; | |||
public class TIFFRendererConfiguratorTestCase extends AbstractBitmapRendererConfiguratorTest { | |||
@@ -51,7 +52,7 @@ public class TIFFRendererConfiguratorTestCase extends AbstractBitmapRendererConf | |||
@Test | |||
@Override | |||
public void testColorModes() throws Exception { | |||
for (TIFFCompressionValues value : TIFFCompressionValues.values()) { | |||
for (TIFFCompressionValue value : TIFFCompressionValue.values()) { | |||
parseConfig(createBuilder().setCompressionMode(value.getName())); | |||
if (value == CCITT_T6 || value == CCITT_T4) { | |||
assertEquals(BufferedImage.TYPE_BYTE_BINARY, settings.getBufferedImageType()); |