Skip to content

Commit

Permalink
Merge pull request #1318 from girder/refactor-associated-image
Browse files Browse the repository at this point in the history
Refactor fetching extra associated images from openslide
  • Loading branch information
manthey authored Sep 21, 2023
2 parents ff02e60 + 54ce91e commit b7e2852
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Changes
- Remove a needless guard around getting an icc profile ([#1316](../../pull/1316))
- Refactor fetching extra associated images from openslide ([#1318](../../pull/1318))

### Bug Fixes
- Guard against potential bad event stream timestamp ([#1306](../../pull/1306))
Expand Down
17 changes: 4 additions & 13 deletions sources/openslide/large_image_source_openslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
##############################################################################

import io
import math
import os

Expand All @@ -26,12 +27,6 @@
from large_image.exceptions import TileSourceError, TileSourceFileNotFoundError
from large_image.tilesource import FileTileSource, nearPowerOfTwo

try:
from libtiff import libtiff_ctypes
except ImportError:
libtiff_ctypes = False


try:
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as _importlib_version
Expand Down Expand Up @@ -376,13 +371,9 @@ def _getAssociatedImage(self, imageKey):
# Reopen handle after a lowlevel error
self._openslide = openslide.OpenSlide(self._largeImagePath)
return None
bytePath = self._largeImagePath
if not isinstance(bytePath, bytes):
bytePath = bytePath.encode()
_tiffFile = libtiff_ctypes.TIFF.open(bytePath)
_tiffFile.SetDirectory(images[imageKey])
img = _tiffFile.read_image()
return PIL.Image.fromarray(img)
tiff_buffer = io.BytesIO()
tifftools.write_tiff(self._tiffinfo['ifds'][images[imageKey]], tiff_buffer)
return PIL.Image.open(tiff_buffer)


def open(*args, **kwargs):
Expand Down

0 comments on commit b7e2852

Please sign in to comment.