large-image-source-tiff 1.30.6__py3-none-any.whl → 1.30.6.dev4__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.
@@ -141,7 +141,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
141
141
  continue
142
142
  # If a layer is a multiple of the tile size, the number of tiles
143
143
  # should be a power of two rounded up from the primary.
144
- if not (td.imageWidth % td.tileWidth) and not (td.imageHeight % td.tileHeight):
144
+ if (not (td.imageWidth % td.tileWidth) and not (td.imageHeight % td.tileHeight)):
145
145
  htw = highest.imageWidth // td.tileWidth
146
146
  hth = highest.imageHeight // td.tileHeight
147
147
  ttw = td.imageWidth // td.tileWidth
@@ -327,19 +327,12 @@ 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
331
330
  for idx, ifd in enumerate(info['ifds']):
332
331
  # if not tiles, add to associated images
333
332
  if tifftools.Tag.tileWidth.value not in ifd['tags']:
334
- associated.append((idx, False))
333
+ associated.append(idx)
335
334
  continue
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
335
+ level = self._levelFromIfd(ifd, info['ifds'][0])
343
336
  # if the same resolution as the main image, add a frame
344
337
  if level == self.levels - 1:
345
338
  frames.append({'dirs': [None] * self.levels})
@@ -378,13 +371,9 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
378
371
  tifftools.Tag.TileOffsets.value not in subifds[0]['tags']):
379
372
  msg = 'Subifd has no strip or tile offsets.'
380
373
  raise TileSourceMalformedError(msg)
381
- try:
382
- level = self._levelFromIfd(subifds[0], info['ifds'][0])
383
- except Exception:
384
- break
374
+ level = self._levelFromIfd(subifds[0], info['ifds'][0])
385
375
  if level < self.levels - 1 and frames[-1]['dirs'][level] is None:
386
376
  frames[-1]['dirs'][level] = (idx, subidx + 1)
387
- used_subifd = True
388
377
  else:
389
378
  msg = 'Tile layers are in a surprising order'
390
379
  raise TileSourceError(msg)
@@ -418,8 +407,8 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
418
407
  self._iccprofiles.append(ifd['tags'][
419
408
  tifftools.Tag.ICCProfile.value]['data'])
420
409
  self._associatedImages = {}
421
- for dirNum, isTiled in associated:
422
- self._addAssociatedImage(dirNum, isTiled)
410
+ for dirNum in associated:
411
+ self._addAssociatedImage(dirNum)
423
412
  self._frames = frames
424
413
  self._tiffDirectories = [
425
414
  self.getTiffDir(
@@ -501,7 +490,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
501
490
  frame.setdefault('frame', {})
502
491
  frame['frame']['IndexC'] = idx
503
492
 
504
- def _addAssociatedImage(self, directoryNum, mustBeTiled=False, topImage=None, imageId=None):
493
+ def _addAssociatedImage(self, directoryNum, mustBeTiled=False, topImage=None):
505
494
  """
506
495
  Check if the specified TIFF directory contains an image with a sensible
507
496
  image description that can be used as an ID. If so, and if the image
@@ -512,7 +501,6 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
512
501
  untiled images.
513
502
  :param topImage: if specified, add image-embedded metadata to this
514
503
  image.
515
- :param imageId: if specified, use this as the image name.
516
504
  """
517
505
  try:
518
506
  associated = self.getTiffDir(directoryNum, mustBeTiled)
@@ -526,8 +514,6 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
526
514
  id = 'dir%d' % directoryNum
527
515
  if not len(self._associatedImages):
528
516
  id = 'macro'
529
- if imageId:
530
- id = imageId
531
517
  if not id and not mustBeTiled:
532
518
  id = {1: 'label', 9: 'macro'}.get(associated._tiffInfo.get('subfiletype'))
533
519
  if not isinstance(id, str):
@@ -539,7 +525,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
539
525
  associated._pixelInfo['width'] <= self._maxAssociatedImageSize and
540
526
  associated._pixelInfo['height'] <= self._maxAssociatedImageSize and
541
527
  id not in self._associatedImages):
542
- image = associated.read_image()
528
+ image = associated._tiffFile.read_image()
543
529
  # Optrascan scanners store xml image descriptions in a "tiled
544
530
  # image". Check if this is the case, and, if so, parse such
545
531
  # data
@@ -695,7 +681,8 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
695
681
  except Exception:
696
682
  if sparseFallback:
697
683
  raise IOTiffError('Missing z level %d' % z)
698
- raise
684
+ else:
685
+ raise
699
686
  else:
700
687
  tile = dir.getTile(x, y, asarray=numpyAllowed == 'always')
701
688
  format = 'JPEG'
@@ -778,7 +765,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
778
765
  """
779
766
  imageList = set(self._associatedImages)
780
767
  for td in self._tiffDirectories:
781
- if td is not None and td is not False:
768
+ if td is not None:
782
769
  imageList |= set(td._embeddedImages)
783
770
  return sorted(imageList)
784
771
 
@@ -793,11 +780,11 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
793
780
  # _associatedImages. There are some sample files where libtiff's
794
781
  # read_image fails to read the _associatedImage properly because of
795
782
  # separated jpeg information. For the samples we currently have,
796
- # preferring the _embeddedImages is sufficient, but if we find other
797
- # files with seemingly bad associated images, we may need to read them
798
- # with a more complex process than read_image.
783
+ # preferring the _embeddedImages is sufficient, but if find other files
784
+ # with seemingly bad associated images, we may need to read them with a
785
+ # more complex process than read_image.
799
786
  for td in self._tiffDirectories:
800
- if td is not None and td is not False and imageKey in td._embeddedImages:
787
+ if td is not None and imageKey in td._embeddedImages:
801
788
  return PIL.Image.open(io.BytesIO(base64.b64decode(td._embeddedImages[imageKey])))
802
789
  if imageKey in self._associatedImages:
803
790
  return PIL.Image.fromarray(self._associatedImages[imageKey])
@@ -447,11 +447,12 @@ class TiledTiffDirectory:
447
447
 
448
448
  if tileByteCountsLibtiffType == libtiff_ctypes.TIFFDataType.TIFF_LONG8:
449
449
  return ctypes.c_uint64
450
- if tileByteCountsLibtiffType == \
450
+ elif tileByteCountsLibtiffType == \
451
451
  libtiff_ctypes.TIFFDataType.TIFF_SHORT:
452
452
  return ctypes.c_uint16
453
- raise IOTiffError(
454
- 'Invalid type for TIFFTAG_TILEBYTECOUNTS: %s' % tileByteCountsLibtiffType)
453
+ else:
454
+ raise IOTiffError(
455
+ 'Invalid type for TIFFTAG_TILEBYTECOUNTS: %s' % tileByteCountsLibtiffType)
455
456
 
456
457
  def _getJpegFrameSize(self, tileNum):
457
458
  """
@@ -528,10 +529,10 @@ class TiledTiffDirectory:
528
529
  if bytesRead == -1:
529
530
  msg = 'Failed to read raw tile'
530
531
  raise IOTiffError(msg)
531
- if bytesRead < rawTileSize:
532
+ elif bytesRead < rawTileSize:
532
533
  msg = 'Buffer underflow when reading tile'
533
534
  raise IOTiffError(msg)
534
- if bytesRead > rawTileSize:
535
+ elif bytesRead > rawTileSize:
535
536
  # It's unlikely that this will ever occur, but incomplete reads will
536
537
  # be checked for by looking for the JPEG end marker
537
538
  msg = 'Buffer overflow when reading tile'
@@ -787,13 +788,11 @@ class TiledTiffDirectory:
787
788
 
788
789
  if (not self._tiffInfo.get('istiled') or
789
790
  self._tiffInfo.get('compression') not in {
790
- libtiff_ctypes.COMPRESSION_JPEG, 33003, 33004, 33005, 34712} or
791
+ libtiff_ctypes.COMPRESSION_JPEG, 33003, 33005, 34712} or
791
792
  self._tiffInfo.get('bitspersample') != 8 or
792
793
  self._tiffInfo.get('sampleformat') not in {
793
794
  None, libtiff_ctypes.SAMPLEFORMAT_UINT} or
794
- (asarray and self._tiffInfo.get('compression') not in {
795
- 33003, 33004, 33005, 34712,
796
- } and (
795
+ (asarray and self._tiffInfo.get('compression') not in {33003, 33005, 34712} and (
797
796
  self._tiffInfo.get('compression') != libtiff_ctypes.COMPRESSION_JPEG or
798
797
  self._tiffInfo.get('photometric') != libtiff_ctypes.PHOTOMETRIC_YCBCR))):
799
798
  return self._getUncompressedTile(tileNum)
@@ -812,7 +811,7 @@ class TiledTiffDirectory:
812
811
  # Get the whole frame, which is in a JPEG or JPEG 2000 format
813
812
  frame = self._getJpegFrame(tileNum, True)
814
813
  # For JP2K, see if we can convert it faster than PIL
815
- if self._tiffInfo.get('compression') in {33003, 33004, 33005, 34712}:
814
+ if self._tiffInfo.get('compression') in {33003, 33005}:
816
815
  try:
817
816
  import openjpeg
818
817
 
@@ -837,7 +836,7 @@ class TiledTiffDirectory:
837
836
  self._embeddedImages = {}
838
837
 
839
838
  if not meta:
840
- return None
839
+ return
841
840
  if not isinstance(meta, str):
842
841
  meta = meta.decode(errors='ignore')
843
842
  try:
@@ -859,7 +858,7 @@ class TiledTiffDirectory:
859
858
  meta.split('|MPP = ', 1)[1].split('|')[0].strip()) * 0.001
860
859
  except Exception:
861
860
  pass
862
- return None
861
+ return
863
862
  try:
864
863
  image = xml.find(
865
864
  ".//DataObject[@ObjectType='DPScannedImage']")
@@ -895,26 +894,3 @@ class TiledTiffDirectory:
895
894
  except Exception:
896
895
  pass
897
896
  return True
898
-
899
- def read_image(self):
900
- """
901
- Use the underlying _tiffFile to read an image. But, if it is in a jp2k
902
- encoding, read the raw data and convert it.
903
- """
904
- if self._tiffInfo.get('compression') not in {33003, 33004, 33005, 34712}:
905
- return self._tiffFile.read_image()
906
- output = None
907
- for yidx, y in enumerate(range(0, self.imageHeight, self.tileHeight)):
908
- for xidx, x in enumerate(range(0, self.imageWidth, self.tileWidth)):
909
- tile = self.getTile(xidx, yidx, asarray=True)
910
- if len(tile.shape) == 2:
911
- tile = tile[:, :, np.newaxis]
912
- if output is None:
913
- output = np.zeros(
914
- (self.imageHeight, self.imageWidth, tile.shape[2]), dtype=tile.dtype)
915
- if tile.shape[0] > self.imageHeight - y:
916
- tile = tile[:self.imageHeight - y, :, :]
917
- if tile.shape[1] > self.imageWidth - x:
918
- tile = tile[:, :self.imageWidth - x, :]
919
- output[y:y + tile.shape[0], x:x + tile.shape[1], :] = tile
920
- return output
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.1
2
2
  Name: large-image-source-tiff
3
- Version: 1.30.6
3
+ Version: 1.30.6.dev4
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,25 +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
22
+ Requires-Dist: large-image>=1.30.6.dev4
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; extra == "girder"
29
- Dynamic: author
30
- Dynamic: author-email
31
- Dynamic: classifier
32
- Dynamic: description
33
- Dynamic: description-content-type
34
- Dynamic: home-page
35
- Dynamic: keywords
36
- Dynamic: license
37
- Dynamic: provides-extra
38
- Dynamic: requires-dist
39
- Dynamic: requires-python
40
- Dynamic: summary
28
+ Requires-Dist: girder-large-image>=1.30.6.dev4; extra == "girder"
41
29
 
42
30
  A TIFF tilesource for large_image.
43
31
 
@@ -0,0 +1,10 @@
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.dev4.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
+ large_image_source_tiff-1.30.6.dev4.dist-info/METADATA,sha256=6j9GKhtm4jtsKn_abHjlqALu5Xz_K6haLN0xxDIiSas,1185
7
+ large_image_source_tiff-1.30.6.dev4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
8
+ large_image_source_tiff-1.30.6.dev4.dist-info/entry_points.txt,sha256=iZ43sIcj98SND7nDUC-_4qroBL6apyXN4iSbPXZ8LE4,166
9
+ large_image_source_tiff-1.30.6.dev4.dist-info/top_level.txt,sha256=QRx_D2oeiOOz_5FlBOAoDPF-E4Q-aFmerUWlaeP14B8,24
10
+ large_image_source_tiff-1.30.6.dev4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- large_image_source_tiff/__init__.py,sha256=o-NkH3SI7XLmEdejSREFMw39kfTMu2LiV3GGHsmNrPQ,36588
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=gkAhuB4-IRzNLlNr958HKE9JZpRJwVo4zRGMd4rsD2o,40338
5
- large_image_source_tiff-1.30.6.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
- large_image_source_tiff-1.30.6.dist-info/METADATA,sha256=vj4QlrQcVdZVAR1VueoBLVs-lYUFrD6G2lOpdDsDa2c,1426
7
- large_image_source_tiff-1.30.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
- large_image_source_tiff-1.30.6.dist-info/entry_points.txt,sha256=iZ43sIcj98SND7nDUC-_4qroBL6apyXN4iSbPXZ8LE4,166
9
- large_image_source_tiff-1.30.6.dist-info/top_level.txt,sha256=QRx_D2oeiOOz_5FlBOAoDPF-E4Q-aFmerUWlaeP14B8,24
10
- large_image_source_tiff-1.30.6.dist-info/RECORD,,