use of loci.common.ReflectedUniverse in project bioformats by openmicroscopy.
the class TiffJAIReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
LOGGER.info("Checking for JAI");
try {
r = new ReflectedUniverse();
r.exec("import javax.media.jai.NullOpImage");
r.exec("import javax.media.jai.OpImage");
r.exec("import com.sun.media.jai.codec.FileSeekableStream");
r.exec("import com.sun.media.jai.codec.ImageDecoder");
r.exec("import com.sun.media.jai.codec.ImageCodec");
} catch (ReflectException exc) {
throw new MissingLibraryException(NO_JAI_MSG, exc);
}
super.initFile(id);
LOGGER.info("Reading movie dimensions");
// map Location to File or RandomAccessFile, if possible
IRandomAccess ira = Location.getMappedFile(id);
if (ira != null) {
if (ira instanceof FileHandle) {
FileHandle fh = (FileHandle) ira;
r.setVar("file", fh.getRandomAccessFile());
} else {
throw new FormatException("Unsupported handle type" + ira.getClass().getName());
}
} else {
String mapId = Location.getMappedId(id);
File file = new File(mapId);
if (file.exists()) {
r.setVar("file", file);
} else
throw new FileNotFoundException(id);
}
r.setVar("tiff", "tiff");
r.setVar("param", null);
// create TIFF decoder
int numPages;
try {
r.exec("s = new FileSeekableStream(file)");
r.exec("dec = ImageCodec.createImageDecoder(tiff, s, param)");
numPages = ((Integer) r.exec("dec.getNumPages()")).intValue();
} catch (ReflectException exc) {
throw new FormatException(exc);
}
if (numPages < 0) {
throw new FormatException("Invalid page count: " + numPages);
}
// decode first image plane
BufferedImage img = openBufferedImage(0);
if (img == null)
throw new FormatException("Invalid image stream");
LOGGER.info("Populating metadata");
CoreMetadata m = core.get(0);
m.imageCount = numPages;
m.sizeX = img.getWidth();
m.sizeY = img.getHeight();
m.sizeZ = 1;
m.sizeC = img.getSampleModel().getNumBands();
m.sizeT = numPages;
m.rgb = m.sizeC > 1;
m.dimensionOrder = "XYCZT";
m.pixelType = AWTImageTools.getPixelType(img);
m.interleaved = true;
m.littleEndian = false;
m.metadataComplete = true;
m.indexed = false;
m.falseColor = false;
// populate the metadata store
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
Aggregations