From fa0341f30237effe523e9905e672d709ffe9c6bd Mon Sep 17 00:00:00 2001 From: Oliver Schmidtmer Date: Sat, 7 May 2016 01:06:53 +0200 Subject: [PATCH] TMI #237: Fix for CCITT images with more b/w changes than columns --- .../plugins/tiff/CCITTFaxDecoderStream.java | 4 ++-- .../tiff/CCITTFaxDecoderStreamTest.java | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStream.java b/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStream.java index 53c1c8aa..0f5cf060 100644 --- a/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStream.java +++ b/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStream.java @@ -86,8 +86,8 @@ final class CCITTFaxDecoderStream extends FilterInputStream { fillOrder, "Expected fill order 1 or 2: %s" ); - this.changesReferenceRow = new int[columns]; - this.changesCurrentRow = new int[columns]; + this.changesReferenceRow = new int[columns + 1]; + this.changesCurrentRow = new int[columns + 1]; switch (type) { case TIFFExtension.COMPRESSION_CCITT_T4: diff --git a/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStreamTest.java b/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStreamTest.java index 68c59d7b..599d26f7 100644 --- a/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStreamTest.java +++ b/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxDecoderStreamTest.java @@ -33,13 +33,11 @@ import org.junit.Test; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Arrays; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; /** * CCITTFaxDecoderStreamTest @@ -229,4 +227,20 @@ public class CCITTFaxDecoderStreamTest { // Ideally, we should have no more data now, but the stream don't know that... // assertEquals("Should contain no more data", -1, stream.read()); } + + @Test + public void testMoreChangesThanColumns() throws IOException { + // Produces an CCITT Stream with 9 changes on 8 columns. + byte[] data = new byte[] {(byte) 0b10101010}; + ByteArrayOutputStream imageOutput = new ByteArrayOutputStream(); + OutputStream outputSteam = new CCITTFaxEncoderStream(imageOutput, 8, 1, TIFFExtension.COMPRESSION_CCITT_T6, 1, 0L); + outputSteam.write(data); + outputSteam.close(); + + byte[] encoded = imageOutput.toByteArray(); + InputStream inputStream = new CCITTFaxDecoderStream(new ByteArrayInputStream(encoded), 8, + TIFFExtension.COMPRESSION_CCITT_T6, 1, 0L); + byte decoded = (byte) inputStream.read(); + assertEquals(data[0], decoded); + } }