use of loci.formats.ReaderWrapper in project bioformats by openmicroscopy.
the class OpenBytesPerformanceTest method setId.
@Test
public void setId() throws Exception {
reader = new ImageReader();
reader = new ChannelFiller(reader);
reader = new ChannelSeparator(reader);
reader = new MinMaxCalculator(reader);
if (memMap && reader.isSingleFile(id)) {
TestTools.mapFile(id);
}
StopWatch stopWatch = new Slf4JStopWatch();
reader.setId(id);
stopWatch.stop(String.format("%s.setId.%s", ((ReaderWrapper) reader).unwrap().getClass().getName(), filename));
seriesCount = reader.getSeriesCount();
}
use of loci.formats.ReaderWrapper 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);
}
use of loci.formats.ReaderWrapper 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);
}
use of loci.formats.ReaderWrapper 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.ReaderWrapper in project bioformats by openmicroscopy.
the class FormatReaderTest method testOMEXML.
@Test(groups = { "all", "xml", "fast", "automated" })
public void testOMEXML() {
String testName = "testOMEXML";
if (!initFile())
result(testName, false, "initFile");
String msg = null;
try {
MetadataRetrieve retrieve = (MetadataRetrieve) reader.getMetadataStore();
boolean success = omexmlService.isOMEXMLMetadata(retrieve);
if (!success)
msg = TestTools.shortClassName(retrieve);
for (int i = 0; i < reader.getSeriesCount() && msg == null; i++) {
reader.setSeries(i);
String type = FormatTools.getPixelTypeString(reader.getPixelType());
if (reader.getSizeX() != retrieve.getPixelsSizeX(i).getValue().intValue()) {
msg = "SizeX";
}
if (reader.getSizeY() != retrieve.getPixelsSizeY(i).getValue().intValue()) {
msg = "SizeY";
}
if (reader.getSizeZ() != retrieve.getPixelsSizeZ(i).getValue().intValue()) {
msg = "SizeZ";
}
if (reader.getSizeC() != retrieve.getPixelsSizeC(i).getValue().intValue()) {
msg = "SizeC";
}
if (reader.getSizeT() != retrieve.getPixelsSizeT(i).getValue().intValue()) {
msg = "SizeT";
}
// NB: OME-TIFF files do not have a BinData element under Pixels
IFormatReader r = reader.unwrap();
if (r instanceof FileStitcher)
r = ((FileStitcher) r).getReader();
if (r instanceof ReaderWrapper)
r = ((ReaderWrapper) r).unwrap();
if (!(r instanceof OMETiffReader)) {
boolean littleEndian = false;
if (retrieve.getPixelsBigEndian(i) != null) {
littleEndian = !retrieve.getPixelsBigEndian(i).booleanValue();
} else if (retrieve.getPixelsBinDataCount(i) == 0) {
littleEndian = !retrieve.getPixelsBinDataBigEndian(i, 0).booleanValue();
}
if (reader.isLittleEndian() != littleEndian) {
msg = "BigEndian";
}
}
if (!reader.getDimensionOrder().equals(retrieve.getPixelsDimensionOrder(i).toString())) {
msg = "DimensionOrder";
}
if (!type.equalsIgnoreCase(retrieve.getPixelsType(i).toString())) {
msg = "PixelType";
}
}
} catch (Throwable t) {
LOGGER.info("", t);
msg = t.getMessage();
}
result(testName, msg == null, msg);
}
Aggregations