use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class CellH5Writer method saveBytes.
/**
* Saves the given image to the specified (possibly already open) file.
*/
@Override
public void saveBytes(int no, byte[] buf) throws IOException, FormatException {
LOGGER.info("CellH5Writer: Save image to HDF5 path: " + outputPath);
MetadataRetrieve r = getMetadataRetrieve();
int sizeX = r.getPixelsSizeX(series).getValue();
int sizeY = r.getPixelsSizeY(series).getValue();
int sizeC = r.getPixelsSizeC(series).getValue();
int sizeT = r.getPixelsSizeT(series).getValue();
int sizeZ = r.getPixelsSizeZ(series).getValue();
DimensionOrder dimo = r.getPixelsDimensionOrder(0);
int c, z, t;
if (dimo.equals(DimensionOrder.XYCZT)) {
c = no % sizeC;
z = ((no - c) / sizeC) % sizeZ;
t = (((no - c) / sizeC)) / sizeZ;
} else if (dimo.equals(DimensionOrder.XYCTZ)) {
c = no % sizeC;
t = ((no - c) / sizeC) % sizeT;
z = (((no - c) / sizeC)) / sizeT;
} else if (dimo.equals(DimensionOrder.XYZTC)) {
z = no % sizeZ;
t = ((no - z) / sizeZ) % sizeT;
c = (((no - z) / sizeZ)) / sizeT;
} else {
throw new FormatException("CellH5Writer: Dimension order not understood: " + dimo.getValue());
}
LOGGER.info("CellH5Writer.saveBytes(): Current c, t, z == {} {} {}", c, t, z);
LOGGER.info("CellH5Writer.saveBytes(): bpp {} byte buffer len {}", bpp, buf.length);
if (bpp == 1) {
MDByteArray image = new MDByteArray(new int[] { 1, 1, 1, sizeY, sizeX });
for (int x_i = 0; x_i < sizeX; x_i++) {
for (int y_i = 0; y_i < sizeY; y_i++) {
byte value = (byte) buf[y_i * sizeX + x_i];
image.set(value, 0, 0, 0, y_i, x_i);
}
}
jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
} else if (bpp == 2) {
ByteBuffer bb = ByteBuffer.wrap(buf);
ShortBuffer sb = bb.asShortBuffer();
MDShortArray image = new MDShortArray(new int[] { 1, 1, 1, sizeY, sizeX });
for (int x_i = 0; x_i < sizeX; x_i++) {
for (int y_i = 0; y_i < sizeY; y_i++) {
short value = sb.get(y_i * sizeX + x_i);
image.set(value, 0, 0, 0, y_i, x_i);
}
}
jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
} else if (bpp == 4) {
ByteBuffer bb = ByteBuffer.wrap(buf);
IntBuffer ib = bb.asIntBuffer();
MDIntArray image = new MDIntArray(new int[] { 1, 1, 1, sizeY, sizeX });
for (int x_i = 0; x_i < sizeX; x_i++) {
for (int y_i = 0; y_i < sizeY; y_i++) {
int value = (int) ib.get(y_i * sizeX + x_i);
image.set(value, 0, 0, 0, y_i, x_i);
}
}
jhdf.writeArraySlice(outputPath, image, new long[] { c, t, z, 0, 0 });
} else {
throw new FormatException("CellH5Writer: Pixel type not supported");
}
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class PrintROIs method main.
public static void main(String[] args) throws Exception {
ImageReader reader = new ImageReader();
IMetadata omexml;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
omexml = 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);
}
reader.setMetadataStore(omexml);
reader.setId(args[0]);
printAllROIs(omexml);
System.out.println();
for (int series = 0; series < reader.getSeriesCount(); series++) {
printSeriesROIs(omexml, series);
}
reader.close();
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class WlzServiceImpl method saveBytes.
@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
if (state == WLZ_SERVICE_WRITE) {
WlzIVertex3 og = new WlzIVertex3(x + bBox.xMin, y + bBox.yMin, no + bBox.zMin);
WlzIVertex2 sz = new WlzIVertex2(w, h);
try {
wlzObj = WlzObject.WlzBuildObj3B(wlzObj, og, sz, objGType, buf.length, buf);
} catch (WlzException e) {
throw new FormatException("Failed save bytes to Woolz object", e);
}
}
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class WlzServiceImpl method open.
@Override
public void open(String file, String rw) throws FormatException, IOException {
try {
String[] v = new String[1];
WlzObject.WlzGetVersion(v);
wlzVersion = new String(v[0]);
} catch (UnsatisfiedLinkError e) {
throw new FormatException(NO_WLZ_MSG, e);
}
if (rw.equals("r")) {
openRead(file);
} else if (rw.equals("w")) {
openWrite(file);
} else {
throw new IOException("Failed to open file " + file);
}
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class CellWorxReader method getReader.
private IFormatReader getReader(String file, boolean omexml) throws FormatException, IOException {
IFormatReader pnl = new DeltavisionReader();
if (checkSuffix(file, "tif")) {
pnl = new MetamorphReader();
}
if (omexml) {
IMetadata metadata;
try {
metadata = service.createOMEXMLMetadata();
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
pnl.setMetadataStore(metadata);
}
pnl.setId(file);
return pnl;
}
Aggregations