Skip to content

Commit

Permalink
Fix scaling tiles from stripped tiffs in some instances
Browse files Browse the repository at this point in the history
In some cases when trying to use a strip-based tiff file, the lower
resolution tile would be horizontal scaled to the strip width.
  • Loading branch information
manthey committed Jan 14, 2025
1 parent b8d0ae1 commit 0d6f43b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- Provide some latitude in vips multiframe detection ([#1770](../../pull/1770))
- Don't read multiplane ndpi files with openslide ([#1772](../../pull/1772))

### Bug Fixes

Vy- Fix scaling tiles from stripped tiffs in some instances ([#1773](../../pull/1773))

## 1.30.6

### Features
Expand Down
4 changes: 3 additions & 1 deletion girder/girder_large_image/models/image_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def _loadTileSource(cls, item, **kwargs):
# tileSource = girder_tilesource.getGirderTileSource(item, **kwargs)
# but, instead, log that the original source no longer works are
# reraise the exception
logger.warning('The original tile source for item %s is not working', item['_id'])
logger.warning(
'The original tile source (%s) for item %s is not working',
sourceName, item['_id'])
try:
file = File().load(item['largeImage']['fileId'], force=True)
localPath = File().getLocalFilePath(file)
Expand Down
13 changes: 10 additions & 3 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,9 +1625,16 @@ def _getTileFromEmptyLevel(self, x: int, y: int, z: int, **kwargs) -> Tuple[
mode = subtile.mode
tile.paste(subtile, (newX * self.tileWidth,
newY * self.tileHeight))
return tile.resize(
(self.tileWidth, self.tileHeight),
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS).convert(mode), TILE_FORMAT_PIL
tile = tile.resize(
(min(self.tileWidth, (tile.width + scale - 1) // scale),
min(self.tileHeight, (tile.height + scale - 1) // scale)),
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)
if tile.width != self.tileWidth or tile.height != self.tileHeight:
fulltile = PIL.Image.new('RGBA', (self.tileWidth, self.tileHeight))
fulltile.paste(tile, (0, 0))
tile = fulltile
tile = tile.convert(mode)
return (tile, TILE_FORMAT_PIL)

@methodcache()
def getTile(self, x: int, y: int, z: int, pilImageAllowed: bool = False,
Expand Down

0 comments on commit 0d6f43b

Please sign in to comment.