Search in sources :

Example 21 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class FileHandleTest method testHandleCount.

@Test
public void testHandleCount() throws FormatException, IOException {
    ArrayList<String> initialHandles = getHandles();
    reader = new ImageReader();
    reader.setId(id);
    ArrayList<String> intermediateHandles = getHandles();
    reader.close();
    ArrayList<String> finalHandles = getHandles();
    int intermediateHandleCount = intermediateHandles.size();
    for (int i = 0; i < initialHandles.size(); i++) {
        String s = initialHandles.get(i);
        initialHandles.remove(s);
        finalHandles.remove(s);
        intermediateHandles.remove(s);
        i--;
    }
    for (int i = 0; i < finalHandles.size(); i++) {
        String s = finalHandles.get(i);
        if (s.endsWith("libnio.so") || s.endsWith("resources.jar") || s.startsWith("/usr/lib") || s.startsWith("/opt/") || s.startsWith("/usr/share/locale") || s.startsWith("/lib") || s.indexOf("turbojpeg") > 0 || s.indexOf("/jre/") > 0 || s.indexOf("nativedata") > 0 || s.indexOf("jhdf") > 0) {
            finalHandles.remove(s);
            i--;
        } else {
            LOGGER.warn(s);
        }
    }
    assertEquals(finalHandles.size(), initialHandles.size());
    assertTrue(intermediateHandles.size() >= initialHandles.size());
    assertTrue(intermediateHandleCount < 1024);
}
Also used : ImageReader(loci.formats.ImageReader) Test(org.testng.annotations.Test)

Example 22 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class FormatReaderTest method testConsistentReader.

@Test(groups = { "all", "fast", "automated" })
public void testConsistentReader() {
    if (config == null)
        throw new SkipException("No config tree");
    String testName = "testConsistentReader";
    if (!initFile())
        result(testName, false, "initFile");
    String format = config.getReader();
    IFormatReader r = reader;
    if (r instanceof ImageReader) {
        r = ((ImageReader) r).getReader();
    } else if (r instanceof ReaderWrapper) {
        try {
            r = ((ReaderWrapper) r).unwrap();
        } catch (FormatException e) {
        } catch (IOException e) {
        }
    }
    String realFormat = TestTools.shortClassName(r);
    result(testName, realFormat.equals(format), realFormat);
}
Also used : IFormatReader(loci.formats.IFormatReader) SkipException(org.testng.SkipException) IOException(java.io.IOException) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) ReaderWrapper(loci.formats.ReaderWrapper) FormatException(loci.formats.FormatException) Test(org.testng.annotations.Test)

Example 23 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class FormatReaderTest method testIsThisType.

@Test(groups = { "all", "fast", "automated" })
public void testIsThisType() {
    String testName = "testIsThisType";
    if (!initFile())
        result(testName, false, "initFile");
    boolean success = true;
    String msg = null;
    try {
        IFormatReader r = reader;
        // unwrap reader
        while (true) {
            if (r instanceof ReaderWrapper) {
                r = ((ReaderWrapper) r).getReader();
            } else if (r instanceof FileStitcher) {
                r = ((FileStitcher) r).getReader();
            } else
                break;
        }
        if (r instanceof ImageReader) {
            ImageReader ir = (ImageReader) r;
            r = ir.getReader();
            IFormatReader[] readers = ir.getReaders();
            String[] used = reader.getUsedFiles();
            for (int i = 0; i < used.length && success; i++) {
                // and only one reader, identifies the dataset as its own
                for (int j = 0; j < readers.length; j++) {
                    boolean result = readers[j].isThisType(used[i]);
                    // TIFF reader is allowed to redundantly green-light files
                    if (result && readers[j] instanceof TiffDelegateReader)
                        continue;
                    // green-light PIC files from NRRD datasets
                    if (result && r instanceof NRRDReader && readers[j] instanceof BioRadReader) {
                        String low = used[i].toLowerCase();
                        boolean isPic = low.endsWith(".pic") || low.endsWith(".pic.gz");
                        if (isPic)
                            continue;
                    }
                    // Analyze reader is allowed to redundantly accept NIfTI files
                    if (result && r instanceof NiftiReader && readers[j] instanceof AnalyzeReader) {
                        continue;
                    }
                    if (result && r instanceof MetamorphReader && readers[j] instanceof MetamorphTiffReader) {
                        continue;
                    }
                    if (result && (readers[j] instanceof L2DReader) || ((r instanceof L2DReader) && (readers[j] instanceof GelReader) || readers[j] instanceof L2DReader)) {
                        continue;
                    }
                    // ND2Reader is allowed to accept JPEG-2000 files
                    if (result && r instanceof JPEG2000Reader && readers[j] instanceof ND2Reader) {
                        continue;
                    }
                    if ((result && r instanceof APLReader && readers[j] instanceof SISReader) || (!result && r instanceof APLReader && readers[j] instanceof APLReader)) {
                        continue;
                    }
                    // reader to pick up TIFFs from a Prairie dataset
                    if (result && r instanceof PrairieReader && readers[j] instanceof OMETiffReader) {
                        continue;
                    }
                    // extra metadata files
                    if (result && r instanceof ColumbusReader && readers[j] instanceof OMETiffReader) {
                        continue;
                    }
                    // with an extra metadata file
                    if (result && r instanceof MicromanagerReader && readers[j] instanceof OMETiffReader) {
                        continue;
                    }
                    if (!result && r instanceof MicromanagerReader && readers[j] instanceof MicromanagerReader && (used[i].toLowerCase().endsWith(".ome.tif") || used[i].toLowerCase().endsWith(".ome.tiff"))) {
                        continue;
                    }
                    if (result && r instanceof TrestleReader && (readers[j] instanceof JPEGReader || readers[j] instanceof PGMReader || readers[j] instanceof TiffDelegateReader)) {
                        continue;
                    }
                    if (result && ((r instanceof HitachiReader) || (readers[j] instanceof HitachiReader && (r instanceof TiffDelegateReader || r instanceof JPEGReader || r instanceof BMPReader)))) {
                        continue;
                    }
                    if (result && r instanceof BDReader && readers[j] instanceof BMPReader) {
                        continue;
                    }
                    if (!result && readers[j] instanceof BDReader && (used[i].endsWith(".bmp") || used[i].endsWith(".adf") || used[i].endsWith(".txt") || used[i].endsWith(".roi"))) {
                        continue;
                    }
                    if (!result && r instanceof VolocityReader && readers[j] instanceof VolocityReader) {
                        continue;
                    }
                    if (!result && r instanceof InCellReader && readers[j] instanceof InCellReader && !used[i].toLowerCase().endsWith(".xdce")) {
                        continue;
                    }
                    if (!result && r instanceof BrukerReader && readers[j] instanceof BrukerReader && !used[i].toLowerCase().equals("acqp") && !used[i].toLowerCase().equals("fid")) {
                        continue;
                    }
                    // Volocity reader is allowed to accept files of other formats
                    if (result && r instanceof VolocityReader) {
                        continue;
                    }
                    if (result && r instanceof NikonReader && readers[j] instanceof DNGReader) {
                        continue;
                    }
                    // DICOM reader is not expected to pick up companion files
                    if (!result && r instanceof DicomReader && readers[j] instanceof DicomReader) {
                        continue;
                    }
                    // AFI reader is not expected to pick up .svs files
                    if (r instanceof AFIReader && (readers[j] instanceof AFIReader || readers[j] instanceof SVSReader)) {
                        continue;
                    }
                    if (!result && readers[j] instanceof MIASReader) {
                        continue;
                    }
                    if ((readers[j] instanceof NDPISReader || r instanceof NDPISReader) && used[i].toLowerCase().endsWith(".ndpi")) {
                        continue;
                    }
                    // Hamamatsu VMS dataset
                    if (readers[j] instanceof JPEGReader && r instanceof HamamatsuVMSReader && used[i].toLowerCase().endsWith(".jpg")) {
                        continue;
                    }
                    // the Hamamatsu VMS reader only picks up its .vms file
                    if (!result && !used[i].toLowerCase().endsWith(".vms") && r instanceof HamamatsuVMSReader) {
                        continue;
                    }
                    // QuickTime reader doesn't pick up resource forks
                    if (!result && i > 0 && r instanceof QTReader) {
                        continue;
                    }
                    if (r instanceof CellVoyagerReader && (!result || readers[j] instanceof OMEXMLReader) && used[i].toLowerCase().endsWith(".ome.xml")) {
                        continue;
                    }
                    // the pattern reader only picks up pattern files
                    if (!used[i].toLowerCase().endsWith(".pattern") && r instanceof FilePatternReader) {
                        continue;
                    }
                    // ignore companion files for Leica LIF
                    if (!used[i].toLowerCase().endsWith(".lif") && r instanceof LIFReader) {
                        continue;
                    }
                    boolean expected = r == readers[j];
                    if (result != expected) {
                        success = false;
                        if (result) {
                            msg = TestTools.shortClassName(readers[j]) + " flagged \"" + used[i] + "\" but so did " + TestTools.shortClassName(r);
                        } else {
                            msg = TestTools.shortClassName(readers[j]) + " skipped \"" + used[i] + "\"";
                        }
                        break;
                    }
                }
            }
        } else {
            success = false;
            msg = "Reader " + r.getClass().getName() + " is not an ImageReader";
        }
    } catch (Throwable t) {
        LOGGER.info("", t);
        success = false;
    }
    result(testName, success, msg);
}
Also used : FileStitcher(loci.formats.FileStitcher) IFormatReader(loci.formats.IFormatReader) ReaderWrapper(loci.formats.ReaderWrapper) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) Test(org.testng.annotations.Test)

Example 24 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class FileConvert method initialize.

/**
 * Set up the file reader and writer, ensuring that the input file is
 * associated with the reader and the output file is associated with the
 * writer.
 *
 * @return true if the reader and writer were successfully set up, or false
 *   if an error occurred
 */
private boolean initialize() {
    Exception exception = null;
    try {
        // construct the object that stores OME-XML metadata
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        IMetadata omexml = service.createOMEXMLMetadata();
        // set up the reader and associate it with the input file
        reader = new ImageReader();
        reader.setMetadataStore(omexml);
        reader.setId(inputFile);
        // set up the writer and associate it with the output file
        writer = new ImageWriter();
        writer.setMetadataRetrieve(omexml);
        writer.setInterleaved(reader.isInterleaved());
        writer.setId(outputFile);
    } catch (FormatException e) {
        exception = e;
    } catch (IOException e) {
        exception = e;
    } catch (DependencyException e) {
        exception = e;
    } catch (ServiceException e) {
        exception = e;
    }
    if (exception != null) {
        System.err.println("Failed to initialize files.");
        exception.printStackTrace();
    }
    return exception == null;
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ImageWriter(loci.formats.ImageWriter) IOException(java.io.IOException) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) FormatException(loci.formats.FormatException) ServiceException(loci.common.services.ServiceException) IOException(java.io.IOException) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Example 25 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class OverlappedTiledWriter method initialize.

/**
 * Set up the file reader and writer, ensuring that the input file is
 * associated with the reader and the output file is associated with the
 * writer.
 *
 * @return true if the reader and writer were successfully set up, or false
 *   if an error occurred
 * @throws DependencyException thrown if failed to create an OMEXMLService
 * @throws IOException thrown if unable to setup input or output stream for reader or writer
 * @throws FormatException thrown if invalid ID set for reader or writer or invalid tile size set
 * @throws ServiceException thrown if unable to create OME-XML meta data
 */
private void initialize() throws DependencyException, FormatException, IOException, ServiceException {
    // construct the object that stores OME-XML metadata
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata omexml = service.createOMEXMLMetadata();
    // set up the reader and associate it with the input file
    reader = new ImageReader();
    reader.setMetadataStore(omexml);
    reader.setId(inputFile);
    // set up the writer and associate it with the output file
    writer = new OMETiffWriter();
    writer.setMetadataRetrieve(omexml);
    writer.setInterleaved(reader.isInterleaved());
    // set the tile size height and width for writing
    this.tileSizeX = writer.setTileSizeX(tileSizeX);
    this.tileSizeY = writer.setTileSizeY(tileSizeY);
    writer.setId(outputFile);
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Aggregations

ImageReader (loci.formats.ImageReader)71 ServiceFactory (loci.common.services.ServiceFactory)23 OMEXMLService (loci.formats.services.OMEXMLService)23 FormatException (loci.formats.FormatException)20 IFormatReader (loci.formats.IFormatReader)20 IMetadata (loci.formats.meta.IMetadata)19 Test (org.testng.annotations.Test)15 IOException (java.io.IOException)11 ChannelFiller (loci.formats.ChannelFiller)11 DependencyException (loci.common.services.DependencyException)10 ServiceException (loci.common.services.ServiceException)10 ChannelSeparator (loci.formats.ChannelSeparator)10 MinMaxCalculator (loci.formats.MinMaxCalculator)10 BufferedImageReader (loci.formats.gui.BufferedImageReader)8 ImageWriter (loci.formats.ImageWriter)7 File (java.io.File)6 FileStitcher (loci.formats.FileStitcher)6 OMETiffWriter (loci.formats.out.OMETiffWriter)6 Location (loci.common.Location)5 DimensionSwapper (loci.formats.DimensionSwapper)5