Skip to content

Commit

Permalink
Change image cache weight function to return kilobytes instead of byt…
Browse files Browse the repository at this point in the history
…es so that it can handle large 16-bit images. Mark version 2.0.2 for release.
  • Loading branch information
trautmane committed Jan 11, 2019
1 parent a31147a commit 25e408f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>modules-root</artifactId>
<groupId>org.janelia.render</groupId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>
</parent>

<name>Render Documents</name>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>Janelia Rendering Utilities</name>
<groupId>org.janelia.render</groupId>
<artifactId>modules-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>

<packaging>pom</packaging>

Expand Down Expand Up @@ -102,7 +102,7 @@
<guava-version>19.0</guava-version>
<jackson-version>2.6.7</jackson-version>
<logback-version>1.1.2</logback-version>
<render-version>2.0.2-SNAPSHOT</render-version>
<render-version>2.0.2</render-version>
<swagger-version>1.5.12</swagger-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion render-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.janelia.render</groupId>
<artifactId>modules-root</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>
</parent>

<name>Render Application</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ImageProcessorCache {
/** Default max number of pixels is 1GB (or 160 full resolution 2500x2500 pixel tiles). */
public static final long DEFAULT_MAX_CACHED_PIXELS = 1000 * 1000000; // 1GB

private final long maximumNumberOfCachedPixels;
private final long maximumNumberOfCachedKilobytes;
private final boolean recordStats;
private final boolean cacheOriginalsForDownSampledImages;

Expand Down Expand Up @@ -73,17 +73,21 @@ public ImageProcessorCache(final long maximumNumberOfCachedPixels,
final boolean recordStats,
final boolean cacheOriginalsForDownSampledImages) {

this.maximumNumberOfCachedPixels = maximumNumberOfCachedPixels;
this.maximumNumberOfCachedKilobytes = maximumNumberOfCachedPixels / 1000;
this.recordStats = recordStats;
this.cacheOriginalsForDownSampledImages = cacheOriginalsForDownSampledImages;

final Weigher<CacheKey, ImageProcessor> weigher =
(key, value) -> {
final long bitCount = value.getPixelCount() * value.getBitDepth();
final long kilobyteCount = bitCount / 8000L;
final int weight;
if (value == null) {
weight = 0;
if (kilobyteCount > Integer.MAX_VALUE) {
weight = Integer.MAX_VALUE;
LOG.warn("{} is too large ({} kilobytes) for cache weight function, using max weight of {}",
key, kilobyteCount, weight);
} else {
weight = value.getPixelCount() * value.getBitDepth() / 8;
weight = (int) kilobyteCount;
}
return weight;
};
Expand All @@ -92,8 +96,7 @@ public ImageProcessorCache(final long maximumNumberOfCachedPixels,
new CacheLoader<CacheKey, ImageProcessor>() {

@Override
public ImageProcessor load(@Nullable final CacheKey key)
throws Exception {
public ImageProcessor load(@Nullable final CacheKey key) {
ImageProcessor imageProcessor = null;
if (key != null) {
imageProcessor = loadImageProcessor(key.getUri(), key.getDownSampleLevels(), key.isMask(),key.isConvertTo16Bit());
Expand All @@ -105,13 +108,13 @@ public ImageProcessor load(@Nullable final CacheKey key)

if (recordStats) {
cache = CacheBuilder.newBuilder()
.maximumWeight(maximumNumberOfCachedPixels)
.maximumWeight(maximumNumberOfCachedKilobytes)
.weigher(weigher)
.recordStats()
.build(loader);
} else {
cache = CacheBuilder.newBuilder()
.maximumWeight(maximumNumberOfCachedPixels)
.maximumWeight(maximumNumberOfCachedKilobytes)
.weigher(weigher)
.build(loader);
}
Expand Down Expand Up @@ -177,7 +180,7 @@ public CacheStats getStats() {
@Override
public String toString() {
return "{numberOfEntries: " + size() +
", maximumNumberOfCachedPixels: " + maximumNumberOfCachedPixels +
", maximumNumberOfCachedKilobytes: " + maximumNumberOfCachedKilobytes +
", recordStats: " + recordStats +
", cacheOriginalsForDownSampledImages: " + cacheOriginalsForDownSampledImages +
'}';
Expand Down Expand Up @@ -287,10 +290,10 @@ private class CacheKey {
private final boolean isMask;
private final boolean convertTo16Bit;

public CacheKey(final String url,
final int downSampleLevels,
final boolean isMask,
final boolean convertTo16Bit) {
CacheKey(final String url,
final int downSampleLevels,
final boolean isMask,
final boolean convertTo16Bit) {

this.url = url;

Expand All @@ -307,10 +310,10 @@ public CacheKey(final String url,
public String getUri() {
return url;
}
public boolean isConvertTo16Bit(){
boolean isConvertTo16Bit(){
return convertTo16Bit;
}
public int getDownSampleLevels() {
int getDownSampleLevels() {
return downSampleLevels;
}

Expand Down
2 changes: 1 addition & 1 deletion render-ws-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>modules-root</artifactId>
<groupId>org.janelia.render</groupId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>
</parent>

<name>Render Web Service Java Client</name>
Expand Down
2 changes: 1 addition & 1 deletion render-ws-spark-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>modules-root</artifactId>
<groupId>org.janelia.render</groupId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>
</parent>

<name>Render Web Service Spark Client</name>
Expand Down
2 changes: 1 addition & 1 deletion render-ws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>modules-root</artifactId>
<groupId>org.janelia.render</groupId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>
</parent>

<name>Render Web Service</name>
Expand Down
2 changes: 1 addition & 1 deletion trakem2-scripts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>modules-root</artifactId>
<groupId>org.janelia.render</groupId>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.2</version>
</parent>

<name>TrakEM2 Scripts</name>
Expand Down

0 comments on commit 25e408f

Please sign in to comment.