Skip to content

Commit f24c1dd

Browse files
committed
deepzoom: revert unrolling of _get_tile_info()
We don't need to avoid generator expressions to keep the type checker happy; we can just assert that the resulting tuples have the correct length. This lets us avoid carrying redundant unrolled code. Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent cfd1663 commit f24c1dd

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

openslide/deepzoom.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -219,48 +219,31 @@ def _get_tile_info(
219219
)
220220

221221
# Get final size of the tile
222-
z_size = (
223-
min(
224-
self._z_t_downsample,
225-
self._z_dimensions[dz_level][0] - self._z_t_downsample * t_location[0],
222+
z_size = tuple(
223+
min(self._z_t_downsample, z_lim - self._z_t_downsample * t) + z_tl + z_br
224+
for t, z_lim, z_tl, z_br in zip(
225+
t_location, self._z_dimensions[dz_level], z_overlap_tl, z_overlap_br
226226
)
227-
+ z_overlap_tl[0]
228-
+ z_overlap_br[0],
229-
min(
230-
self._z_t_downsample,
231-
self._z_dimensions[dz_level][1] - self._z_t_downsample * t_location[1],
232-
)
233-
+ z_overlap_tl[1]
234-
+ z_overlap_br[1],
235227
)
236228

237229
# Obtain the region coordinates
238-
z_location = (self._z_from_t(t_location[0]), self._z_from_t(t_location[1]))
239-
l_location = (
240-
self._l_from_z(dz_level, z_location[0] - z_overlap_tl[0]),
241-
self._l_from_z(dz_level, z_location[1] - z_overlap_tl[1]),
242-
)
230+
z_location = [self._z_from_t(t) for t in t_location]
231+
l_location = [
232+
self._l_from_z(dz_level, z - z_tl)
233+
for z, z_tl in zip(z_location, z_overlap_tl)
234+
]
243235
# Round location down and size up, and add offset of active area
244-
l0_location = (
245-
int(self._l0_from_l(slide_level, l_location[0]) + self._l0_offset[0]),
246-
int(self._l0_from_l(slide_level, l_location[1]) + self._l0_offset[1]),
236+
l0_location = tuple(
237+
int(self._l0_from_l(slide_level, l) + l0_off)
238+
for l, l0_off in zip(l_location, self._l0_offset)
247239
)
248-
l_size = (
249-
int(
250-
min(
251-
math.ceil(self._l_from_z(dz_level, z_size[0])),
252-
self._l_dimensions[slide_level][0] - math.ceil(l_location[0]),
253-
)
254-
),
255-
int(
256-
min(
257-
math.ceil(self._l_from_z(dz_level, z_size[1])),
258-
self._l_dimensions[slide_level][1] - math.ceil(l_location[1]),
259-
)
260-
),
240+
l_size = tuple(
241+
int(min(math.ceil(self._l_from_z(dz_level, dz)), l_lim - math.ceil(l)))
242+
for l, dz, l_lim in zip(l_location, z_size, self._l_dimensions[slide_level])
261243
)
262244

263245
# Return read_region() parameters plus tile size for final scaling
246+
assert len(l0_location) == 2 and len(l_size) == 2 and len(z_size) == 2
264247
return ((l0_location, slide_level, l_size), z_size)
265248

266249
def _l0_from_l(self, slide_level: int, l: float) -> float:

0 commit comments

Comments
 (0)