Skip to content

Commit

Permalink
Merge pull request #1787 from melissalinkert/12843
Browse files Browse the repository at this point in the history
Zeiss CZI: fix assembly of overlapping tiles
  • Loading branch information
melissalinkert committed May 18, 2015
2 parents 8c2ab18 + b681f66 commit 5943cc3
Showing 1 changed file with 6 additions and 26 deletions.
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 @@ -299,9 +299,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 @@ -313,7 +310,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 @@ -322,33 +318,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 @@ -363,22 +355,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

0 comments on commit 5943cc3

Please sign in to comment.