}
protected byte[] decompress(final byte[] compressed, final int compression,
final int expectedSize, final int tileWidth, final int tileHeight)
throws ImageReadException, IOException {
final TiffField fillOrderField = directory
.findField(TiffTagConstants.TIFF_TAG_FILL_ORDER);
int fillOrder = TiffTagConstants.FILL_ORDER_VALUE_NORMAL;
if (fillOrderField != null) {
fillOrder = fillOrderField.getIntValue();
}
if (fillOrder == TiffTagConstants.FILL_ORDER_VALUE_NORMAL) {
// good
} 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");