use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class EditTiffG method openFile.
public void openFile(File f) {
try {
String id = f.getAbsolutePath();
String xml = new TiffParser(id).getComment();
setXML(xml);
file = f;
setTitle(TITLE + " - " + id);
} catch (IOException exc) {
showError(exc);
}
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class MinimalTiffReader method initTiffParser.
/**
* Reinitialize the underlying TiffParser.
*/
protected void initTiffParser() {
if (in == null) {
try {
in = new RandomAccessInputStream(getCurrentFile(), 16);
} catch (IOException e) {
LOGGER.error("Could not initialize stream", e);
}
}
tiffParser = new TiffParser(in);
tiffParser.setDoCaching(false);
tiffParser.setUse64BitOffsets(use64Bit);
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class TiffWriter method saveBytes.
// -- IFormatWriter API methods --
/**
* @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int)
*/
@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
IFD ifd = new IFD();
if (!sequential) {
TiffParser parser = new TiffParser(currentId);
try {
long[] ifdOffsets = parser.getIFDOffsets();
if (no < ifdOffsets.length) {
ifd = parser.getIFD(ifdOffsets[no]);
}
saveBytes(no, buf, ifd, x, y, w, h);
} finally {
RandomAccessInputStream tiffParserStream = parser.getStream();
if (tiffParserStream != null) {
tiffParserStream.close();
}
}
} else {
saveBytes(no, buf, ifd, x, y, w, h);
}
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class LeicaReader method findLEIFile.
// -- Helper methods --
/**
* Find the .lei file that belongs to the same dataset as the given file.
*/
private String findLEIFile(String baseFile) throws FormatException, IOException {
if (checkSuffix(baseFile, LEI_SUFFIX)) {
return baseFile;
} else if (checkSuffix(baseFile, TiffReader.TIFF_SUFFIXES) && isGroupFiles()) {
// need to find the associated .lei file
if (ifds == null)
super.initFile(baseFile);
in = new RandomAccessInputStream(baseFile, 16);
TiffParser tp = new TiffParser(in);
in.order(tp.checkHeader().booleanValue());
in.seek(0);
LOGGER.info("Finding companion file name");
// open the TIFF file and look for the "Image Description" field
ifds = tp.getIFDs();
if (ifds == null)
throw new FormatException("No IFDs found");
String descr = ifds.get(0).getComment();
// remove anything of the form "[blah]"
descr = descr.replaceAll("\\[.*.\\]\n", "");
// each remaining line in descr is a (key, value) pair,
// where '=' separates the key from the value
String lei = baseFile.substring(0, baseFile.lastIndexOf(File.separator) + 1);
StringBuilder suffix = new StringBuilder();
StringTokenizer lines = new StringTokenizer(descr, "\n");
String line = null, key = null, value = null;
while (lines.hasMoreTokens()) {
line = lines.nextToken();
if (line.indexOf('=') == -1)
continue;
key = line.substring(0, line.indexOf('=')).trim();
value = line.substring(line.indexOf('=') + 1).trim();
addGlobalMeta(key, value);
if (key.startsWith("Series Name")) {
suffix.append(value);
}
}
lei += suffix.toString();
// now open the LEI file
Location l = new Location(lei).getAbsoluteFile();
if (l.exists()) {
return lei;
} else {
if (!lei.endsWith("lei") && !lei.endsWith("LEI")) {
lei = lei.substring(0, lei.lastIndexOf(".") + 1);
String test = lei + "lei";
if (new Location(test).exists()) {
return test;
}
test = lei + "LEI";
if (new Location(test).exists()) {
return test;
}
}
l = l.getParentFile();
String[] list = l.list();
for (int i = 0; i < list.length; i++) {
if (checkSuffix(list[i], LEI_SUFFIX)) {
return new Location(l.getAbsolutePath(), list[i]).getAbsolutePath();
}
}
}
} else if (checkSuffix(baseFile, "raw") && isGroupFiles()) {
// check for that there is an .lei file in the same directory
String prefix = baseFile;
if (prefix.indexOf('.') != -1) {
prefix = prefix.substring(0, prefix.lastIndexOf("."));
}
Location lei = new Location(prefix + ".lei");
if (!lei.exists()) {
lei = new Location(prefix + ".LEI");
while (!lei.exists() && prefix.indexOf('_') != -1) {
prefix = prefix.substring(0, prefix.lastIndexOf("_"));
lei = new Location(prefix + ".lei");
if (!lei.exists())
lei = new Location(prefix + ".LEI");
}
}
if (lei.exists())
return lei.getAbsolutePath();
}
return null;
}
use of loci.formats.tiff.TiffParser in project bioformats by openmicroscopy.
the class LeicaReader method isThisType.
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
TiffParser tp = new TiffParser(stream);
IFD ifd = tp.getFirstIFD();
if (ifd == null)
return false;
return ifd.containsKey(new Integer(LEICA_MAGIC_TAG));
}
Aggregations