use of ij.io.FileOpener in project TrakEM2 by trakem2.
the class Patch method getAlphaMask.
/**
* Return a new {@link ByteProcessor} representing the alpha mask, if any, over the pixel data.
* @return null if there isn't one, or if the mask image could not be loaded.
*/
public synchronized ByteProcessor getAlphaMask() {
if (0 == alpha_mask_id)
return null;
final String path = createAlphaMaskFilePath(alpha_mask_id);
// Expects a zip file containing one single TIFF file entry
ZipInputStream zis = null;
try {
zis = new ZipInputStream(new FileInputStream(path));
// prepares the entry for reading
final ZipEntry ze = zis.getNextEntry();
// Assume the first entry is the mask
final ImageProcessor mask = new FileOpener(new TiffDecoder(zis, ze.getName()).getTiffInfo()[0]).open(false).getProcessor();
if (mask.getWidth() != o_width || mask.getHeight() != o_height) {
Utils.log2("Mask has improper dimensions: " + mask.getWidth() + " x " + mask.getHeight() + " for patch #" + this.id + " which is of " + o_width + " x " + o_height);
return null;
}
return (ByteProcessor) (mask.getClass() == ByteProcessor.class ? mask : mask.convertToByte(false));
} catch (final Throwable t) {
Utils.log2("Could not load alpha mask for patch #" + this.id + " from file " + path);
IJError.print(t);
return null;
} finally {
try {
if (null != zis)
zis.close();
} catch (final Exception e) {
IJError.print(e);
}
}
}
Aggregations