From a783324a8ce0080ae7815dfb143da51529d2a698 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 1 Sep 2023 13:20:08 -0400 Subject: [PATCH] Add more logic for determining associated images in tiff source --- CHANGELOG.md | 1 + sources/tiff/large_image_source_tiff/__init__.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fc3f1a81..a4d778323 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/sources/tiff/large_image_source_tiff/__init__.py b/sources/tiff/large_image_source_tiff/__init__.py index b6eae26c2..448b57360 100644 --- a/sources/tiff/large_image_source_tiff/__init__.py +++ b/sources/tiff/large_image_source_tiff/__init__.py @@ -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. @@ -464,6 +464,8 @@ 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 @@ -471,7 +473,8 @@ def _addAssociatedImage(self, largeImagePath, directoryNum, mustBeTiled=False, t # 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