Skip to content

Commit

Permalink
Merge pull request #891 from girder/cache-read-tiff
Browse files Browse the repository at this point in the history
Cache read_tiff calls to speed up restyling
  • Loading branch information
manthey authored Jul 22, 2022
2 parents 11e9844 + 0038cbe commit a9f1bd6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- When converting girder images locally, prefer mount paths ([886](../../pull/886))
- Store the id of job results for easier post-job work ([887](../../pull/887))
- Harden style compositing of partial tiles ([889](../../pull/889))
- Cache read_tiff calls to speed up restyling ([891](../../pull/891))

### Changes
- Be more consistent in source class name attribute assignment ([884](../../pull/884))
Expand Down
8 changes: 7 additions & 1 deletion sources/tiff/large_image_source_tiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import math
import os

import cachetools
import numpy
import PIL.Image
import tifftools
Expand Down Expand Up @@ -48,6 +49,11 @@
pass


@cachetools.cached(cache=cachetools.LRUCache(maxsize=10))
def _cached_read_tiff(path):
return tifftools.read_tiff(path)


class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
"""
Provides tile access to TIFF files.
Expand Down Expand Up @@ -264,7 +270,7 @@ def _initWithTiffTools(self): # noqa
self.levels = max(1, int(math.ceil(math.log(max(
dir0.imageWidth / dir0.tileWidth,
dir0.imageHeight / dir0.tileHeight)) / math.log(2))) + 1)
info = tifftools.read_tiff(self._largeImagePath)
info = _cached_read_tiff(self._largeImagePath)
frames = []
associated = [] # for now, a list of directories
curframe = -1
Expand Down

0 comments on commit a9f1bd6

Please sign in to comment.