use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class IvisionReader method openBytes.
/**
* @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
*/
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
int planeSize = getSizeX() * getSizeY() * getSizeC();
if (color16)
planeSize = 2 * (planeSize / 3);
else if (squareRoot)
planeSize *= 2;
else if (hasPaddingByte) {
planeSize += getSizeX() * getSizeY();
} else
planeSize *= FormatTools.getBytesPerPixel(getPixelType());
in.seek(imageOffset + planeSize * no);
if (color16) {
// TODO
throw new FormatException("16-bit color iVision files are not supported");
} else if (squareRoot) {
// TODO
throw new FormatException("Square-root iVision files are not supported");
} else if (hasPaddingByte) {
int next = 0;
in.skipBytes(y * getSizeX() * getSizeC());
for (int row = 0; row < h; row++) {
in.skipBytes(x * getSizeC());
for (int col = 0; col < w; col++) {
in.skipBytes(1);
in.read(buf, next, getSizeC());
next += getSizeC();
}
in.skipBytes(getSizeC() * (getSizeX() - w - x));
}
} else
readPlane(in, x, y, w, h, buf);
return buf;
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class KhorosReader 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.skipBytes(4);
in.order(true);
int dependency = in.readInt();
addGlobalMeta("Comment", in.readString(512));
in.order(dependency == 4 || dependency == 8);
CoreMetadata m = core.get(0);
m.sizeX = in.readInt();
m.sizeY = in.readInt();
in.skipBytes(28);
m.imageCount = in.readInt();
if (getImageCount() == 0)
m.imageCount = 1;
m.sizeC = in.readInt();
int type = in.readInt();
switch(type) {
case 0:
m.pixelType = FormatTools.INT8;
break;
case 1:
m.pixelType = FormatTools.UINT8;
break;
case 2:
m.pixelType = FormatTools.UINT16;
break;
case 4:
m.pixelType = FormatTools.INT32;
break;
case 5:
m.pixelType = FormatTools.FLOAT;
break;
case 9:
m.pixelType = FormatTools.DOUBLE;
break;
default:
throw new FormatException("Unsupported pixel type : " + type);
}
// read lookup table
in.skipBytes(12);
int c = in.readInt();
if (c > 1) {
m.sizeC = c;
int n = in.readInt();
lut = new byte[c][n];
in.skipBytes(436);
for (int i = 0; i < lut.length; i++) {
for (int j = 0; j < lut[0].length; j++) {
lut[i][j] = in.readByte();
}
}
} else
in.skipBytes(440);
offset = in.getFilePointer();
m.sizeZ = getImageCount();
m.sizeT = 1;
m.rgb = getSizeC() > 1;
m.interleaved = false;
m.littleEndian = dependency == 4 || dependency == 8;
m.dimensionOrder = "XYCZT";
m.indexed = lut != null;
m.falseColor = false;
m.metadataComplete = true;
if (isIndexed()) {
m.sizeC = 1;
m.rgb = false;
}
MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this);
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class L2DReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
if (!checkSuffix(id, "l2d") && isGroupFiles()) {
// find the corresponding .l2d file
Location parent = new Location(id).getAbsoluteFile().getParentFile();
parent = parent.getParentFile();
String[] list = parent.list();
for (String file : list) {
if (checkSuffix(file, "l2d")) {
initFile(new Location(parent, file).getAbsolutePath());
return;
}
}
throw new FormatException("Could not find .l2d file");
} else if (!isGroupFiles()) {
super.initFile(id);
tiffs = new String[][] { { id } };
TiffReader r = new TiffReader();
r.setMetadataStore(getMetadataStore());
r.setId(id);
core = new ArrayList<CoreMetadata>(r.getCoreMetadataList());
metadataStore = r.getMetadataStore();
final Map<String, Object> globalMetadata = r.getGlobalMetadata();
for (final Map.Entry<String, Object> entry : globalMetadata.entrySet()) {
addGlobalMeta(entry.getKey(), entry.getValue());
}
r.close();
reader = new MinimalTiffReader();
return;
}
super.initFile(id);
String[] scans = getScanNames();
Location parent = new Location(id).getAbsoluteFile().getParentFile();
// remove scan names that do not correspond to existing directories
final List<String> validScans = new ArrayList<String>();
for (String s : scans) {
Location scanDir = new Location(parent, s);
if (scanDir.exists() && scanDir.isDirectory())
validScans.add(s);
}
scans = validScans.toArray(new String[validScans.size()]);
// read metadata from each scan
tiffs = new String[scans.length][];
metadataFiles = new List[scans.length];
core = new ArrayList<CoreMetadata>(scans.length);
String[] comments = new String[scans.length];
String[] wavelengths = new String[scans.length];
String[] dates = new String[scans.length];
String model = null;
tileWidth = new int[scans.length];
tileHeight = new int[scans.length];
core.clear();
for (int i = 0; i < scans.length; i++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
setSeries(i);
metadataFiles[i] = new ArrayList<String>();
String scanName = scans[i] + ".scn";
Location scanDir = new Location(parent, scans[i]);
// read .scn file from each scan
String scanPath = new Location(scanDir, scanName).getAbsolutePath();
addDirectory(scanDir.getAbsolutePath(), i);
String scanData = DataTools.readFile(scanPath);
String[] lines = scanData.split("\n");
for (String line : lines) {
if (!line.startsWith("#")) {
String key = line.substring(0, line.indexOf('='));
String value = line.substring(line.indexOf('=') + 1);
addSeriesMeta(key, value);
if (key.equals("ExperimentNames")) {
// TODO : parse experiment metadata - this is typically a list of
// overlay shapes, or analysis data
} else if (key.equals("ImageNames")) {
tiffs[i] = value.split(",");
for (int t = 0; t < tiffs[i].length; t++) {
tiffs[i][t] = new Location(scanDir, tiffs[i][t].trim()).getAbsolutePath();
}
} else if (key.equals("Comments")) {
comments[i] = value;
} else if (key.equals("ScanDate")) {
dates[i] = value;
} else if (key.equals("ScannerName")) {
model = value;
} else if (key.equals("ScanChannels")) {
wavelengths[i] = value;
}
}
}
}
setSeries(0);
reader = new MinimalTiffReader();
MetadataStore store = makeFilterMetadata();
for (int i = 0; i < getSeriesCount(); i++) {
CoreMetadata ms = core.get(i);
ms.imageCount = tiffs[i].length;
ms.sizeC = tiffs[i].length;
ms.sizeT = 1;
ms.sizeZ = 1;
ms.dimensionOrder = "XYCZT";
reader.setId(tiffs[i][0]);
ms.sizeX = reader.getSizeX();
ms.sizeY = reader.getSizeY();
ms.sizeC *= reader.getSizeC();
ms.rgb = reader.isRGB();
ms.indexed = reader.isIndexed();
ms.littleEndian = reader.isLittleEndian();
ms.pixelType = reader.getPixelType();
tileWidth[i] = reader.getOptimalTileWidth();
tileHeight[i] = reader.getOptimalTileHeight();
}
MetadataTools.populatePixels(store, this);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageName(scans[i], i);
if (dates[i] != null) {
dates[i] = DateTools.formatDate(dates[i], DATE_FORMAT);
if (dates[i] != null) {
store.setImageAcquisitionDate(new Timestamp(dates[i]), i);
}
}
}
if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
String instrumentID = MetadataTools.createLSID("Instrument", 0);
store.setInstrumentID(instrumentID, 0);
for (int i = 0; i < getSeriesCount(); i++) {
store.setImageInstrumentRef(instrumentID, i);
store.setImageDescription(comments[i], i);
if (wavelengths[i] != null) {
String[] waves = wavelengths[i].split("[, ]");
if (waves.length < getEffectiveSizeC()) {
LOGGER.debug("Expected {} wavelengths; got {} wavelengths.", getEffectiveSizeC(), waves.length);
}
for (int q = 0; q < waves.length; q++) {
String laser = MetadataTools.createLSID("LightSource", 0, q);
store.setLaserID(laser, 0, q);
Double wave = new Double(waves[q].trim());
Length wavelength = FormatTools.getWavelength(wave);
if (wavelength != null) {
store.setLaserWavelength(wavelength, 0, q);
}
store.setLaserType(getLaserType("Other"), 0, q);
store.setLaserLaserMedium(getLaserMedium("Other"), 0, q);
store.setChannelLightSourceSettingsID(laser, i, q);
}
}
}
store.setMicroscopeModel(model, 0);
store.setMicroscopeType(getMicroscopeType("Other"), 0);
}
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class WrappedCodec method getOptions.
protected static ome.codecs.CodecOptions getOptions(CodecOptions options) throws FormatException {
if (options == null) {
return null;
}
ome.codecs.CodecOptions newOptions = null;
Class c = options.getClass();
if (c.equals(HuffmanCodecOptions.class)) {
newOptions = new ome.codecs.HuffmanCodecOptions();
copyOptions(options, newOptions);
((ome.codecs.HuffmanCodecOptions) newOptions).table = ((HuffmanCodecOptions) options).table;
} else if (c.equals(JPEG2000CodecOptions.class)) {
newOptions = new ome.codecs.JPEG2000CodecOptions();
copyOptions(options, newOptions);
((ome.codecs.JPEG2000CodecOptions) newOptions).codeBlockSize = ((JPEG2000CodecOptions) options).codeBlockSize;
((ome.codecs.JPEG2000CodecOptions) newOptions).numDecompositionLevels = ((JPEG2000CodecOptions) options).numDecompositionLevels;
((ome.codecs.JPEG2000CodecOptions) newOptions).resolution = ((JPEG2000CodecOptions) options).resolution;
((ome.codecs.JPEG2000CodecOptions) newOptions).writeBox = ((JPEG2000CodecOptions) options).writeBox;
} else if (c.equals(MJPBCodecOptions.class)) {
newOptions = new ome.codecs.MJPBCodecOptions();
copyOptions(options, newOptions);
((ome.codecs.MJPBCodecOptions) newOptions).interlaced = ((MJPBCodecOptions) options).interlaced;
} else if (c.equals(CodecOptions.class)) {
newOptions = new ome.codecs.CodecOptions();
copyOptions(options, newOptions);
} else {
throw new FormatException("Unwrapped codec: " + c.getName());
}
return newOptions;
}
use of loci.formats.FormatException in project bioformats by openmicroscopy.
the class WrappedCodec method unwrapCodecException.
static FormatException unwrapCodecException(ome.codecs.CodecException e) {
FormatException fe;
if (e.getMessage() != null) {
fe = new FormatException(e.getMessage());
} else {
fe = new FormatException();
}
if (e.getCause() != null) {
fe.initCause(e.getCause());
}
fe.setStackTrace(e.getStackTrace());
return fe;
}
Aggregations