Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fetching extra associated images from openslide #1318

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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