use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class JPEGXRCodec method initialize.
// -- Helper methods --
/**
* Initializes the JPEG-XR dependency service. This is called at the
* beginning of the {@link #decompress} method to avoid having the
* constructor's method definition contain a checked exception.
*
* @throws FormatException If there is an error initializing JPEG-XR
* services.
*/
private void initialize() throws FormatException {
if (service != null)
return;
try {
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(JPEGXRService.class);
} catch (DependencyException e) {
throw new MissingLibraryException("JPEG-XR library not available", e);
}
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class VeecoReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
CoreMetadata m = core.get(0);
try {
ServiceFactory factory = new ServiceFactory();
netcdf = factory.getInstance(NetCDFService.class);
netcdf.setFile(id);
} catch (DependencyException e) {
throw new MissingLibraryException(e);
}
Vector<String> variableList = netcdf.getVariableList();
if (variableList.size() == 0) {
throw new FormatException("No image data found");
}
String imageName = variableList.get(0);
try {
image = netcdf.getVariableValue(imageName);
} catch (ServiceException e) {
throw new FormatException("Could not retrieve image data", e);
}
Hashtable<String, Object> attributes = netcdf.getVariableAttributes(imageName);
for (String attr : attributes.keySet()) {
addGlobalMeta(attr, attributes.get(attr));
}
if (image instanceof byte[][]) {
byte[][] byteImage = (byte[][]) image;
m.sizeX = byteImage[0].length;
m.sizeY = byteImage.length;
m.pixelType = FormatTools.INT8;
} else if (image instanceof short[][]) {
short[][] shortImage = (short[][]) image;
m.sizeX = shortImage[0].length;
m.sizeY = shortImage.length;
m.pixelType = FormatTools.INT16;
// set the endianness to use when unpacking pixels
// NetCDF may not return the pixels with a constant endianness,
// so this ensures that the reader corrects accordingly (see ticket 12085)
short nativeMin = 0;
short nativeMax = 0;
short swappedMin = 0;
short swappedMax = 0;
for (int y = 0; y < shortImage.length; y++) {
for (int x = 0; x < shortImage[y].length; x++) {
if (shortImage[y][x] < nativeMin) {
nativeMin = shortImage[y][x];
}
if (shortImage[y][x] > nativeMax) {
nativeMax = shortImage[y][x];
}
short swapped = DataTools.swap(shortImage[y][x]);
if (swapped < swappedMin) {
swappedMin = swapped;
}
if (swapped > swappedMax) {
swappedMax = swapped;
}
}
}
unpackEndian = nativeMin <= swappedMin && nativeMax >= swappedMax;
}
m.sizeZ = 1;
m.sizeC = 1;
m.sizeT = 1;
m.imageCount = m.sizeZ * m.sizeC * m.sizeT;
m.dimensionOrder = "XYCZT";
m.littleEndian = false;
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class CellH5Writer method setId.
// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
if (id.equals(currentId))
return;
super.setId(id);
try {
ServiceFactory factory = new ServiceFactory();
jhdf = factory.getInstance(JHDFService.class);
jhdf.setFileForWrite(id);
} catch (DependencyException e) {
throw new MissingLibraryException(JHDFServiceImpl.NO_JHDF_MSG, e);
}
MetadataRetrieve retrieve = getMetadataRetrieve();
int sizeX = retrieve.getPixelsSizeX(0).getValue();
int sizeY = retrieve.getPixelsSizeY(0).getValue();
int sizeZ = retrieve.getPixelsSizeZ(0).getValue();
int sizeC = retrieve.getPixelsSizeC(0).getValue();
int sizeT = retrieve.getPixelsSizeT(0).getValue();
int type = FormatTools.pixelTypeFromString(retrieve.getPixelsType(0).toString());
bpp = FormatTools.getBytesPerPixel(type);
LOGGER.info("CellH5Writer: Found image with dimensions XYZCT {}x{}x{}x{}x{}, and bits per pixel {}", sizeX, sizeY, sizeZ, sizeC, sizeT, bpp);
String plate = "PLATE_00";
String well = "WELL_00";
int site = 1;
if (retrieve.getPlateCount() > 0) {
plate = retrieve.getPlateName(0);
well = retrieve.getWellExternalIdentifier(0, 0);
site = retrieve.getWellSampleIndex(0, 0, 0).getValue();
LOGGER.info("CellH5Writer: Found plate information Plate / Well / Site {} / {} / {}", plate, well, site);
} else {
LOGGER.info("CellH5Writer: No plate information found. Using default values...");
}
jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.OBJECT);
jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.FEATURE);
jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.IMAGE);
outputPath = String.format("/sample/0/plate/%s/experiment/%s/position/%d/image/channel", plate, well, site);
jhdf.initIntArray(outputPath, new long[] { sizeC, sizeT, sizeZ, sizeY, sizeX }, bpp);
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class OMEXMLReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
in = new RandomAccessInputStream(id);
in.setEncoding("ASCII");
binData = new ArrayList<BinData>();
binDataOffsets = new ArrayList<Long>();
compression = new ArrayList<String>();
DefaultHandler handler = new OMEXMLHandler();
try {
RandomAccessInputStream s = new RandomAccessInputStream(id);
XMLTools.parseXML(s, handler);
s.close();
} catch (IOException e) {
throw new FormatException("Malformed OME-XML", e);
}
int lineNumber = 1;
for (BinData bin : binData) {
int line = bin.getRow();
int col = bin.getColumn();
while (lineNumber < line) {
in.readLine();
lineNumber++;
}
binDataOffsets.add(in.getFilePointer() + col - 1);
}
LOGGER.info("Populating metadata");
OMEXMLMetadata omexmlMeta;
OMEXMLService service;
try {
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(OMEXMLService.class);
omexmlMeta = service.createOMEXMLMetadata(omexml);
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
} catch (ServiceException se) {
throw new FormatException(se);
}
hasSPW = omexmlMeta.getPlateCount() > 0;
// TODO
// Hashtable originalMetadata = omexmlMeta.getOriginalMetadata();
// if (originalMetadata != null) metadata = originalMetadata;
int numDatasets = omexmlMeta.getImageCount();
int oldSeries = getSeries();
core.clear();
for (int i = 0; i < numDatasets; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
setSeries(i);
Integer w = omexmlMeta.getPixelsSizeX(i).getValue();
Integer h = omexmlMeta.getPixelsSizeY(i).getValue();
Integer t = omexmlMeta.getPixelsSizeT(i).getValue();
Integer z = omexmlMeta.getPixelsSizeZ(i).getValue();
Integer c = omexmlMeta.getPixelsSizeC(i).getValue();
if (w == null || h == null || t == null || z == null | c == null) {
throw new FormatException("Image dimensions not found");
}
Boolean endian = null;
if (binData.size() > 0) {
endian = false;
if (omexmlMeta.getPixelsBigEndian(i) != null) {
endian = omexmlMeta.getPixelsBigEndian(i).booleanValue();
} else if (omexmlMeta.getPixelsBinDataCount(i) != 0) {
endian = omexmlMeta.getPixelsBinDataBigEndian(i, 0).booleanValue();
}
}
String pixType = omexmlMeta.getPixelsType(i).toString();
ms.dimensionOrder = omexmlMeta.getPixelsDimensionOrder(i).toString();
ms.sizeX = w.intValue();
ms.sizeY = h.intValue();
ms.sizeT = t.intValue();
ms.sizeZ = z.intValue();
ms.sizeC = c.intValue();
ms.imageCount = getSizeZ() * getSizeC() * getSizeT();
ms.littleEndian = endian == null ? false : !endian.booleanValue();
ms.rgb = false;
ms.interleaved = false;
ms.indexed = false;
ms.falseColor = true;
ms.pixelType = FormatTools.pixelTypeFromString(pixType);
ms.orderCertain = true;
if (omexmlMeta.getPixelsSignificantBits(i) != null) {
ms.bitsPerPixel = omexmlMeta.getPixelsSignificantBits(i).getValue();
}
}
setSeries(oldSeries);
// populate assigned metadata store with the
// contents of the internal OME-XML metadata object
MetadataStore store = getMetadataStore();
service.convertMetadata(omexmlMeta, store);
MetadataTools.populatePixels(store, this, false, false);
}
use of loci.formats.MissingLibraryException in project bioformats by openmicroscopy.
the class TiffJAIReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
LOGGER.info("Checking for JAI");
try {
r = new ReflectedUniverse();
r.exec("import javax.media.jai.NullOpImage");
r.exec("import javax.media.jai.OpImage");
r.exec("import com.sun.media.jai.codec.FileSeekableStream");
r.exec("import com.sun.media.jai.codec.ImageDecoder");
r.exec("import com.sun.media.jai.codec.ImageCodec");
} catch (ReflectException exc) {
throw new MissingLibraryException(NO_JAI_MSG, exc);
}
super.initFile(id);
LOGGER.info("Reading movie dimensions");
// map Location to File or RandomAccessFile, if possible
IRandomAccess ira = Location.getMappedFile(id);
if (ira != null) {
if (ira instanceof FileHandle) {
FileHandle fh = (FileHandle) ira;
r.setVar("file", fh.getRandomAccessFile());
} else {
throw new FormatException("Unsupported handle type" + ira.getClass().getName());
}
} else {
String mapId = Location.getMappedId(id);
File file = new File(mapId);
if (file.exists()) {
r.setVar("file", file);
} else
throw new FileNotFoundException(id);
}
r.setVar("tiff", "tiff");
r.setVar("param", null);
// create TIFF decoder
int numPages;
try {
r.exec("s = new FileSeekableStream(file)");
r.exec("dec = ImageCodec.createImageDecoder(tiff, s, param)");
numPages = ((Integer) r.exec("dec.getNumPages()")).intValue();
} catch (ReflectException exc) {
throw new FormatException(exc);
}
if (numPages < 0) {
throw new FormatException("Invalid page count: " + numPages);
}
// decode first image plane
BufferedImage img = openBufferedImage(0);
if (img == null)
throw new FormatException("Invalid image stream");
LOGGER.info("Populating metadata");
CoreMetadata m = core.get(0);
m.imageCount = numPages;
m.sizeX = img.getWidth();
m.sizeY = img.getHeight();
m.sizeZ = 1;
m.sizeC = img.getSampleModel().getNumBands();
m.sizeT = numPages;
m.rgb = m.sizeC > 1;
m.dimensionOrder = "XYCZT";
m.pixelType = AWTImageTools.getPixelType(img);
m.interleaved = true;
m.littleEndian = false;
m.metadataComplete = true;
m.indexed = false;
m.falseColor = false;
// populate the metadata store
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
Aggregations