Skip to content

Commit

Permalink
Merge pull request #2 from chris-allan/fix-tile-cache
Browse files Browse the repository at this point in the history
Make tile cache robust to resolution level changes
  • Loading branch information
sbesson authored Mar 14, 2024
2 parents de94b38 + 8be8948 commit 944ef18
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ZarrPixelBuffer implements PixelBuffer {
/** Zarr array corresponding to the current resolution level */
private ZarrArray array;

/** { z, c, t, x, y, w, h } vs. tile byte array cache */
/** { resolutionLevel, z, c, t, x, y, w, h } vs. tile byte array cache */
private final AsyncLoadingCache<List<Integer>, byte[]> tileCache;

/** Whether or not the Zarr is on S3 or similar */
Expand Down Expand Up @@ -117,16 +117,18 @@ public ZarrPixelBuffer(Pixels pixels, Path root, Integer maxPlaneWidth,
tileCache = Caffeine.newBuilder()
.maximumSize(getSizeC())
.buildAsync(key -> {
int z = key.get(0);
int c = key.get(1);
int t = key.get(2);
int x = key.get(3);
int y = key.get(4);
int w = key.get(5);
int h = key.get(6);
int resolutionLevel = key.get(0);
int z = key.get(1);
int c = key.get(2);
int t = key.get(3);
int x = key.get(4);
int y = key.get(5);
int w = key.get(6);
int h = key.get(7);
int[] shape = new int[] { 1, 1, 1, h, w };
byte[] innerBuffer =
new byte[length(shape) * getByteWidth()];
setResolutionLevel(resolutionLevel);
return getTileDirect(z, c, t, x, y, w, h, innerBuffer);
});
}
Expand Down Expand Up @@ -450,7 +452,8 @@ public PixelData getTile(
channels = Arrays.asList(new Integer[] { 0, 1 ,2 });
}
for (Integer channel : channels) {
List<Integer> v = Arrays.asList(z, channel, t, x, y, w, h);
List<Integer> v = Arrays.asList(
getResolutionLevel(), z, channel, t, x, y, w, h);
keys.add(v);
if (channel == c) {
key = v;
Expand Down

0 comments on commit 944ef18

Please sign in to comment.