Skip to content

Commit

Permalink
Merge pull request #1791 from girder/multiframe-pil
Browse files Browse the repository at this point in the history
Better detect multiframe images in PIL
  • Loading branch information
manthey authored Jan 28, 2025
2 parents 109dec7 + 9d7a406 commit 4b2b390
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Add a general channelNames property to tile sources ([#1783](../../pull/1783))
- Speed up compositing styles ([#1784](../../pull/1784))
- Better repr of large_image classes ([#1787](../../pull/1787))
- Better detect multiframe images in PIL ([#1791](../../pull/1791))

### Changes

Expand Down
10 changes: 9 additions & 1 deletion sources/pil/large_image_source_pil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class PILFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
'jpg': SourcePriority.LOW,
'jpeg': SourcePriority.LOW,
'jpe': SourcePriority.LOW,
'nef': SourcePriority.LOW,
}
mimeTypes = {
None: SourcePriority.FALLBACK_HIGH,
Expand Down Expand Up @@ -222,7 +223,14 @@ def _fromRawpy(self, largeImagePath):
"""
Try to use rawpy to read an image.
"""
# if rawpy is present, try reading via that library first
# if rawpy is present, try reading via that library first, but only
# if PIL reports a single frame
try:
img = PIL.Image.open(largeImagePath)
if len(list(PIL.ImageSequence.Iterator(img))) > 1:
return
except Exception:
pass
try:
import builtins

Expand Down
1 change: 1 addition & 0 deletions test/lisource_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ def command():
if not large_image.tilesource.AvailableTileSources:
large_image.tilesource.loadTileSources()
if opts.all:
large_image.config.setConfig('max_small_image_size', 16384)
for key in list(large_image.config.ConfigValues):
if '_ignored_names' in key:
del large_image.config.ConfigValues[key]
Expand Down

0 comments on commit 4b2b390

Please sign in to comment.