Search in sources :

Example 6 with ReflectException

use of loci.common.ReflectException in project bioformats by openmicroscopy.

the class LegacyQTReader 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 QuickTime Java");
    if (tools == null) {
        tools = new LegacyQTTools();
        r = tools.getUniverse();
    }
    tools.checkQTLibrary();
    super.initFile(id);
    LOGGER.info("Reading movie dimensions");
    try {
        r.exec("QTSession.open()");
        // open movie file
        Location file = new Location(id);
        r.setVar("path", file.getAbsolutePath());
        r.exec("qtf = new QTFile(path)");
        r.exec("openMovieFile = OpenMovieFile.asRead(qtf)");
        r.exec("m = Movie.fromFile(openMovieFile)");
        int numTracks = ((Integer) r.exec("m.getTrackCount()")).intValue();
        int trackMostLikely = 0;
        int trackNum = 0;
        while (++trackNum <= numTracks && trackMostLikely == 0) {
            r.setVar("trackNum", trackNum);
            r.exec("imageTrack = m.getTrack(trackNum)");
            r.exec("d = imageTrack.getSize()");
            Integer w = (Integer) r.exec("d.getWidth()");
            if (w.intValue() > 0)
                trackMostLikely = trackNum;
        }
        r.setVar("trackMostLikely", trackMostLikely);
        r.exec("imageTrack = m.getTrack(trackMostLikely)");
        r.exec("d = imageTrack.getSize()");
        Integer w = (Integer) r.exec("d.getWidth()");
        Integer h = (Integer) r.exec("d.getHeight()");
        r.exec("moviePlayer = new MoviePlayer(m)");
        r.setVar("dim", new Dimension(w.intValue(), h.intValue()));
        ImageProducer qtip = (ImageProducer) r.exec("qtip = new QTImageProducer(moviePlayer, dim)");
        image = Toolkit.getDefaultToolkit().createImage(qtip);
        r.setVar("zero", 0);
        r.setVar("one", 1f);
        r.exec("timeInfo = new TimeInfo(zero, zero)");
        r.exec("moviePlayer.setTime(zero)");
        Vector<Integer> v = new Vector<Integer>();
        int time = 0;
        Integer q = new Integer(time);
        do {
            v.add(q);
            r.exec("timeInfo = imageTrack.getNextInterestingTime(" + "StdQTConstants.nextTimeMediaSample, timeInfo.time, one)");
            q = (Integer) r.getVar("timeInfo.time");
            time = q.intValue();
        } while (time >= 0);
        CoreMetadata m = core.get(0);
        m.imageCount = v.size();
        times = new int[getImageCount()];
        for (int i = 0; i < times.length; i++) {
            q = v.elementAt(i);
            times[i] = q.intValue();
        }
        LOGGER.info("Populating metadata");
        BufferedImage img = AWTImageTools.makeBuffered(image);
        m.sizeX = img.getWidth();
        m.sizeY = img.getHeight();
        m.sizeZ = 1;
        m.sizeC = img.getRaster().getNumBands();
        m.sizeT = getImageCount();
        m.pixelType = AWTImageTools.getPixelType(img);
        m.dimensionOrder = "XYCTZ";
        m.rgb = true;
        m.interleaved = false;
        m.littleEndian = false;
        m.indexed = false;
        m.falseColor = false;
        MetadataStore store = makeFilterMetadata();
        MetadataTools.populatePixels(store, this);
    } catch (ReflectException e) {
        throw new FormatException("Open movie failed", e);
    }
}
Also used : Dimension(java.awt.Dimension) CoreMetadata(loci.formats.CoreMetadata) ReflectException(loci.common.ReflectException) BufferedImage(java.awt.image.BufferedImage) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) LegacyQTTools(loci.formats.gui.LegacyQTTools) ImageProducer(java.awt.image.ImageProducer) Vector(java.util.Vector) Location(loci.common.Location)

Example 7 with ReflectException

use of loci.common.ReflectException in project bioformats by openmicroscopy.

the class DisplayHandler method displayImage5D.

public void displayImage5D(ImagePlus imp) {
    WindowManager.setTempCurrentImage(imp);
    IFormatReader r = process.getReader();
    ReflectedUniverse ru = new ReflectedUniverse();
    try {
        ru.exec("import i5d.Image5D");
        ru.setVar("title", imp.getTitle());
        ru.setVar("stack", imp.getStack());
        ru.setVar("sizeC", imp.getNChannels());
        ru.setVar("sizeZ", imp.getNSlices());
        ru.setVar("sizeT", imp.getNFrames());
        ru.exec("i5d = new Image5D(title, stack, sizeC, sizeZ, sizeT)");
        ru.setVar("cal", imp.getCalibration());
        ru.setVar("fi", imp.getOriginalFileInfo());
        ru.exec("i5d.setCalibration(cal)");
        ru.exec("i5d.setFileInfo(fi)");
        // ru.exec("i5d.setDimensions(sizeC, sizeZ, sizeT)");
        ru.exec("i5d.show()");
    } catch (ReflectException exc) {
        WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem interfacing with Image5D");
    }
}
Also used : IFormatReader(loci.formats.IFormatReader) ReflectedUniverse(loci.common.ReflectedUniverse) ReflectException(loci.common.ReflectException)

Example 8 with ReflectException

use of loci.common.ReflectException in project bioformats by openmicroscopy.

the class MetaSupportList method format.

/**
 * Gets the name of the format for the current handler.
 */
public String format() {
    ReflectedUniverse r = new ReflectedUniverse();
    IFormatHandler handler;
    try {
        r.exec("import loci.formats.in." + handlerName);
    } catch (ReflectException exc) {
    }
    try {
        r.exec("import loci.formats.out." + handlerName);
    } catch (ReflectException exc) {
    }
    try {
        handler = (IFormatHandler) r.exec("new " + handlerName + "()");
        return handler.getFormat();
    } catch (ReflectException exc) {
    }
    return null;
}
Also used : IFormatHandler(loci.formats.IFormatHandler) ReflectedUniverse(loci.common.ReflectedUniverse) ReflectException(loci.common.ReflectException)

Example 9 with ReflectException

use of loci.common.ReflectException 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);
}
Also used : FileHandle(loci.common.FileHandle) FileNotFoundException(java.io.FileNotFoundException) ReflectException(loci.common.ReflectException) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) BufferedImage(java.awt.image.BufferedImage) MetadataStore(loci.formats.meta.MetadataStore) MissingLibraryException(loci.formats.MissingLibraryException) ReflectedUniverse(loci.common.ReflectedUniverse) IRandomAccess(loci.common.IRandomAccess) File(java.io.File)

Example 10 with ReflectException

use of loci.common.ReflectException in project bioformats by openmicroscopy.

the class TiffJAIReader method openBufferedImage.

/**
 * Obtains a BufferedImage from the given data source using JAI.
 */
protected BufferedImage openBufferedImage(int no) throws FormatException {
    r.setVar("no", no);
    RenderedImage img;
    try {
        r.exec("img = dec.decodeAsRenderedImage(no)");
        img = (RenderedImage) r.exec("new NullOpImage(img, null, OpImage.OP_IO_BOUND, null)");
    } catch (ReflectException exc) {
        throw new FormatException(exc);
    }
    return AWTImageTools.convertRenderedImage(img);
}
Also used : RenderedImage(java.awt.image.RenderedImage) ReflectException(loci.common.ReflectException) FormatException(loci.formats.FormatException)

Aggregations

ReflectException (loci.common.ReflectException)10 FormatException (loci.formats.FormatException)7 ReflectedUniverse (loci.common.ReflectedUniverse)4 BufferedImage (java.awt.image.BufferedImage)3 Dimension (java.awt.Dimension)2 CoreMetadata (loci.formats.CoreMetadata)2 LegacyQTTools (loci.formats.gui.LegacyQTTools)2 MetadataStore (loci.formats.meta.MetadataStore)2 Image (java.awt.Image)1 DirectColorModel (java.awt.image.DirectColorModel)1 ImageProducer (java.awt.image.ImageProducer)1 MemoryImageSource (java.awt.image.MemoryImageSource)1 RenderedImage (java.awt.image.RenderedImage)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Vector (java.util.Vector)1 FileHandle (loci.common.FileHandle)1 IRandomAccess (loci.common.IRandomAccess)1 Location (loci.common.Location)1 IFormatHandler (loci.formats.IFormatHandler)1