From 1e6227bee59781a8180a0929cda7ce9e7fb96da3 Mon Sep 17 00:00:00 2001 From: Schmidor Date: Sat, 4 Jul 2015 00:42:09 +0200 Subject: [PATCH] CCITT FAX Encoding: Support FillOrder Reversed --- .../imageio/plugins/tiff/CCITTFaxDecoderStream.java | 11 +++++++++-- .../plugins/tiff/CCITTFaxDecoderStreamTest.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 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 34a0e9e3..cd149a31 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 @@ -33,6 +33,7 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import com.twelvemonkeys.imageio.metadata.exif.TIFF; import com.twelvemonkeys.lang.Validate; /** @@ -345,8 +346,14 @@ final class CCITTFaxDecoderStream extends FilterInputStream { } bufferPos = 0; } - - boolean isSet = ((buffer >> (7 - bufferPos)) & 1) == 1; + + boolean isSet; + if(fillOrder == TIFFBaseline.FILL_LEFT_TO_RIGHT){ + isSet = ((buffer >> (7 - bufferPos)) & 1) == 1; + }else{ + isSet = ((buffer >> (bufferPos)) & 1) == 1; + } + bufferPos++; if (bufferPos > 7) bufferPos = -1; 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 0139f9d1..b7c9ac87 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 @@ -179,6 +179,17 @@ public class CCITTFaxDecoderStreamTest { assertArrayEquals(imageData, bytes); } + @Test + public void testDecodeType3_2D_REVERSED() throws IOException { + InputStream stream = new CCITTFaxDecoderStream(new ByteArrayInputStream(DATA_G3_2D_lsb2msb), 6, + TIFFExtension.COMPRESSION_CCITT_T4, 2, TIFFExtension.GROUP3OPT_2DENCODING); + + byte[] imageData = ((DataBufferByte) image.getData().getDataBuffer()).getData(); + byte[] bytes = new byte[imageData.length]; + new DataInputStream(stream).readFully(bytes); + assertArrayEquals(imageData, bytes); + } + @Test public void testDecodeType4() throws IOException { InputStream stream = new CCITTFaxDecoderStream(new ByteArrayInputStream(DATA_G4), 6,