Fix Deepzoom
Closed this issue ยท 1 comments
vincentsarago commented
๐ is not working Yet
titiler-image/titiler/image/factory.py
Lines 876 to 997 in 8ae9a69
# TODO: it doesn't work yet | |
@self.router.get("/{z}/{x}_{y}", **img_endpoint_params) | |
@self.router.get("/{z}/{x}_{y}.{format}", **img_endpoint_params) | |
def deepzoom_tile( | |
level: int = Path(..., alias="z"), | |
column: int = Path(..., alias="x"), | |
row: int = Path(..., alias="y"), | |
format: ImageType = Query( | |
ImageType.png, description="Output image type. Defaults to PNG." | |
), | |
src_path: str = Query(description="Dataset URL", alias="url"), | |
layer_params: BidxExprParams = Depends(), | |
dataset_params: DatasetParams = Depends(), | |
rescale: Optional[List[Tuple[float, ...]]] = Depends(RescalingParams), | |
color_formula: Optional[str] = Query( | |
None, | |
title="Color Formula", | |
description="rio-color formula (info: https://github.com/mapbox/rio-color)", | |
), | |
colormap: Optional[ColorMapType] = Depends(ColorMapParams), | |
add_mask: Optional[bool] = Query( | |
None, alias="return_mask", description="Add mask to the output data." | |
), | |
): | |
"""DeepZoom tile.""" | |
tile_size = 254 | |
tile_overlap = 1 | |
with ImageReader(src_path) as dst: | |
max_dimension = max(dst.dataset.width, dst.dataset.height) | |
max_level = int(math.ceil(math.log(max_dimension, 2))) + 1 | |
assert 0 <= level and level < max_level, "Invalid pyramid level" | |
print(max_dimension) | |
print(max_level) | |
# Overview Size | |
# level_width = dst.dataset.width // 2 ** (max_level - level) | |
# level_height = dst.dataset.height // 2 ** (max_level - level) | |
scale = math.pow(0.5, max_level - 1 - level) | |
level_width = int(math.ceil(dst.dataset.width * scale)) | |
level_height = int(math.ceil(dst.dataset.height * scale)) | |
print(level_height, level_width) | |
# Nb tiles for Ovr | |
level_x_tile = int(math.ceil(level_width / tile_size)) | |
level_y_tile = int(math.ceil(level_height / tile_size)) | |
print(level_x_tile, level_y_tile) | |
offset_x = 0 if column == 0 else tile_overlap | |
offset_y = 0 if row == 0 else tile_overlap | |
x = (column * tile_size) - offset_x | |
y = (row * tile_size) - offset_y | |
w = tile_size + (1 if column == 0 else 2) * tile_overlap | |
h = tile_size + (1 if row == 0 else 2) * tile_overlap | |
w = min(w, level_width - x) | |
h = min(h, level_height - y) | |
print((x, y, x + w, y + h)) | |
# Output Size | |
width = ( | |
min(tile_size, level_width - (tile_size * (level_x_tile - 1))) | |
if column == level_x_tile - 1 | |
else tile_size | |
) | |
height = ( | |
min(tile_size, level_height - (tile_size * (level_y_tile - 1))) | |
if row == level_y_tile - 1 | |
else tile_size | |
) | |
print(width, height) | |
# BBox | |
x_origin = (dst.dataset.width / level_width) * tile_size * column | |
y_origin = (dst.dataset.height / level_height) * tile_size * row | |
x_max = min( | |
dst.dataset.width, | |
x_origin + dst.dataset.width / level_width * width, | |
) | |
y_max = min( | |
dst.dataset.height, | |
y_origin + dst.dataset.height / level_height * height, | |
) | |
print(x_origin, y_origin, x_max, y_max) | |
w = windows.from_bounds( | |
x_origin, | |
y_max, | |
x_max, | |
y_origin, | |
transform=dst.transform, | |
) | |
image = dst.read( | |
window=w, | |
width=width, | |
height=height, | |
**layer_params, | |
**dataset_params, | |
) | |
dst_colormap = getattr(dst, "colormap", None) | |
if rescale: | |
image.rescale(rescale) | |
if color_formula: | |
image.apply_color_formula(color_formula) | |
content = image.render( | |
add_mask=add_mask if add_mask is not None else True, | |
img_format=format.driver, | |
colormap=colormap or dst_colormap, | |
**format.profile, | |
) | |
return Response(content, media_type=format.mediatype) |
vincentsarago commented
I've removed the Deepzoom factory for now.
If someone needs it I'll be happy to help finishing what was started in โ๏ธ