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));
}
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();
}
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;
}
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);
}
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);
}
Aggregations