use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class Upgrade200909Test method setUp.
@BeforeMethod
public void setUp() throws Exception {
ServiceFactory sf = new ServiceFactory();
service = sf.getInstance(OMEXMLService.class);
InputStream s = Upgrade200909Test.class.getResourceAsStream(XML_FILE);
byte[] b = new byte[s.available()];
s.read(b);
s.close();
xml = new String(b);
metadata = service.createOMEXMLMetadata(xml);
ome = (OME) metadata.getRoot();
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class Upgrade201106Test method setUp.
@BeforeMethod
public void setUp() throws Exception {
ServiceFactory sf = new ServiceFactory();
service = sf.getInstance(OMEXMLService.class);
InputStream s = Upgrade201106Test.class.getResourceAsStream(XML_FILE);
byte[] b = new byte[s.available()];
s.read(b);
s.close();
xml = new String(b);
metadata = service.createOMEXMLMetadata(xml);
ome = (OME) metadata.getRoot();
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class ConvertToOmeTiff method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Usage: java ConvertToOmeTiff file1 file2 ...");
return;
}
ImageReader reader = new ImageReader();
OMETiffWriter writer = new OMETiffWriter();
for (int i = 0; i < args.length; i++) {
String id = args[i];
int dot = id.lastIndexOf(".");
String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".ome.tif";
System.out.print("Converting " + id + " to " + outId + " ");
// record metadata to OME-XML format
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata omexmlMeta = service.createOMEXMLMetadata();
reader.setMetadataStore(omexmlMeta);
reader.setId(id);
// configure OME-TIFF writer
writer.setMetadataRetrieve(omexmlMeta);
writer.setId(outId);
// writer.setCompression("J2K");
// write out image planes
int seriesCount = reader.getSeriesCount();
for (int s = 0; s < seriesCount; s++) {
reader.setSeries(s);
writer.setSeries(s);
int planeCount = reader.getImageCount();
for (int p = 0; p < planeCount; p++) {
byte[] plane = reader.openBytes(p);
// write plane to output file
writer.saveBytes(p, plane);
System.out.print(".");
}
}
writer.close();
reader.close();
System.out.println(" [done]");
}
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class DisplayHandler method displayOMEXML.
/**
* Displays OME-XML metadata in a tree in its own window.
*/
public XMLWindow displayOMEXML() throws FormatException, IOException {
if (!options.isShowOMEXML())
return null;
XMLWindow metaWindow = null;
metaWindow = new XMLWindow("OME Metadata - " + process.getIdName());
Exception exc = null;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metaWindow.setXML(service.getOMEXML(process.getOMEMetadata()));
WindowTools.placeWindow(metaWindow);
metaWindow.setVisible(true);
} catch (DependencyException e) {
exc = e;
} catch (ServiceException e) {
exc = e;
} catch (ParserConfigurationException e) {
exc = e;
} catch (SAXException e) {
exc = e;
}
if (exc != null)
throw new FormatException(exc);
// save reference to OME-XML window
xmlWindow = metaWindow;
return metaWindow;
}
use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.
the class ImportProcess method createBaseReader.
/**
* Initializes an {@link loci.formats.IFormatReader}
* according to the current configuration.
*/
private void createBaseReader() throws FormatException, IOException {
if (options.isLocal() || options.isHTTP()) {
BF.status(options.isQuiet(), "Identifying " + idName);
imageReader = LociPrefs.makeImageReader();
baseReader = imageReader.getReader(options.isUsingPatternIds() ? new FilePattern(options.getId()).getFiles()[0] : options.getId());
} else if (options.isOMERO()) {
BF.status(options.isQuiet(), "Establishing server connection");
try {
ReflectedUniverse r = new ReflectedUniverse();
r.exec("import loci.ome.io.OmeroReader");
r.exec("baseReader = new OmeroReader()");
ClassList<IFormatReader> classes = new ClassList<IFormatReader>(IFormatReader.class);
r.setVar("classes", classes);
r.exec("class = baseReader.getClass()");
r.exec("classes.addClass(class)");
imageReader = new ImageReader(classes);
baseReader = imageReader.getReader(options.getId());
} catch (Exception exc) {
WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem communicating with the server.");
cancel();
return;
}
} else {
WindowTools.reportException(null, options.isQuiet(), "Sorry, there has been an internal error: unknown data source");
cancel();
return;
}
// attach OME-XML metadata store
Exception exc = null;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
meta = service.createOMEXMLMetadata();
omeXML = null;
} catch (DependencyException de) {
exc = de;
} catch (ServiceException se) {
exc = se;
}
if (exc != null) {
WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem constructing the OME-XML metadata store");
throw new FormatException(exc);
}
baseReader.setMetadataStore(meta);
BF.status(options.isQuiet(), "");
DebugTools.enableIJLogging(IJ.debugMode);
}
Aggregations