[
https://issues.apache.org/jira/browse/IMAGING-170?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary Lucas updated IMAGING-170:
-------------------------------
Attachment: Imaging_170_2015_09_21.patch
Attached is a patch that will enable the TIFF Image Writer to apply the
differencing predictor when using LZW compression. Doing so often results in
output file size reductions of 30 percent or more. I also added code on the
file-reading size to improve the speed of reading files that are written using
the predictor. I was fortunate in this effort in that some of the original
test files in the old Sanselan release included differencing predictors so I
was able to independently verify my changes (see Oregon Scientific DS6639 LZW
files in the test data folder).
At present, the differencing predictor is only applied when storing data in the
3-bytes per sample. I did not implement writing logic for 1-byte samples. The
reading logic, of course, continues to process 1-byte samples correctly, just
as it always has.
I have tested this change using my own personal test programs and also added
code to apply the test during the project round-trip test when running the
Maven package target.
To set your writer to apply the predictor, use the following options when
preparing the parameters for the write operation:
{code:title=WriterExample.java|borderStyle=solid}
params.put(ImagingConstants.PARAM_KEY_COMPRESSION,
TiffConstants.TIFF_COMPRESSION_LZW);
params.put(TiffConstants.PARAM_KEY_LZW_COMPRESSION_PREDICTOR,
TiffConstants.TIFF_LZW_COMPRESSION_PREDICTOR_DIFFERENCING);
// for additional compression (but more expensive processing),
you may
// also try increasing the block size as shown below
//params.put(
// TiffConstants.PARAM_KEY_LZW_COMPRESSION_BLOCK_SIZE,
// new
Integer(TiffConstants.TIFF_LZW_COMPRESSION_BLOCK_SIZE_LARGE));
{code}
> TIFF image gains significant size using TiffImageWriterLossless
> ---------------------------------------------------------------
>
> Key: IMAGING-170
> URL: https://issues.apache.org/jira/browse/IMAGING-170
> Project: Commons Imaging
> Issue Type: Bug
> Components: Format: TIFF
> Affects Versions: 1.0
> Environment: System: Fedora release 21, kernel version:
> 3.18.7-200.fc21.x86_64, JAVA: openjdk version "1.8.0_31", IDE: Eclipse Kepler
> 2, Build id: 20140224-0627
> Reporter: Remigiusz Malessa
> Priority: Minor
> Attachments: Imaging_170_2015_09_21.patch, kwf00346.tif
>
>
> Good afternoon,
> I am posting an issue report as suggested by mr Benedikt Ritter. It's my
> first issue report and I've just recently started using the Commons Imaging,
> so please go easy on me.
> ------------------------------------------------
> Using Commons Imaging I am reading a Tiff image (will attempt to attach it to
> this ticket), then I remove a tag (Focal Plane Resolution Unit) and then I
> save the new TiffOutputSet to the system using TiffImageWriterLossless.
> The original image is 15MB, the new image (with the Tag removed) is 28MB.
> Here's how I do it:
> {code:title=RemoveTag.java|borderStyle=solid}
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import org.apache.camel.Exchange;
> import org.apache.commons.imaging.ImageFormats;
> import org.apache.commons.imaging.ImageReadException;
> import org.apache.commons.imaging.ImageWriteException;
> import org.apache.commons.imaging.Imaging;
> import org.apache.commons.imaging.common.ImageMetadata;
> import org.apache.commons.imaging.formats.tiff.TiffField;
> import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
> import org.apache.commons.imaging.formats.tiff.write.TiffImageWriterLossless;
> import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
> import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
> File tInputFile = new File("/home/rem/TEMP/tags.original.tif");
> File toutputFile = new File("/home/rem/TEMP/tags.new.tif");
> final BufferedImage image = Imaging.getBufferedImage(tInputFile);
> ImageMetadata tMetadata = Imaging.getMetadata(tInputFile);
> TiffImageMetadata imageMetadata = (TiffImageMetadata) tMetadata;
> outputSet = imageMetadata.getOutputSet();
> TiffOutputDirectory exifDirectory = outputSet.getExifDirectory();
> exifDirectory.removeField(41488);
> ImageFormats format = ImageFormats.TIFF;
> Map<String, Object> params = new HashMap<String, Object>();
> BufferedImage image = Imaging.getBufferedImage(tInputFile);
> byte[] bytes = Imaging.writeImageToBytes(image, format, params);
> TiffImageWriterLossless writerLossLess = new TiffImageWriterLossless(bytes);
> writerLossLess.write(os, outputSet);
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)