Search in sources :

Example 36 with ImageReader

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

the class PrintFormatTable method printSupportedFormats.

public static void printSupportedFormats(String[] args) {
    PrintStyles printStyle = PrintStyles.TXT;
    boolean usage = false;
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-help"))
                usage = true;
            else if (args[i].equals("-xml"))
                printStyle = PrintStyles.XML;
            else if (args[i].equals("-html"))
                printStyle = PrintStyles.HTML;
            else if (args[i].equals("-txt"))
                printStyle = PrintStyles.TXT;
            else {
                LOGGER.warn("unknown flag: {}; try -help for options", args[i]);
            }
        }
    }
    if (usage) {
        LOGGER.info("Usage: formatlist [-html] [-txt] [-xml]");
        LOGGER.info("  -html: show formats in an HTML table");
        LOGGER.info("   -txt: show formats in plaintext (default)");
        LOGGER.info("   -xml: show formats as XML data");
        return;
    }
    LOGGER.info(getHeader(printStyle));
    // retrieve all of the file format readers and writers
    ImageReader baseReader = new ImageReader();
    IFormatReader[] readers = baseReader.getReaders();
    ImageWriter baseWriter = new ImageWriter();
    IFormatWriter[] writers = baseWriter.getWriters();
    for (int i = 0; i < readers.length; i++) {
        String readerFormatName = readers[i].getFormat();
        boolean read = true;
        boolean write = false;
        boolean wmp = false;
        // check if there is a corresponding writer
        IFormatWriter writer = null;
        for (int j = 0; j < writers.length; j++) {
            if (writers[j].getFormat().equals(readerFormatName)) {
                writer = writers[j];
            }
        }
        if (writer != null) {
            write = true;
            // written to a single file
            if (writer.canDoStacks())
                wmp = true;
        }
        String[] extensions = readers[i].getSuffixes();
        StringBuilder ext = new StringBuilder();
        for (int j = 0; j < extensions.length; j++) {
            ext.append(extensions[j]);
            if (j < extensions.length - 1) {
                ext.append(", ");
            }
        }
        // display information about the format
        LOGGER.info(getFormatLine(printStyle, readerFormatName, read, write, wmp, ext.toString()));
    }
    LOGGER.info(getFooter(printStyle));
}
Also used : IFormatWriter(loci.formats.IFormatWriter) IFormatReader(loci.formats.IFormatReader) ImageWriter(loci.formats.ImageWriter) ImageReader(loci.formats.ImageReader)

Example 37 with ImageReader

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

the class ImageConverterTest method checkImage.

public void checkImage() throws FormatException, IOException {
    IFormatReader r = new ImageReader();
    r.setId(outFile.getAbsolutePath());
    assertEquals(r.getSizeX(), 512);
    r.close();
}
Also used : IFormatReader(loci.formats.IFormatReader) ImageReader(loci.formats.ImageReader)

Example 38 with ImageReader

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

the class GUITools method buildFileFilters.

// -- File chooser --
/**
 * Constructs a list of file filters for the given file format handler.
 */
public static FileFilter[] buildFileFilters(IFormatHandler handler) {
    FileFilter[] filters = null;
    // unwrap reader
    while (true) {
        if (handler instanceof ReaderWrapper) {
            handler = ((ReaderWrapper) handler).getReader();
        } else if (handler instanceof FileStitcher) {
            handler = ((FileStitcher) handler).getReader();
        } else if (handler instanceof WriterWrapper) {
            handler = ((WriterWrapper) handler).getWriter();
        } else
            break;
    }
    // handle special cases of ImageReader and ImageWriter
    if (handler instanceof ImageReader) {
        ImageReader imageReader = (ImageReader) handler;
        IFormatReader[] readers = imageReader.getReaders();
        Vector filterList = new Vector();
        Vector comboList = new Vector();
        for (int i = 0; i < readers.length; i++) {
            filterList.add(new FormatFileFilter(readers[i]));
            // NB: Some readers need to open a file to determine if it is the
            // proper type, when the extension alone is insufficient to
            // distinguish. This behavior is fine for individual filters, but not
            // for ImageReader's combination filter, because it makes the combo
            // filter too slow. So rather than composing the combo filter from
            // FormatFileFilters, we use faster but less accurate
            // ExtensionFileFilters instead.
            String[] suffixes = readers[i].getSuffixes();
            String format = readers[i].getFormat();
            comboList.add(new ExtensionFileFilter(suffixes, format));
        }
        comboList.add(new NoExtensionFileFilter());
        FileFilter combo = makeComboFilter(sortFilters(comboList));
        if (combo != null)
            filterList.add(combo);
        filters = sortFilters(filterList);
    } else if (handler instanceof ImageWriter) {
        IFormatWriter[] writers = ((ImageWriter) handler).getWriters();
        Vector filterList = new Vector();
        for (int i = 0; i < writers.length; i++) {
            String[] suffixes = writers[i].getSuffixes();
            String format = writers[i].getFormat();
            filterList.add(new ExtensionFileFilter(suffixes, format));
        }
        filters = sortFilters(filterList);
    } else // handle default reader and writer cases
    if (handler instanceof IFormatReader) {
        IFormatReader reader = (IFormatReader) handler;
        filters = new FileFilter[] { new FormatFileFilter(reader) };
    } else {
        String[] suffixes = handler.getSuffixes();
        String format = handler.getFormat();
        filters = new FileFilter[] { new ExtensionFileFilter(suffixes, format) };
    }
    return filters;
}
Also used : IFormatReader(loci.formats.IFormatReader) ImageWriter(loci.formats.ImageWriter) ReaderWrapper(loci.formats.ReaderWrapper) WriterWrapper(loci.formats.WriterWrapper) FileStitcher(loci.formats.FileStitcher) FileFilter(javax.swing.filechooser.FileFilter) ImageReader(loci.formats.ImageReader) Vector(java.util.Vector)

Example 39 with ImageReader

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

the class Schema_Transform_Test method setUp.

/**
 * Overridden to initialize the list.
 *
 * @see AbstractServerTest#setUp()
 */
@Override
@BeforeClass
protected void setUp() throws Exception {
    super.setUp();
    upgrades = new HashMap<String, List<String>>();
    downgrades = currentSchema();
    windowsOS = (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1);
    factory = new ServiceFactory();
    service = factory.getInstance(OMEXMLService.class);
    metadata = service.createOMEXMLMetadata();
    reader = new ImageReader();
    reader.setMetadataStore(metadata);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService) BeforeClass(org.testng.annotations.BeforeClass)

Example 40 with ImageReader

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

the class SixteenBitLosslessJPEG2000Test method testLosslessPixels.

@Test
public void testLosslessPixels() throws Exception {
    int failureCount = 0;
    for (int v = Short.MIN_VALUE; v < Short.MAX_VALUE; v += increment) {
        int index = v + Short.MAX_VALUE + 1;
        byte[] pixels = DataTools.shortToBytes((short) v, false);
        String file = index + ".jp2";
        ByteArrayHandle tmpFile = new ByteArrayHandle(1);
        Location.mapFile(file, tmpFile);
        IMetadata metadata16;
        try {
            ServiceFactory factory = new ServiceFactory();
            OMEXMLService service = factory.getInstance(OMEXMLService.class);
            metadata16 = service.createOMEXMLMetadata();
        } catch (DependencyException exc) {
            throw new FormatException("Could not create OME-XML store.", exc);
        } catch (ServiceException exc) {
            throw new FormatException("Could not create OME-XML store.", exc);
        }
        MetadataTools.populateMetadata(metadata16, 0, "foo", false, "XYCZT", "uint16", 1, 1, 1, 1, 1, 1);
        IFormatWriter writer16 = new JPEG2000Writer();
        writer16.setMetadataRetrieve(metadata16);
        writer16.setId(file);
        writer16.saveBytes(0, pixels);
        writer16.close();
        byte[] buf = tmpFile.getBytes();
        byte[] realData = new byte[(int) tmpFile.length()];
        System.arraycopy(buf, 0, realData, 0, realData.length);
        tmpFile.close();
        tmpFile = new ByteArrayHandle(realData);
        Location.mapFile(file, tmpFile);
        ImageReader reader = new ImageReader();
        reader.setId(file);
        byte[] plane = reader.openBytes(0);
        for (int q = 0; q < plane.length; q++) {
            if (plane[q] != pixels[q]) {
                LOGGER.debug("FAILED on {}", DataTools.bytesToShort(pixels, false));
                failureCount++;
                break;
            }
        }
        reader.close();
        tmpFile.close();
        Location.mapFile(file, null);
    }
    assertEquals(failureCount, 0);
}
Also used : JPEG2000Writer(loci.formats.out.JPEG2000Writer) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) IFormatWriter(loci.formats.IFormatWriter) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ByteArrayHandle(loci.common.ByteArrayHandle) ImageReader(loci.formats.ImageReader) Test(org.testng.annotations.Test)

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