tiles
#
Caching of tiles loaded from a zoom-level image pyramid.
- class TileCache(image: DeepZoom, extra_tiles=2)[source]#
Pixel cache for tiles of a zoom-level image pyramid.
The pixels that are loaded include some tiles on each side that are intended to be outside the displayed area. This means that when the user moves the viewport by a small amount, image tiles are loaded outside the displayed area, not inside. This can be leveraged by the GUI framework, where the displayed image would only be the viewport, but the framework is aware of the entire canvas, which can then be updated at a slower pace without affecting the user experience.
(canvas_x, canvas_y) +-----------------------------------------------+ | | | | | (viewport_x, viewport_y) | | +---------------------+ | | | | | | | | | | | | | | | | | | | | | | +---------------------+ | | (viewport_x + viewport_w, | | viewport_y + viewport_h) | +-----------------------------------------------+ (canvas_x + canvas_w, canvas_y + canvas_h)
Pixel indices are denoted
(x, y)
, tile indices as(i, j)
. The coordinates of a top-left corner are denoted(x1, y1)
or(i1, i1)
respectively. A bottom-right corners is(x2, y2)
for pixels,(i2, j2)
for tiles. Ranges are left-inclusive, right-exclusive. Width and height of the corresponding rectangles are typically abbreviated asw
andh
.Pixel indices into the full image (not the canvas) are denoted with capital letters, like
(X, Y)
.- image#
tiled image pyramid to retrieve pixel data from
- canvas#
array holding all pixel data currently cached
- extra_tiles#
number of extra tiles to cache outside the viewport
- zoom_level#
the current zoom level
- zoom_min#
minimum available zoom level (smallest number)
- zoom_max#
maximum available zoom level (largest number)
- zoom_to(level, x, y)[source]#
Zooms to the given
level
towards viewport coordinates (x, y).Returns
True
if image needs to be reloaded because tiles have been added,False
otherwise.
- move_by(Δx: int, Δy: int) bool [source]#
Moves viewport position by
(Δx, Δy)
.Returns
True
if image needs to be reloaded because tiles have been added,False
otherwise.
- move_to(X1: int, Y1: int) bool [source]#
Moves the viewport within the current zoom level.
Loads new tiles if needed and updates the viewport.
(X1, Y1)
are the coordinates of the top-left corner in the full image at the current zoom level.Returns
True
if image needs to be reloaded because tiles have been added,False
otherwise.