Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIF: fix offset calculation for certain datasets with multiple unstitched files #4222

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions components/formats-gpl/src/loci/formats/in/LIFReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,23 +573,48 @@ protected void initFile(String id) throws FormatException, IOException {

// correct offsets, if necessary
if (offsets.size() > getSeriesCount()) {
LOGGER.debug("Adjusting image offsets; found {} expected {}",
offsets.size(), getSeriesCount());
Long[] storedOffsets = offsets.toArray(new Long[offsets.size()]);
for (int i=0; i<storedOffsets.length; i++) {
LOGGER.debug("original offset #{} = {}", i, storedOffsets[i]);
LOGGER.debug(" bytes available = {}",
i == storedOffsets.length - 1 ? in.length() - storedOffsets[i] :
storedOffsets[i + 1] - storedOffsets[i]);
}

offsets.clear();
int index = 0;
for (int i=0; i<getSeriesCount(); i++) {
int tileCountIndex = 0;
for (int i=0; i<getSeriesCount(); i++, tileCountIndex++) {
setSeries(i);
long nBytes = (long) FormatTools.getPlaneSize(this) * getImageCount();
long tileBytes = (long) FormatTools.getPlaneSize(this) * getImageCount();
int currentTileCount = tileCount[tileCountIndex];
long nBytes = tileBytes * currentTileCount;
long start = storedOffsets[index];
long end = index == storedOffsets.length - 1 ? in.length() :
storedOffsets[index + 1];
while (end - start < nBytes && ((end - start) / nBytes) != 1) {
LOGGER.debug("Series {} needs {} bytes", i, nBytes);
LOGGER.debug(" index = {}", index);
LOGGER.debug(" start = {}, end = {}, total = {}", start, end, end - start);
while (end - start < nBytes && ((end - start) / nBytes) != 1 && index < storedOffsets.length - 1) {
index++;
start = storedOffsets[index];
end = index == storedOffsets.length - 1 ? in.length() :
storedOffsets[index + 1];
LOGGER.debug(" checking index = {}, start = {}, end = {}, total = {}",
index, start, end, end - start);
}
offsets.add(storedOffsets[index]);

// tiled image will have all tiles stored together,
// even though we split the tiles into separate series so they could be stitched later
// the size of 'offsets' should match the length of 'tileCount',
// so we don't store a separate offset for each tile
i += (currentTileCount - 1);

index++;
LOGGER.debug("offsets = {}, index = {}", offsets, index);
}
setSeries(0);
}
Expand Down