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

Zeiss CZI: fix assembly of overlapping tiles #1787

Merged
merged 2 commits into from
May 18, 2015
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
32 changes: 6 additions & 26 deletions components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)

Region image = new Region(x, y, w, h);

int currentX = 0;
int currentY = 0;

int bpp = FormatTools.getBytesPerPixel(getPixelType());
int pixel = getRGBChannelCount() * bpp;
int outputRowLen = w * pixel;
Expand All @@ -312,7 +309,6 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
if (planes.size() == getImageCount()) {
validScanDim = false;
}
int previousHeight = 0;

Arrays.fill(buf, (byte) 0);
RandomAccessInputStream stream = new RandomAccessInputStream(currentId);
Expand All @@ -321,33 +317,29 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
if ((plane.seriesIndex == currentSeries && plane.planeIndex == no) ||
(plane.planeIndex == previousChannel && validScanDim))
{
byte[] rawData = new SubBlock(plane).readPixelData();

if ((prestitched != null && prestitched) || validScanDim) {
int realX = plane.x;
int realY = plane.y;

if (prestitched == null) {
currentY = 0;
}

Region tile = new Region(plane.col, plane.row, realX, realY);
if (validScanDim) {
tile.y += (no / getSizeC());
image.height = scanDim;
}

if (tile.intersects(image)) {
byte[] rawData = new SubBlock(plane).readPixelData();
Region intersection = tile.intersection(image);
int intersectionX = 0;

if (tile.x < image.x) {
intersectionX = image.x - tile.x;
}

if (tile.x == 0 && outputCol > 0) {
outputCol = 0;
outputRow += previousHeight;
outputCol = (intersection.x - x) * pixel;
outputRow = intersection.y - y;
if (validScanDim) {
outputRow -= tile.y;
}

int rowLen = pixel * (int) Math.min(intersection.width, realX);
Expand All @@ -362,22 +354,10 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
rawData, inputOffset, buf, outputOffset, rowLen);
outputOffset += outputRowLen;
}

outputCol += rowLen;
if (outputCol >= w * pixel) {
outputCol = 0;
outputRow += intersection.height;
}
previousHeight = intersection.height;
}

currentX += realX;
if (currentX >= getSizeX()) {
currentX = 0;
currentY += realY;
}
}
else {
byte[] rawData = new SubBlock(plane).readPixelData();
RandomAccessInputStream s = new RandomAccessInputStream(rawData);
try {
readPlane(s, x, y, w, h, buf);
Expand Down