} else if (fillOrder == TiffTagConstants.FILL_ORDER_VALUE_REVERSED) {
for (int i = 0; i < compressed.length; i++) {
compressed[i] = (byte) (Integer.reverse(0xff & compressed[i]) >>> 24);
}
} else {
throw new ImageReadException("TIFF FillOrder=" + fillOrder
+ " is invalid");
}
switch (compression) {
case TIFF_COMPRESSION_UNCOMPRESSED: // None;
return compressed;
case TIFF_COMPRESSION_CCITT_1D: // CCITT Group 3 1-Dimensional Modified
// Huffman run-length encoding.
return T4AndT6Compression.decompressModifiedHuffman(compressed,
tileWidth, tileHeight);
case TIFF_COMPRESSION_CCITT_GROUP_3: {
int t4Options = 0;
final TiffField field = directory
.findField(TiffTagConstants.TIFF_TAG_T4_OPTIONS);
if (field != null) {
t4Options = field.getIntValue();
}
final boolean is2D = (t4Options & TIFF_FLAG_T4_OPTIONS_2D) != 0;
final boolean usesUncompressedMode = (t4Options & TIFF_FLAG_T4_OPTIONS_UNCOMPRESSED_MODE) != 0;
if (usesUncompressedMode) {
throw new ImageReadException(
"T.4 compression with the uncompressed mode extension is not yet supported");
}
final boolean hasFillBitsBeforeEOL = (t4Options & TIFF_FLAG_T4_OPTIONS_FILL) != 0;
if (is2D) {
return T4AndT6Compression.decompressT4_2D(compressed,
tileWidth, tileHeight, hasFillBitsBeforeEOL);
}
return T4AndT6Compression.decompressT4_1D(compressed,
tileWidth, tileHeight, hasFillBitsBeforeEOL);
}
case TIFF_COMPRESSION_CCITT_GROUP_4: {
int t6Options = 0;
final TiffField field = directory
.findField(TiffTagConstants.TIFF_TAG_T6_OPTIONS);
if (field != null) {
t6Options = field.getIntValue();
}
final boolean usesUncompressedMode = (t6Options & TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE) != 0;
if (usesUncompressedMode) {
throw new ImageReadException(
"T.6 compression with the uncompressed mode extension is not yet supported");
}
return T4AndT6Compression.decompressT6(compressed, tileWidth,
tileHeight);
}
case TIFF_COMPRESSION_LZW: // LZW
{
final InputStream is = new ByteArrayInputStream(compressed);
final int lzwMinimumCodeSize = 8;
final MyLzwDecompressor myLzwDecompressor = new MyLzwDecompressor(
lzwMinimumCodeSize, ByteOrder.BIG_ENDIAN);
myLzwDecompressor.setTiffLZWMode();
return myLzwDecompressor.decompress(is, expectedSize);
}
case TIFF_COMPRESSION_PACKBITS: // Packbits
{
return new PackBits().decompress(compressed, expectedSize);
}
default:
throw new ImageReadException("Tiff: unknown/unsupported compression: " + compression);
}
}