large-image-source-tiff 1.30.6.dev14__py3-none-any.whl → 1.30.6.dev18__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -327,12 +327,19 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
327
327
  self._info = info
328
328
  frames = []
329
329
  associated = [] # for now, a list of directories
330
+ used_subifd = False
330
331
  for idx, ifd in enumerate(info['ifds']):
331
332
  # if not tiles, add to associated images
332
333
  if tifftools.Tag.tileWidth.value not in ifd['tags']:
333
- associated.append(idx)
334
+ associated.append((idx, False))
334
335
  continue
335
- level = self._levelFromIfd(ifd, info['ifds'][0])
336
+ try:
337
+ level = self._levelFromIfd(ifd, info['ifds'][0])
338
+ except TileSourceError:
339
+ if idx and used_subifd:
340
+ associated.append((idx, True))
341
+ continue
342
+ raise
336
343
  # if the same resolution as the main image, add a frame
337
344
  if level == self.levels - 1:
338
345
  frames.append({'dirs': [None] * self.levels})
@@ -371,9 +378,13 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
371
378
  tifftools.Tag.TileOffsets.value not in subifds[0]['tags']):
372
379
  msg = 'Subifd has no strip or tile offsets.'
373
380
  raise TileSourceMalformedError(msg)
374
- level = self._levelFromIfd(subifds[0], info['ifds'][0])
381
+ try:
382
+ level = self._levelFromIfd(subifds[0], info['ifds'][0])
383
+ except Exception:
384
+ break
375
385
  if level < self.levels - 1 and frames[-1]['dirs'][level] is None:
376
386
  frames[-1]['dirs'][level] = (idx, subidx + 1)
387
+ used_subifd = True
377
388
  else:
378
389
  msg = 'Tile layers are in a surprising order'
379
390
  raise TileSourceError(msg)
@@ -407,8 +418,8 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
407
418
  self._iccprofiles.append(ifd['tags'][
408
419
  tifftools.Tag.ICCProfile.value]['data'])
409
420
  self._associatedImages = {}
410
- for dirNum in associated:
411
- self._addAssociatedImage(dirNum)
421
+ for dirNum, isTiled in associated:
422
+ self._addAssociatedImage(dirNum, isTiled)
412
423
  self._frames = frames
413
424
  self._tiffDirectories = [
414
425
  self.getTiffDir(
@@ -490,7 +501,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
490
501
  frame.setdefault('frame', {})
491
502
  frame['frame']['IndexC'] = idx
492
503
 
493
- def _addAssociatedImage(self, directoryNum, mustBeTiled=False, topImage=None):
504
+ def _addAssociatedImage(self, directoryNum, mustBeTiled=False, topImage=None, imageId=None):
494
505
  """
495
506
  Check if the specified TIFF directory contains an image with a sensible
496
507
  image description that can be used as an ID. If so, and if the image
@@ -501,6 +512,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
501
512
  untiled images.
502
513
  :param topImage: if specified, add image-embedded metadata to this
503
514
  image.
515
+ :param imageId: if specified, use this as the image name.
504
516
  """
505
517
  try:
506
518
  associated = self.getTiffDir(directoryNum, mustBeTiled)
@@ -514,6 +526,8 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
514
526
  id = 'dir%d' % directoryNum
515
527
  if not len(self._associatedImages):
516
528
  id = 'macro'
529
+ if imageId:
530
+ id = imageId
517
531
  if not id and not mustBeTiled:
518
532
  id = {1: 'label', 9: 'macro'}.get(associated._tiffInfo.get('subfiletype'))
519
533
  if not isinstance(id, str):
@@ -765,7 +779,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
765
779
  """
766
780
  imageList = set(self._associatedImages)
767
781
  for td in self._tiffDirectories:
768
- if td is not None:
782
+ if td is not None and td is not False:
769
783
  imageList |= set(td._embeddedImages)
770
784
  return sorted(imageList)
771
785
 
@@ -784,7 +798,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
784
798
  # with seemingly bad associated images, we may need to read them with a
785
799
  # more complex process than read_image.
786
800
  for td in self._tiffDirectories:
787
- if td is not None and imageKey in td._embeddedImages:
801
+ if td is not None and td is not False and imageKey in td._embeddedImages:
788
802
  return PIL.Image.open(io.BytesIO(base64.b64decode(td._embeddedImages[imageKey])))
789
803
  if imageKey in self._associatedImages:
790
804
  return PIL.Image.fromarray(self._associatedImages[imageKey])
@@ -788,11 +788,13 @@ class TiledTiffDirectory:
788
788
 
789
789
  if (not self._tiffInfo.get('istiled') or
790
790
  self._tiffInfo.get('compression') not in {
791
- libtiff_ctypes.COMPRESSION_JPEG, 33003, 33005, 34712} or
791
+ libtiff_ctypes.COMPRESSION_JPEG, 33003, 33004, 33005, 34712} or
792
792
  self._tiffInfo.get('bitspersample') != 8 or
793
793
  self._tiffInfo.get('sampleformat') not in {
794
794
  None, libtiff_ctypes.SAMPLEFORMAT_UINT} or
795
- (asarray and self._tiffInfo.get('compression') not in {33003, 33005, 34712} and (
795
+ (asarray and self._tiffInfo.get('compression') not in {
796
+ 33003, 33004, 33005, 34712,
797
+ } and (
796
798
  self._tiffInfo.get('compression') != libtiff_ctypes.COMPRESSION_JPEG or
797
799
  self._tiffInfo.get('photometric') != libtiff_ctypes.PHOTOMETRIC_YCBCR))):
798
800
  return self._getUncompressedTile(tileNum)
@@ -811,7 +813,7 @@ class TiledTiffDirectory:
811
813
  # Get the whole frame, which is in a JPEG or JPEG 2000 format
812
814
  frame = self._getJpegFrame(tileNum, True)
813
815
  # For JP2K, see if we can convert it faster than PIL
814
- if self._tiffInfo.get('compression') in {33003, 33005}:
816
+ if self._tiffInfo.get('compression') in {33003, 33004, 33005, 34712}:
815
817
  try:
816
818
  import openjpeg
817
819
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: large-image-source-tiff
3
- Version: 1.30.6.dev14
3
+ Version: 1.30.6.dev18
4
4
  Summary: A TIFF tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -19,13 +19,13 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Requires-Python: >=3.8
20
20
  Description-Content-Type: text/x-rst
21
21
  License-File: LICENSE
22
- Requires-Dist: large-image>=1.30.6.dev14
22
+ Requires-Dist: large-image>=1.30.6.dev18
23
23
  Requires-Dist: pylibtiff
24
24
  Requires-Dist: tifftools>=1.2.0
25
25
  Provides-Extra: all
26
26
  Requires-Dist: pylibjpeg-openjpeg; extra == "all"
27
27
  Provides-Extra: girder
28
- Requires-Dist: girder-large-image>=1.30.6.dev14; extra == "girder"
28
+ Requires-Dist: girder-large-image>=1.30.6.dev18; extra == "girder"
29
29
 
30
30
  A TIFF tilesource for large_image.
31
31
 
@@ -0,0 +1,10 @@
1
+ large_image_source_tiff/__init__.py,sha256=F3mCl2eWSg4Lmqi5EXhpLTsjjjYJn-qrP4OgxndFEtk,36627
2
+ large_image_source_tiff/exceptions.py,sha256=NgdwloaDCtbtUMe2BU2lXEU8IwQSYtaokIwGIFypCps,617
3
+ large_image_source_tiff/girder_source.py,sha256=Dp2e3O4VTANYXZI_eybgzs5BcyuMcw2-MAzCUJ8zzPg,1031
4
+ large_image_source_tiff/tiff_reader.py,sha256=lsE00vLYi93cnoit66dq1S9N8f194JC5L66_5HVCV1w,39210
5
+ large_image_source_tiff-1.30.6.dev18.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
+ large_image_source_tiff-1.30.6.dev18.dist-info/METADATA,sha256=4pA3UxzYcKgety1sBrHuMeFZAKgW7TXfzdxXMb9udII,1188
7
+ large_image_source_tiff-1.30.6.dev18.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
+ large_image_source_tiff-1.30.6.dev18.dist-info/entry_points.txt,sha256=iZ43sIcj98SND7nDUC-_4qroBL6apyXN4iSbPXZ8LE4,166
9
+ large_image_source_tiff-1.30.6.dev18.dist-info/top_level.txt,sha256=QRx_D2oeiOOz_5FlBOAoDPF-E4Q-aFmerUWlaeP14B8,24
10
+ large_image_source_tiff-1.30.6.dev18.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- large_image_source_tiff/__init__.py,sha256=lUgwD58vyfM3QOGY3913jfneHUzSYIkui0YlB2-bhzY,36060
2
- large_image_source_tiff/exceptions.py,sha256=NgdwloaDCtbtUMe2BU2lXEU8IwQSYtaokIwGIFypCps,617
3
- large_image_source_tiff/girder_source.py,sha256=Dp2e3O4VTANYXZI_eybgzs5BcyuMcw2-MAzCUJ8zzPg,1031
4
- large_image_source_tiff/tiff_reader.py,sha256=Gqzv3ct5YDicho9l23a0Gjoyln7TJNEbqAov4RnHRGI,39143
5
- large_image_source_tiff-1.30.6.dev14.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
- large_image_source_tiff-1.30.6.dev14.dist-info/METADATA,sha256=n2EL5cY23RI_we7HZ8VHbShrmHDrr102XmUiZ0Snee8,1188
7
- large_image_source_tiff-1.30.6.dev14.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
- large_image_source_tiff-1.30.6.dev14.dist-info/entry_points.txt,sha256=iZ43sIcj98SND7nDUC-_4qroBL6apyXN4iSbPXZ8LE4,166
9
- large_image_source_tiff-1.30.6.dev14.dist-info/top_level.txt,sha256=QRx_D2oeiOOz_5FlBOAoDPF-E4Q-aFmerUWlaeP14B8,24
10
- large_image_source_tiff-1.30.6.dev14.dist-info/RECORD,,