diff --git a/sources/openslide/large_image_source_openslide/__init__.py b/sources/openslide/large_image_source_openslide/__init__.py index c580f84ca..13a2d51f9 100644 --- a/sources/openslide/large_image_source_openslide/__init__.py +++ b/sources/openslide/large_image_source_openslide/__init__.py @@ -202,12 +202,13 @@ def _getAvailableLevels(self, path): 'height': svsLevelDimensions[svslevel][1], } if level['width'] > 0 and level['height'] > 0: - # add to the list so that we can sort by resolution - levels.append((level['width'] * level['height'], level)) + # add to the list so that we can sort by resolution and + # then by earlier entries + levels.append((level['width'] * level['height'], -len(levels), level)) except openslide.lowlevel.OpenSlideError: self._openslide = openslide.OpenSlide(path) # sort highest resolution first. - levels = [entry[-1] for entry in sorted(levels, reverse=True)] + levels = [entry[-1] for entry in sorted(levels, reverse=True, key=lambda x: x[:-1])] # Discard levels that are not a power-of-two compared to the highest # resolution level. levels = [entry for entry in levels if