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

Add more logic for determining associated images in tiff source #1291

Merged
merged 1 commit into from
Sep 1, 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 @@ -4,6 +4,7 @@

### Improvements
- Add [common] extra_requires ([#1288](../../pull/1288))
- Add more logic for determining associated images in tiff source ([#1291](../../pull/1291))

### Changes
- Internal metadata get endpoint is now public ([#1285](../../pull/1285))
Expand Down
7 changes: 5 additions & 2 deletions sources/tiff/large_image_source_tiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def _addAssociatedImage(self, largeImagePath, directoryNum, mustBeTiled=False, t

:param largeImagePath: path to the TIFF file.
:param directoryNum: libtiff directory number of the image.
:param mustBeTiles: if true, use tiled images. If false, require
:param mustBeTiled: if true, use tiled images. If false, require
untiled images.
:param topImage: if specified, add image-embedded metadata to this
image.
Expand All @@ -464,14 +464,17 @@ def _addAssociatedImage(self, largeImagePath, directoryNum, mustBeTiled=False, t
id = 'dir%d' % directoryNum
if not len(self._associatedImages):
id = 'macro'
if not id and not mustBeTiled:
id = {1: 'label', 9: 'macro'}.get(associated._tiffInfo.get('subfiletype'))
if not isinstance(id, str):
id = id.decode()
# Only use this as an associated image if the parsed id is
# a reasonable length, alphanumeric characters, and the
# image isn't too large.
if (id.isalnum() and len(id) > 3 and len(id) <= 20 and
associated._pixelInfo['width'] <= self._maxAssociatedImageSize and
associated._pixelInfo['height'] <= self._maxAssociatedImageSize):
associated._pixelInfo['height'] <= self._maxAssociatedImageSize and
id not in self._associatedImages):
image = associated._tiffFile.read_image()
# Optrascan scanners store xml image descriptions in a "tiled
# image". Check if this is the case, and, if so, parse such
Expand Down