Created
October 26, 2019 21:50
-
-
Save jazerix/e19e2b20bd6789af88adddd8ea871bea to your computer and use it in GitHub Desktop.
Calculate Zoomify TileGroups with Vips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int MaxTileGroup(Layer layer) | |
{ | |
int x = layer.tiles_across-1; | |
int y = layer.tiles_down-1; | |
int n = 0; | |
Layer below = layer.below; | |
while(below != null) | |
{ | |
n += below.tiles_across * below.tiles_down; | |
below = below.below; | |
} | |
n += y * layer.tiles_across + x; | |
return n / 256; | |
} | |
public static int MaxTileGroup(Layer layer) | |
{ | |
int x = layer.tiles_across-1; | |
int y = layer.tiles_down-1; | |
int n = 0; | |
Layer below = layer.below; | |
while(below != null) | |
{ | |
n += below.tiles_across * below.tiles_down; | |
below = below.below; | |
} | |
n += y * layer.tiles_across + x; | |
return n / 256; | |
} | |
public static Layer BuildPyramid(Layer above, int width, int height) | |
{ | |
Layer layer = new Layer(); | |
layer.width = width; | |
layer.height = height; | |
layer.tiles_across = RoundUp(width, 256) / 256; | |
layer.tiles_down = RoundUp(height, 256) / 256; | |
if (above == null) | |
layer.Sub = 1; | |
else | |
layer.Sub = above.Sub * 2; | |
layer.below = null; | |
layer.above = above; | |
int limit = 256; | |
if (width > limit || height > limit) | |
{ | |
if ((layer.below = BuildPyramid(layer, (width + 1) / 2, (height + 1) / 2)) == null) | |
{ | |
return null; | |
} | |
layer.N = layer.below.N + 1; | |
} | |
else | |
{ | |
layer.N = 0; | |
} | |
return layer; | |
} | |
public static int RoundDown(int number, int multiple) | |
{ | |
return number - (number % multiple); | |
} | |
public static int RoundUp(int number, int multiple) | |
{ | |
return RoundDown(number + multiple - 1, multiple); | |
} | |
class Layer | |
{ | |
public int width { get; set; } | |
public int height { get; set; } | |
public int tiles_across { get; set; } | |
public int tiles_down { get; set; } | |
public int Sub { get; set; } | |
public int N { get; set; } | |
public Layer below { get; set; } | |
public Layer above { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment