mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 12:35:29 -04:00
TMI-85: Support 16 bit signed int data
This commit is contained in:
parent
87b6c817a0
commit
5def68c7e3
@ -140,6 +140,8 @@ final class EXIFEntry extends AbstractEntry {
|
|||||||
return "ColorMap";
|
return "ColorMap";
|
||||||
case TIFF.TAG_EXTRA_SAMPLES:
|
case TIFF.TAG_EXTRA_SAMPLES:
|
||||||
return "ExtraSamples";
|
return "ExtraSamples";
|
||||||
|
case TIFF.TAG_SAMPLE_FORMAT:
|
||||||
|
return "SampleFormat";
|
||||||
|
|
||||||
case TIFF.TAG_SUB_IFD:
|
case TIFF.TAG_SUB_IFD:
|
||||||
return "SubIFD";
|
return "SubIFD";
|
||||||
|
@ -234,12 +234,12 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException {
|
public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException {
|
||||||
readIFD(imageIndex);
|
readIFD(imageIndex);
|
||||||
|
|
||||||
getSampleFormat(); // We don't support anything but SAMPLEFORMAT_UINT at the moment, just sanity checking input
|
int sampleFormat = getSampleFormat();
|
||||||
int planarConfiguration = getValueAsIntWithDefault(TIFF.TAG_PLANAR_CONFIGURATION, TIFFExtension.PLANARCONFIG_PLANAR);
|
int planarConfiguration = getValueAsIntWithDefault(TIFF.TAG_PLANAR_CONFIGURATION, TIFFExtension.PLANARCONFIG_PLANAR);
|
||||||
int interpretation = getValueAsInt(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, "PhotometricInterpretation");
|
int interpretation = getValueAsInt(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, "PhotometricInterpretation");
|
||||||
int samplesPerPixel = getValueAsIntWithDefault(TIFF.TAG_SAMPLES_PER_PIXEL, 1);
|
int samplesPerPixel = getValueAsIntWithDefault(TIFF.TAG_SAMPLES_PER_PIXEL, 1);
|
||||||
int bitsPerSample = getBitsPerSample();
|
int bitsPerSample = getBitsPerSample();
|
||||||
int dataType = bitsPerSample <= 8 ? DataBuffer.TYPE_BYTE : bitsPerSample <= 16 ? DataBuffer.TYPE_USHORT : DataBuffer.TYPE_INT;
|
int dataType = getDataType(sampleFormat, bitsPerSample);
|
||||||
|
|
||||||
// Read embedded cs
|
// Read embedded cs
|
||||||
ICC_Profile profile = getICCProfile();
|
ICC_Profile profile = getICCProfile();
|
||||||
@ -403,6 +403,24 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getDataType(int sampleFormat, int bitsPerSample) throws IIOException {
|
||||||
|
switch (sampleFormat) {
|
||||||
|
case TIFFBaseline.SAMPLEFORMAT_UINT:
|
||||||
|
return bitsPerSample <= 8 ? DataBuffer.TYPE_BYTE : bitsPerSample <= 16 ? DataBuffer.TYPE_USHORT : DataBuffer.TYPE_INT;
|
||||||
|
case TIFFExtension.SAMPLEFORMAT_INT:
|
||||||
|
if (bitsPerSample == 16) {
|
||||||
|
return DataBuffer.TYPE_SHORT;
|
||||||
|
}
|
||||||
|
throw new IIOException("Unsupported BitPerSample for SampleFormat 2/Signed Integer (expected 16): " + bitsPerSample);
|
||||||
|
case TIFFExtension.SAMPLEFORMAT_FP:
|
||||||
|
throw new IIOException("Unsupported TIFF SampleFormat: (3/Floating point)");
|
||||||
|
case TIFFExtension.SAMPLEFORMAT_UNDEFINED:
|
||||||
|
throw new IIOException("Unsupported TIFF SampleFormat (4/Undefined)");
|
||||||
|
default:
|
||||||
|
throw new IIOException("Unknown TIFF SampleFormat (expected 1, 2, 3 or 4): " + sampleFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IndexColorModel createIndexColorModel(final int bitsPerSample, final int dataType, final int[] cmapShort) {
|
private IndexColorModel createIndexColorModel(final int bitsPerSample, final int dataType, final int[] cmapShort) {
|
||||||
// According to the spec, there should be exactly 3 * bitsPerSample^2 entries in the color map for TIFF.
|
// According to the spec, there should be exactly 3 * bitsPerSample^2 entries in the color map for TIFF.
|
||||||
// Should we enforce this?
|
// Should we enforce this?
|
||||||
@ -452,12 +470,10 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sampleFormat != TIFFBaseline.SAMPLEFORMAT_UINT) {
|
return (int) sampleFormat;
|
||||||
throw new IIOException("Unsupported TIFF SampleFormat (expected 1/Unsigned Integer): " + sampleFormat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default, and the only value we support
|
// The default
|
||||||
return TIFFBaseline.SAMPLEFORMAT_UINT;
|
return TIFFBaseline.SAMPLEFORMAT_UINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1152,7 +1168,10 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case DataBuffer.TYPE_USHORT:
|
case DataBuffer.TYPE_USHORT:
|
||||||
short[] rowDataShort = ((DataBufferUShort) tileRowRaster.getDataBuffer()).getData();
|
case DataBuffer.TYPE_SHORT:
|
||||||
|
short[] rowDataShort = tileRowRaster.getTransferType() == DataBuffer.TYPE_USHORT
|
||||||
|
? ((DataBufferUShort) tileRowRaster.getDataBuffer()).getData()
|
||||||
|
: ((DataBufferShort) tileRowRaster.getDataBuffer()).getData();
|
||||||
|
|
||||||
for (int row = startRow; row < startRow + rowsInTile; row++) {
|
for (int row = startRow; row < startRow + rowsInTile; row++) {
|
||||||
if (row >= srcRegion.y + srcRegion.height) {
|
if (row >= srcRegion.y + srcRegion.height) {
|
||||||
|
@ -75,7 +75,8 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTestCase<TIFFImageRe
|
|||||||
new TestData(getClassLoaderResource("/tiff/smallliz.tif"), new Dimension(160, 160)), // YCbCr, Old-Style JPEG compressed (full JFIF stream)
|
new TestData(getClassLoaderResource("/tiff/smallliz.tif"), new Dimension(160, 160)), // YCbCr, Old-Style JPEG compressed (full JFIF stream)
|
||||||
new TestData(getClassLoaderResource("/tiff/zackthecat.tif"), new Dimension(234, 213)), // YCbCr, Old-Style JPEG compressed (tables, no JFIF stream)
|
new TestData(getClassLoaderResource("/tiff/zackthecat.tif"), new Dimension(234, 213)), // YCbCr, Old-Style JPEG compressed (tables, no JFIF stream)
|
||||||
new TestData(getClassLoaderResource("/tiff/test-single-gray-compression-type-2.tiff"), new Dimension(1728, 1146)), // Gray, CCITT type 2 compressed
|
new TestData(getClassLoaderResource("/tiff/test-single-gray-compression-type-2.tiff"), new Dimension(1728, 1146)), // Gray, CCITT type 2 compressed
|
||||||
new TestData(getClassLoaderResource("/tiff/cramps-tile.tif"), new Dimension(800, 607)) // Gray/WhiteIsZero, uncompressed, striped & tiled...
|
new TestData(getClassLoaderResource("/tiff/cramps-tile.tif"), new Dimension(800, 607)), // Gray/WhiteIsZero, uncompressed, striped & tiled...
|
||||||
|
new TestData(getClassLoaderResource("/tiff/part.tif"), new Dimension(50, 50)) // Gray/BlackIsZero, uncompressed, striped signed int (SampleFormat 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
imageio/imageio-tiff/src/test/resources/tiff/part.tif
Normal file
BIN
imageio/imageio-tiff/src/test/resources/tiff/part.tif
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user