Skip to content

Commit

Permalink
Preliminary work on issue #24 (Dynamic background changes when zooming)
Browse files Browse the repository at this point in the history
  • Loading branch information
tokee committed Aug 31, 2016
1 parent a462c4f commit 2d726be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
25 changes: 15 additions & 10 deletions src/main/java/dk/statsbiblioteket/nrtmosaic/Keeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,22 @@ public PyramidGrey23 getClosestBottom(int primary, int secondary, Random random)
}

// Attempts to extract UUID from origin and use cached fill color
// TODO: This should be deprecated due to the dynamic fill option
public int getFillGrey(String origin) {
if (Util.DEFAULT_FILL_STYLE == Util.FILL_STYLE.fixed) {
return Util.FILL_COLOR_INT;
}
try {
return getFillGrey(new UUID(origin));
} catch (IllegalArgumentException e) {
log.warn("Unable to extract UUID from '" + origin + "'. Using default fill grey " + Util.FILL_COLOR_INT);
public int getFillGrey(String origin, Integer dynamicGrey) {
switch (Util.DEFAULT_FILL_STYLE) {
case fixed:
return Util.FILL_COLOR_INT;
case average:
try {
return getFillGrey(new UUID(origin));
} catch (IllegalArgumentException e) {
log.warn("Unable to extract UUID from '" + origin + "'. Using default grey " + Util.FILL_COLOR_INT);
return Util.FILL_COLOR_INT;
}
case dynamic:
return dynamicGrey == null ? Util.FILL_COLOR_INT : dynamicGrey;
default: throw new UnsupportedOperationException(
"The fill style '" + Util.DEFAULT_FILL_STYLE + "' is not supported yet");
}
return Util.FILL_COLOR_INT;
}
/**
* Depending on property "tile.fill.style", this either returns the average grey for th pyramid or the default fill.
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/dk/statsbiblioteket/nrtmosaic/Prime.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ private Prime() {

private static final Pattern DEEPZOOM = Pattern.compile("(.*)/([0-9]+)/([0-9]+)_([0-9]+)(.*)");
public BufferedImage deepzoom(String deepZoomSnippet, String gam, String cnt) throws IOException {
return deepzoom(deepZoomSnippet, gam, cnt, false, false);
return deepzoom(deepZoomSnippet, gam, cnt, false, false, null);
}
public BufferedImage deepzoom(String deepZoomSnippet, String gam, String cnt, boolean pad, boolean border)
throws IOException {
public BufferedImage deepzoom(String deepZoomSnippet, String gam, String cnt, boolean pad, boolean border,
Integer dynamicGrey) throws IOException {

// /avis-show/symlinks/9/c/0/5/9c05d958-b616-47c1-9e4f-63ec2dd9429e.jp2_files/0/0_0.jpg
// Group 1 2 3 45
Expand Down Expand Up @@ -123,7 +123,7 @@ public BufferedImage deepzoom(String deepZoomSnippet, String gam, String cnt, bo
} else if (level > LAST_BASIC_LEVEL) {
result = deepzoomRender(pre, fx, fy, level, post, gam, cnt);
} else {
result = deepZoomBasic(deepZoomSnippet, fx, fy, level, gam, cnt, pad);
result = deepZoomBasic(deepZoomSnippet, fx, fy, level, gam, cnt, pad, dynamicGrey);
}
if (border) {
Util.drawBorder(result);
Expand All @@ -133,7 +133,7 @@ public BufferedImage deepzoom(String deepZoomSnippet, String gam, String cnt, bo

// Topmost levels where NRTMosaic works as a plain image server
private BufferedImage deepZoomBasic(String deepZoomSnippet, long fx, long fy, int level, String gam, String cnt,
boolean pad) throws IOException {
boolean pad, Integer dynamicGrey) throws IOException {
log.trace("deepzoom basic tile for " + deepZoomSnippet + ", pad=" + pad);
final long startTime = System.nanoTime();
PyramidGrey23 pyramid = keeper.getPyramid(deepZoomSnippet);
Expand All @@ -153,7 +153,7 @@ private BufferedImage deepZoomBasic(String deepZoomSnippet, long fx, long fy, in
", maxExistingX=" + maxExistingX);*/
if (fx > maxExistingX || fy > maxExistingY) {
log.trace("Basic image has no tile for " + fx + "x" + fy + " at level " + level + ". Returning blank");
return Util.getBlankTile(keeper.getFillGrey(deepZoomSnippet));
return Util.getBlankTile(keeper.getFillGrey(deepZoomSnippet, dynamicGrey));
}
}

Expand All @@ -166,11 +166,11 @@ private BufferedImage deepZoomBasic(String deepZoomSnippet, long fx, long fy, in
if (!pad) {
return unpadded;
}
return Util.pad(unpadded, edge, edge, keeper.getFillGrey(deepZoomSnippet));
return Util.pad(unpadded, edge, edge, keeper.getFillGrey(deepZoomSnippet, dynamicGrey));
} catch (IIOException e) {
if (pad) {
log.debug("No basic tile at '" + deepZoomSnippet + "' but pad==true so default blank is returned");
return Util.getBlankTile(keeper.getFillGrey(deepZoomSnippet));
return Util.getBlankTile(keeper.getFillGrey(deepZoomSnippet, dynamicGrey));
}
throw new IIOException("Unable to read '" + external + "' as an image", e);
} finally {
Expand Down Expand Up @@ -282,7 +282,8 @@ private BufferedImage deepzoomRedirect(String pre, long fx, long fy, int level,
final String basicSnippet = toBasicDeepzoomSnippet(pyramid, redirectFX, redirectFY, level);
log.debug("deepzoom redirect from " + pre + " " + fx + "x" + fy + ", level " + level + " to deepzoom " +
basicSnippet + " in " + (System.nanoTime()-startTime)/1000000+"ms");
return deepzoom(basicSnippet, gam, cnt, true, border);
// TODO: Resolve tile to derive dynamic fill grey and send it forward to the basic
return deepzoom(basicSnippet, gam, cnt, true, border, null);
}

private String toBasicDeepzoomSnippet(PyramidGrey23 pyramid, long redirectFX, long redirectFY, int level) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dk/statsbiblioteket/nrtmosaic/TileProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Tile23 getTile(String source, boolean allowNA) {
} catch (IOException e) {
if (allowNA) {
log.debug("No tile at '" + source + "' but allowNA==true so default blank is used");
image = Util.getBlankTile(keeper.getFillGrey(imageURL.toString()));
image = Util.getBlankTile(keeper.getFillGrey(imageURL.toString(), null));
} else {
throw new RuntimeException("Unable to resolve tile for source=" + source);
}
Expand All @@ -89,7 +89,7 @@ public Tile23 getTile(String source, boolean allowNA) {
throw new IllegalStateException("image is null for '" + source + "'");
}
if (image.getWidth() != edge || image.getHeight() != edge) {
int fillGrey = keeper.getFillGrey(imageURL.toString());
int fillGrey = keeper.getFillGrey(imageURL.toString(), null);
log.trace("Padding tile '" + source + "' of " + image.getWidth() + "x" + image.getHeight() +
" pixels to " + edge + "x" + edge + " pixels with fill " + fillGrey);
image = Util.pad(image, edge, edge, fillGrey);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/dk/statsbiblioteket/nrtmosaic/PrimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void showSome(String BASE, int level, int x, int y) throws IOException {
for (int dy = 0; dy < 3; dy++) {
for (int dx = 0; dx < 6; dx++) {
tiles.add(Prime.instance().deepzoom(String.format(
"%s/%d/%d_%d", BASE, level, x + dx, y + dy), "2.0", "1.2", true, false));
"%s/%d/%d_%d", BASE, level, x + dx, y + dy), "2.0", "1.2", true, false, null));
}
}
Util.show(tiles);
Expand Down

0 comments on commit 2d726be

Please sign in to comment.