From be90082bd3fbca0689a342b905689fb6c7e67498 Mon Sep 17 00:00:00 2001 From: Schmidor Date: Thu, 12 Nov 2015 00:38:41 +0100 Subject: [PATCH] Testcase for "Fixed an issue with long runlengths in CCITTFax writing #188" --- .../tiff/CCITTFaxEncoderStreamTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java b/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java index 9a6f12a2..75210053 100644 --- a/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java +++ b/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java @@ -43,6 +43,7 @@ import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.io.*; import java.net.URL; +import java.util.Arrays; import static org.junit.Assert.*; @@ -125,6 +126,32 @@ public class CCITTFaxEncoderStreamTest { // testImage(getClassLoaderResource("/tiff/test-single-gray-compression-type-2.tiff")); } + /** + * Test for "Fixed an issue with long runlengths in CCITTFax writing #188" + * + * @throws IOException + */ + @Test + public void testRunlengthIssue() throws IOException { + byte[] data = new byte[400]; + Arrays.fill(data, (byte) 0xFF); + data[0] = 0; + data[399] = 0; + + ByteArrayOutputStream imageOutput = new ByteArrayOutputStream(); + OutputStream outputSteam = new CCITTFaxEncoderStream(imageOutput, 3200, 1, TIFFExtension.COMPRESSION_CCITT_T6, 1, 0L); + outputSteam.write(data); + outputSteam.close(); + byte[] encodedData = imageOutput.toByteArray(); + + byte[] decodedData = new byte[data.length]; + CCITTFaxDecoderStream inputStream = new CCITTFaxDecoderStream(new ByteArrayInputStream(encodedData), 3200, TIFFExtension.COMPRESSION_CCITT_T6, 1, 0L); + new DataInputStream(inputStream).readFully(decodedData); + inputStream.close(); + + assertArrayEquals(data, decodedData); + } + protected URL getClassLoaderResource(final String pName) { return getClass().getResource(pName); }