mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 19:45:28 -04:00
TMI #164 Support for TIFF with 32 but floating point samples.
This commit is contained in:
parent
211b31e154
commit
22e490ca40
@ -531,8 +531,14 @@ public class TIFFImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
throw new IIOException("Unsupported BitsPerSample for SampleFormat 2/Signed Integer (expected 8/16/32): " + bitsPerSample);
|
||||
|
||||
case TIFFExtension.SAMPLEFORMAT_FP:
|
||||
throw new IIOException("Unsupported TIFF SampleFormat: 3 (Floating point)");
|
||||
if (bitsPerSample == 32) {
|
||||
return DataBuffer.TYPE_FLOAT;
|
||||
}
|
||||
|
||||
throw new IIOException("Unsupported BitsPerSample for SampleFormat 3/Floating Point (expected 32): " + bitsPerSample);
|
||||
|
||||
case TIFFExtension.SAMPLEFORMAT_UNDEFINED:
|
||||
// Spec says:
|
||||
// A field value of “undefined” is a statement by the writer that it did not know how
|
||||
@ -1381,6 +1387,46 @@ public class TIFFImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DataBuffer.TYPE_FLOAT:
|
||||
float[] rowDataFloat = ((DataBufferFloat) tileRowRaster.getDataBuffer()).getData();
|
||||
|
||||
for (int row = startRow; row < startRow + rowsInTile; row++) {
|
||||
if (row >= srcRegion.y + srcRegion.height) {
|
||||
break; // We're done with this tile
|
||||
}
|
||||
|
||||
readFully(input, rowDataFloat);
|
||||
|
||||
if (row >= srcRegion.y) {
|
||||
// normalizeBlack(interpretation, rowDataFloat);
|
||||
|
||||
// Subsample horizontal
|
||||
if (xSub != 1) {
|
||||
for (int x = srcRegion.x / xSub * numBands; x < ((srcRegion.x + srcRegion.width) / xSub) * numBands; x += numBands) {
|
||||
System.arraycopy(rowDataFloat, x * xSub, rowDataFloat, x, numBands);
|
||||
}
|
||||
}
|
||||
|
||||
raster.setDataElements(startCol, row - srcRegion.y, tileRowRaster);
|
||||
}
|
||||
// Else skip data
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Candidate util method (with off/len + possibly byte order)
|
||||
private void readFully(final DataInput input, final float[] rowDataFloat) throws IOException {
|
||||
if (input instanceof ImageInputStream) {
|
||||
ImageInputStream imageInputStream = (ImageInputStream) input;
|
||||
imageInputStream.readFully(rowDataFloat, 0, rowDataFloat.length);
|
||||
}
|
||||
else {
|
||||
for (int k = 0; k < rowDataFloat.length; k++) {
|
||||
rowDataFloat[k] = input.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,8 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
|
||||
new TestData(getClassLoaderResource("/tiff/cmyk_jpeg_no_profile.tif"), new Dimension(150, 63)), // CMYK, JPEG compressed, no ICC profile
|
||||
new TestData(getClassLoaderResource("/tiff/cmyk_jpeg.tif"), new Dimension(100, 100)), // CMYK, JPEG compressed, with ICC profile
|
||||
new TestData(getClassLoaderResource("/tiff/grayscale-alpha.tiff"), new Dimension(248, 351)), // Gray + unassociated alpha
|
||||
new TestData(getClassLoaderResource("/tiff/signed-integral-8bit.tif"), new Dimension(439, 167)), // 8 bit gray, *signed* integral
|
||||
new TestData(getClassLoaderResource("/tiff/signed-integral-8bit.tif"), new Dimension(439, 167)), // Gray, 8 bit *signed* integral
|
||||
new TestData(getClassLoaderResource("/tiff/floatingpoint-32bit.tif"), new Dimension(300, 100)), // RGB, 32 bit floating point
|
||||
// CCITT
|
||||
new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D
|
||||
new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d_fill.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user