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

Calculate resolution sizes based on an integer scale factor, not the zoom level #9

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,28 @@ else if (map.has("channels")) {
int levels = map.getAsJsonPrimitive("levels").getAsInt();
if (levels > 1) {
JsonObject zoom = map.getAsJsonObject("zoomLevelScaling");
double aspectRatio = (double) sizeX / sizeY;
logger.debug("image aspect ratio = {}", aspectRatio);
for (int i = 0; i < levels; i++) {
levelBuilder.addLevelByDownsample(1.0 / zoom.getAsJsonPrimitive(Integer.toString(i)).getAsDouble());
double rawZoomFactor = zoom.getAsJsonPrimitive(Integer.toString(i)).getAsDouble();
logger.debug("level = {}, rawZoomFactor = {}", i, rawZoomFactor);

// level width and height calculation are best-effort,
// given that we cannot currently get the precise dimensions
// this needs to be fixed once web API is fixed

// we expect the width calculation to be accurate, as zoomLevelScaling
// was calculated based upon the resolution widths alone
int levelWidth = (int) Math.floor(rawZoomFactor * sizeX);

// now apply the image aspect ratio to find the height
// this assumes that the aspect ratio remains consistent across the whole pyramid
// subtract 1 to account for potential rounding issues
int levelHeight = (int) Math.floor(levelWidth / aspectRatio) - 1;

logger.debug(" level width = {}, level height = {}", levelWidth, levelHeight);

levelBuilder.addLevel(1 / rawZoomFactor, levelWidth, levelHeight);
}
} else {
levelBuilder.addFullResolutionLevel();
Expand Down