findCompressionType always uses RLE if leading EOL is missing (#657)

Update of the last read byte is missing since the last update. So if only the first EOL is missing, further EOLs after the lines are not detected.

(cherry picked from commit ac8a36db1c578b1f4fc7b9afd8603993be80c7d8)
This commit is contained in:
Oliver Schmidtmer 2022-01-15 00:21:47 +01:00 committed by Harald Kuhr
parent 3d5cf0eecd
commit f133ea7d61
2 changed files with 15 additions and 0 deletions

View File

@ -170,6 +170,7 @@ final class CCITTFaxDecoderStream extends FilterInputStream {
// no EOL before stream end // no EOL before stream end
return TIFFBaseline.COMPRESSION_CCITT_MODIFIED_HUFFMAN_RLE; return TIFFBaseline.COMPRESSION_CCITT_MODIFIED_HUFFMAN_RLE;
} }
streamByte = (byte) read;
} }
b = (short) ((b << 1) + ((streamByte >> (7 - (i % 8))) & 0x01)); b = (short) ((b << 1) + ((streamByte >> (7 - (i % 8))) & 0x01));

View File

@ -363,6 +363,20 @@ public class CCITTFaxDecoderStreamTest {
} }
} }
@Test
public void testFindCompressionTypeForMissingStartEOL() throws IOException {
// Type 4, missing leading EOL code
// starts with 1728px long white lines
byte[] data = new byte[]{
0x4d, (byte) 0x9a, (byte) 0x80, 0x01, 0x4d, (byte) 0x9a, (byte) 0x80, 0x01, 0x4d, (byte) 0x9a, (byte) 0x80, 0x01, 0x4d, (byte) 0x9a, (byte) 0x80, 0x01,
(byte) 0x91, 0x3c, 0x17, 0x6d, 0x02, (byte) 0xf2, (byte) 0xb0, 0x20, (byte) 0x01, (byte) 0xda, (byte) 0xa8, (byte) 0xb3, 0x17, 0x4e, 0x62, (byte) 0xcd, (byte) 0xa7
};
try (ByteArrayInputStream is = new ByteArrayInputStream(data)) {
int detectedType = CCITTFaxDecoderStream.findCompressionType(TIFFExtension.COMPRESSION_CCITT_T4, is);
assertEquals(TIFFExtension.COMPRESSION_CCITT_T4, detectedType);
}
}
private InputStream getResourceAsStream(String name) { private InputStream getResourceAsStream(String name) {
return getClass().getResourceAsStream(name); return getClass().getResourceAsStream(name);
} }