use of uk.ac.sussex.gdsc.core.ij.io.ExtendedFileInfo in project GDSC-SMLM by aherbert.
the class SeriesImageSource method openImage.
private TiffImage openImage(int id, String path) {
TiffImage tiffImage = null;
// We only need the meta data for the first image. We then assume check
// all other images in the series match the pixel type and width of the first.
final boolean pixelInfoOnly = id != 0;
// Open using specialised TIFF reader for better non-sequential support
SeekableStream ss = null;
try {
ss = createSeekableStream(path, imageData[id].fileSize);
final FastTiffDecoder td = FastTiffDecoder.create(ss, path);
td.setTrackProgress(trackProgress);
// Try and use the index map
final IndexMap indexMap = td.getIndexMap();
// Check the image map is the correct size (only if we have sizes)
if (indexMap != null && (imageSize == null || indexMap.getSize() == getImageSize(id))) {
// We need the first IFD to define the image pixel type and width/height
final ExtendedFileInfo fi = td.getTiffInfo(indexMap, 0, pixelInfoOnly);
// A byte array seekable stream will ignore the close() method so we can re-use it
tiffImage = new TiffImage(indexMap, fi, (ss instanceof ByteArraySeekableStream) ? ss : null);
} else {
// Reset after reading the index map
td.reset();
// Read all the IFDs
final ExtendedFileInfo[] info = td.getTiffInfo(pixelInfoOnly);
if (info != null) {
// A byte array seekable stream will ignore the close() method so we can re-use it
tiffImage = new TiffImage(info, (ss instanceof ByteArraySeekableStream) ? ss : null);
}
}
} catch (final IOException ioe) {
// Ignore
} finally {
closeInputStream(ss);
}
if (tiffImage == null) {
// Prevent reading again. Skip the storeTiffImage(...) method
// as that may be optional and we don't want to repeat the error.
imageData[id].tiffImage = new TiffImage();
} else {
storeTiffImage(id, tiffImage);
}
return tiffImage;
}
Aggregations