TMI #164 Support for TIFF with 32 but floating point samples.

This commit is contained in:
Harald Kuhr 2015-08-21 10:49:46 +02:00
parent 211b31e154
commit 22e490ca40
3 changed files with 49 additions and 2 deletions

View File

@ -531,8 +531,14 @@ public class TIFFImageReader extends ImageReaderBase {
} }
throw new IIOException("Unsupported BitsPerSample for SampleFormat 2/Signed Integer (expected 8/16/32): " + bitsPerSample); throw new IIOException("Unsupported BitsPerSample for SampleFormat 2/Signed Integer (expected 8/16/32): " + bitsPerSample);
case TIFFExtension.SAMPLEFORMAT_FP: 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: case TIFFExtension.SAMPLEFORMAT_UNDEFINED:
// Spec says: // Spec says:
// A field value of undefined is a statement by the writer that it did not know how // 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; 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();
}
} }
} }

View File

@ -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_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/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/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 // 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.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 new TestData(getClassLoaderResource("/tiff/ccitt/group3_1d_fill.tif"), new Dimension(6, 4)), // B/W, CCITT T4 1D