lsmFilenames = parseMDB(id);
}
else lsmFilenames = new String[] {id};
if (lsmFilenames == null || lsmFilenames.length == 0) {
throw new FormatException("LSM files were not found.");
}
timestamps = new Vector<Double>();
imageNames = new Vector<String>();
xCoordinates = new Vector<Double>();
yCoordinates = new Vector<Double>();
zCoordinates = new Vector<Double>();
seriesCounts = new Hashtable<String, Integer>();
int seriesCount = 0;
Vector<String> validFiles = new Vector<String>();
for (String filename : lsmFilenames) {
try {
int extraSeries = getExtraSeries(filename);
seriesCounts.put(filename, extraSeries);
seriesCount += extraSeries;
validFiles.add(filename);
}
catch (IOException e) {
LOGGER.debug("Failed to parse " + filename, e);
}
}
lsmFilenames = validFiles.toArray(new String[validFiles.size()]);
core.clear();
for (int c=0; c<seriesCount; c++) {
CoreMetadata ms = new CoreMetadata();
core.add(ms);
}
channelNames = new String[seriesCount][];
ifdsList = new Vector<IFDList>();
ifdsList.setSize(seriesCount);
int realSeries = 0;
for (int i=0; i<lsmFilenames.length; i++) {
RandomAccessInputStream stream =
new RandomAccessInputStream(lsmFilenames[i]);
int count = seriesCounts.get(lsmFilenames[i]);
TiffParser tp = new TiffParser(stream);
Boolean littleEndian = tp.checkHeader();
long[] ifdOffsets = tp.getIFDOffsets();
int ifdsPerSeries = (ifdOffsets.length / 2) / count;
int offset = 0;
Object zeissTag = null;
for (int s=0; s<count; s++, realSeries++) {
CoreMetadata ms = core.get(realSeries);
ms.littleEndian = littleEndian;
IFDList ifds = new IFDList();
while (ifds.size() < ifdsPerSeries) {
tp.setDoCaching(offset == 0);
IFD ifd = tp.getIFD(ifdOffsets[offset]);
if (offset == 0) zeissTag = ifd.get(ZEISS_ID);
if (offset > 0 && ifds.size() == 0) {
ifd.putIFDValue(ZEISS_ID, zeissTag);
}
ifds.add(ifd);
if (zeissTag != null) offset += 2;
else offset++;
}
for (IFD ifd : ifds) {
tp.fillInIFD(ifd);
}
ifdsList.set(realSeries, ifds);
}
stream.close();
}
MetadataStore store = makeFilterMetadata();
lut = new byte[ifdsList.size()][][];
long[] previousStripOffsets = null;
for (int series=0; series<ifdsList.size(); series++) {
// IFD ordering is ZPT, so reset state if we have multiple timepoints
// this prevents offsets from being confused when the first offset in
// the next series is legitimately smaller than the last offset in
// the previous series
if (series > 0 && getSizeT() > 1) {
previousStripOffsets = null;
}
IFDList ifds = ifdsList.get(series);
for (IFD ifd : ifds) {
// check that predictor is set to 1 if anything other
// than LZW compression is used
if (ifd.getCompression() != TiffCompression.LZW) {
ifd.putIFDValue(IFD.PREDICTOR, 1);
}
}
// fix the offsets for > 4 GB files
RandomAccessInputStream s =
new RandomAccessInputStream(getLSMFileFromSeries(series));
for (int i=0; i<ifds.size(); i++) {
long[] stripOffsets = ifds.get(i).getStripOffsets();
if (stripOffsets == null || (i != 0 && previousStripOffsets == null)) {
throw new FormatException(
"Strip offsets are missing; this is an invalid file.");
}
else if (i == 0 && previousStripOffsets == null) {
previousStripOffsets = stripOffsets;
continue;