CCITT FAX Encoding: Support FillOrder Reversed

This commit is contained in:
Schmidor 2015-07-04 00:42:09 +02:00
parent 62862d835a
commit 1e6227bee5
2 changed files with 20 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
import com.twelvemonkeys.lang.Validate; import com.twelvemonkeys.lang.Validate;
/** /**
@ -345,8 +346,14 @@ final class CCITTFaxDecoderStream extends FilterInputStream {
} }
bufferPos = 0; 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++; bufferPos++;
if (bufferPos > 7) if (bufferPos > 7)
bufferPos = -1; bufferPos = -1;

View File

@ -179,6 +179,17 @@ public class CCITTFaxDecoderStreamTest {
assertArrayEquals(imageData, bytes); 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 @Test
public void testDecodeType4() throws IOException { public void testDecodeType4() throws IOException {
InputStream stream = new CCITTFaxDecoderStream(new ByteArrayInputStream(DATA_G4), 6, InputStream stream = new CCITTFaxDecoderStream(new ByteArrayInputStream(DATA_G4), 6,