use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class MetamorphTiffReader 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 {
if (getSeriesCount() == 1 && files.length == 1 && !dualCamera) {
return super.openBytes(no, buf, x, y, w, h);
}
int[] lengths = new int[] { getSizeZ(), getEffectiveSizeC(), fieldColumnCount, fieldRowCount, wellCount, getSizeT() };
int[] zct = getZCTCoords(no);
Well well = getWell(getSeries());
int[] position = new int[] { zct[0], zct[1], well.fieldCol, well.fieldRow, well.well, zct[2] };
if (dualCamera) {
position[1] = 0;
}
int fileIndex = FormatTools.positionToRaster(lengths, position);
final RandomAccessInputStream s;
if (fileIndex < files.length) {
s = new RandomAccessInputStream(files[fileIndex]);
} else {
s = new RandomAccessInputStream(files[0]);
}
TiffParser parser = new TiffParser(s);
int ndx = getSeries() * getSizeZ() * getSizeT() + no;
int[] pos = getZCTCoords(no);
if (dualCamera) {
int channel = pos[1];
pos[1] = 0;
ndx = getSeries() * getSizeZ() * getSizeT() + FormatTools.positionToRaster(new int[] { getSizeZ(), 1, getSizeT() }, pos);
pos[1] = channel;
}
IFD ifd = files.length == 1 ? ifds.get(ndx) : parser.getFirstIFD();
int realX = dualCamera ? (pos[1] == 0 ? x : x + pos[1] * getSizeX()) : x;
parser.getSamples(ifd, buf, realX, y, w, h);
s.close();
return buf;
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class MetamorphTiffReader method parseFile.
private void parseFile(String tiff, MetamorphHandler handler) throws IOException {
RandomAccessInputStream s = new RandomAccessInputStream(tiff);
TiffParser parser = new TiffParser(s);
IFD firstIFD = parser.getFirstIFD();
String xml = XMLTools.sanitizeXML(firstIFD.getComment());
XMLTools.parseXML(xml, handler);
s.close();
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class MetamorphTiffReader method isThisType.
// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
TiffParser tp = new TiffParser(stream);
String comment = tp.getComment();
if (comment == null)
return false;
comment = comment.trim();
return comment.startsWith("<MetaData>") && comment.endsWith("</MetaData>");
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class NDPIReader method isThisType.
// -- IFormatReader API methods --
/* (non-Javadoc)
* @see loci.formats.FormatReader#isThisType(java.lang.String, boolean)
*/
@Override
public boolean isThisType(String name, boolean open) {
boolean isThisType = super.isThisType(name, open);
if (isThisType && open) {
RandomAccessInputStream stream = null;
TiffParser parser = null;
try {
stream = new RandomAccessInputStream(name);
parser = new TiffParser(stream);
parser.setDoCaching(false);
parser.setUse64BitOffsets(stream.length() >= Math.pow(2, 32));
if (!parser.isValidHeader()) {
return false;
}
IFD ifd = parser.getFirstIFD();
if (ifd == null) {
return false;
}
return ifd.containsKey(MARKER_TAG);
} catch (IOException e) {
LOGGER.debug("I/O exception during isThisType() evaluation.", e);
return false;
} finally {
try {
if (stream != null) {
stream.close();
}
if (parser != null) {
parser.getStream().close();
}
} catch (IOException e) {
LOGGER.debug("I/O exception during stream closure.", e);
}
}
}
return isThisType;
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class NDPISReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
Location parent = new Location(id).getAbsoluteFile().getParentFile();
String[] lines = DataTools.readFile(currentId).split("\r\n");
for (String line : lines) {
int eq = line.indexOf('=');
if (eq < 0) {
continue;
}
String key = line.substring(0, eq).trim();
String value = line.substring(eq + 1).trim();
if (key.equals("NoImages")) {
ndpiFiles = new String[Integer.parseInt(value)];
readers = new ChannelSeparator[ndpiFiles.length];
} else if (key.startsWith("Image")) {
int index = Integer.parseInt(key.replaceAll("Image", ""));
ndpiFiles[index] = new Location(parent, value).getAbsolutePath();
readers[index] = new ChannelSeparator(new NDPIReader());
readers[index].setFlattenedResolutions(hasFlattenedResolutions());
}
}
MetadataStore store = makeFilterMetadata();
readers[0].getReader().setMetadataStore(store);
readers[0].setId(ndpiFiles[0]);
core = new ArrayList<CoreMetadata>(readers[0].getCoreMetadataList());
for (int i = 0; i < core.size(); i++) {
CoreMetadata ms = core.get(i);
ms.sizeC = readers.length;
ms.rgb = false;
ms.imageCount = ms.sizeC * ms.sizeZ * ms.sizeT;
}
MetadataTools.populatePixels(store, this);
bandUsed = new int[ndpiFiles.length];
IFD ifd;
for (int c = 0; c < readers.length; c++) {
// populate channel names based on IFD entry
try (RandomAccessInputStream in = new RandomAccessInputStream(ndpiFiles[c])) {
TiffParser tp = new TiffParser(in);
ifd = tp.getIFDs().get(0);
}
String channelName = ifd.getIFDStringValue(TAG_CHANNEL);
Float wavelength = (Float) ifd.getIFDValue(TAG_EMISSION_WAVELENGTH);
store.setChannelName(channelName, 0, c);
store.setChannelEmissionWavelength(new Length(wavelength, UNITS.NANOMETER), 0, c);
bandUsed[c] = 0;
if (ifd.getSamplesPerPixel() >= 3) {
// 580 < wavelength <= 780 Red
if (380 < wavelength && wavelength <= 490)
bandUsed[c] = 2;
else if (490 < wavelength && wavelength <= 580)
bandUsed[c] = 1;
else if (580 < wavelength && wavelength <= 780)
bandUsed[c] = 0;
}
}
}
Aggregations