large-image-source-tiff 1.28.2.dev10__py3-none-any.whl → 1.28.2.dev14__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.

Potentially problematic release.


This version of large-image-source-tiff might be problematic. Click here for more details.

@@ -73,6 +73,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
73
73
  }
74
74
 
75
75
  _maxAssociatedImageSize = 8192
76
+ _maxUntiledImage = 4096
76
77
 
77
78
  def __init__(self, path, **kwargs): # noqa
78
79
  """
@@ -85,18 +86,18 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
85
86
 
86
87
  self._largeImagePath = str(self._getLargeImagePath())
87
88
 
89
+ lastException = None
88
90
  try:
89
91
  self._initWithTiffTools()
90
92
  return
91
93
  except Exception as exc:
92
94
  self.logger.debug('Cannot read with tifftools route; %r', exc)
95
+ lastException = exc
93
96
 
94
97
  alldir = []
95
98
  try:
96
99
  if hasattr(self, '_info'):
97
100
  alldir = self._scanDirectories()
98
- else:
99
- lastException = 'Could not parse file with tifftools'
100
101
  except IOOpenTiffError:
101
102
  msg = 'File cannot be opened via tiff source.'
102
103
  raise TileSourceError(msg)
@@ -157,7 +158,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
157
158
  tifftools.constants.SampleFormat[sampleformat or 1].name,
158
159
  bitspersample,
159
160
  ))
160
- self._bandCount = highest._tiffInfo.get('samplesperpixel')
161
+ self._bandCount = highest._tiffInfo.get('samplesperpixel', 1)
161
162
  # Sort the directories so that the highest resolution is the last one;
162
163
  # if a level is missing, put a None value in its place.
163
164
  self._tiffDirectories = [directories.get(key) for key in
@@ -252,8 +253,13 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
252
253
  """
253
254
  sizeX = ifd['tags'][tifftools.Tag.ImageWidth.value]['data'][0]
254
255
  sizeY = ifd['tags'][tifftools.Tag.ImageLength.value]['data'][0]
255
- tileWidth = baseifd['tags'][tifftools.Tag.TileWidth.value]['data'][0]
256
- tileHeight = baseifd['tags'][tifftools.Tag.TileLength.value]['data'][0]
256
+ if tifftools.Tag.TileWidth.value in baseifd['tags']:
257
+ tileWidth = baseifd['tags'][tifftools.Tag.TileWidth.value]['data'][0]
258
+ tileHeight = baseifd['tags'][tifftools.Tag.TileLength.value]['data'][0]
259
+ else:
260
+ tileWidth = sizeX
261
+ tileHeight = baseifd['tags'][tifftools.Tag.RowsPerStrip.value]['data'][0]
262
+
257
263
  for tag in {
258
264
  tifftools.Tag.SamplesPerPixel.value,
259
265
  tifftools.Tag.BitsPerSample.value,
@@ -298,7 +304,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
298
304
  directories are the same size and format; all non-tiled directories are
299
305
  treated as associated images.
300
306
  """
301
- dir0 = self.getTiffDir(0)
307
+ dir0 = self.getTiffDir(0, mustBeTiled=None)
302
308
  self.tileWidth = dir0.tileWidth
303
309
  self.tileHeight = dir0.tileHeight
304
310
  self.sizeX = dir0.imageWidth
@@ -312,12 +318,11 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
312
318
  tifftools.constants.SampleFormat[sampleformat or 1].name,
313
319
  bitspersample,
314
320
  ))
315
- self._bandCount = dir0._tiffInfo.get('samplesperpixel')
321
+ self._bandCount = dir0._tiffInfo.get('samplesperpixel', 1)
316
322
  info = _cached_read_tiff(self._largeImagePath)
317
323
  self._info = info
318
324
  frames = []
319
325
  associated = [] # for now, a list of directories
320
- curframe = -1
321
326
  for idx, ifd in enumerate(info['ifds']):
322
327
  # if not tiles, add to associated images
323
328
  if tifftools.Tag.tileWidth.value not in ifd['tags']:
@@ -326,7 +331,6 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
326
331
  level = self._levelFromIfd(ifd, info['ifds'][0])
327
332
  # if the same resolution as the main image, add a frame
328
333
  if level == self.levels - 1:
329
- curframe += 1
330
334
  frames.append({'dirs': [None] * self.levels})
331
335
  frames[-1]['dirs'][-1] = (idx, 0)
332
336
  try:
@@ -365,6 +369,35 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
365
369
  else:
366
370
  msg = 'Tile layers are in a surprising order'
367
371
  raise TileSourceError(msg)
372
+ # If we have a single untiled ifd that is "small", use it
373
+ if tifftools.Tag.tileWidth.value not in info['ifds'][0]['tags']:
374
+ if (
375
+ self.sizeX > self._maxUntiledImage or self.sizeY > self._maxUntiledImage or
376
+ (len(info['ifds']) != 1 or tifftools.Tag.SubIfd.value in ifd['tags']) or
377
+ (tifftools.Tag.ImageDescription.value in ifd['tags'] and
378
+ 'ImageJ' in ifd['tags'][tifftools.Tag.ImageDescription.value]['data'])
379
+ ):
380
+ msg = 'A tiled TIFF is required.'
381
+ raise ValidationTiffError(msg)
382
+ associated = []
383
+ level = self._levelFromIfd(ifd, info['ifds'][0])
384
+ frames.append({'dirs': [None] * self.levels})
385
+ frames[-1]['dirs'][-1] = (idx, 0)
386
+ try:
387
+ frameMetadata = json.loads(
388
+ ifd['tags'][tifftools.Tag.ImageDescription.value]['data'])
389
+ for key in {'channels', 'frame'}:
390
+ if key in frameMetadata:
391
+ frames[-1][key] = frameMetadata[key]
392
+ except Exception:
393
+ pass
394
+ if tifftools.Tag.ICCProfile.value in ifd['tags']:
395
+ if not hasattr(self, '_iccprofiles'):
396
+ self._iccprofiles = []
397
+ while len(self._iccprofiles) < len(frames) - 1:
398
+ self._iccprofiles.append(None)
399
+ self._iccprofiles.append(ifd['tags'][
400
+ tifftools.Tag.ICCProfile.value]['data'])
368
401
  self._associatedImages = {}
369
402
  for dirNum in associated:
370
403
  self._addAssociatedImage(dirNum)
@@ -207,8 +207,8 @@ class TiledTiffDirectory:
207
207
  # the create_image.py script, such as flatten or colourspace. These
208
208
  # should only be done if necessary, which would require the conversion
209
209
  # job to check output and perform subsequent processing as needed.
210
- if (not self._tiffInfo.get('samplesperpixel') or
211
- self._tiffInfo.get('samplesperpixel') < 1):
210
+ if (not self._tiffInfo.get('samplesperpixel', 1) or
211
+ self._tiffInfo.get('samplesperpixel', 1) < 1):
212
212
  msg = 'Only RGB and greyscale TIFF files are supported'
213
213
  raise ValidationTiffError(msg)
214
214
 
@@ -607,7 +607,7 @@ class TiledTiffDirectory:
607
607
  self._tiffInfo.get('bitspersample'),
608
608
  self._tiffInfo.get('sampleformat') if self._tiffInfo.get(
609
609
  'sampleformat') is not None else libtiff_ctypes.SAMPLEFORMAT_UINT)
610
- image = np.empty((th, tw, self._tiffInfo['samplesperpixel']),
610
+ image = np.empty((th, tw, self._tiffInfo.get('samplesperpixel', 1)),
611
611
  dtype=_ctypesFormattbl[format])
612
612
  imageBuffer = image.ctypes.data_as(ctypes.POINTER(ctypes.c_char))
613
613
  if self._tiffInfo.get('istiled'):
@@ -635,7 +635,7 @@ class TiledTiffDirectory:
635
635
  raise IOTiffError(
636
636
  'Read an unexpected number of bytes from an encoded tile' if readSize >= 0 else
637
637
  'Failed to read from an encoded tile')
638
- if (self._tiffInfo.get('samplesperpixel') == 3 and
638
+ if (self._tiffInfo.get('samplesperpixel', 1) == 3 and
639
639
  self._tiffInfo.get('photometric') == libtiff_ctypes.PHOTOMETRIC_YCBCR):
640
640
  if self._tiffInfo.get('bitspersample') == 16:
641
641
  image = np.floor_divide(image, 256).astype(np.uint8)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: large-image-source-tiff
3
- Version: 1.28.2.dev10
3
+ Version: 1.28.2.dev14
4
4
  Summary: A TIFF tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -17,11 +17,11 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Python: >=3.8
19
19
  License-File: LICENSE
20
- Requires-Dist: large-image >=1.28.2.dev10
20
+ Requires-Dist: large-image >=1.28.2.dev14
21
21
  Requires-Dist: pylibtiff
22
22
  Requires-Dist: tifftools >=1.2.0
23
23
  Provides-Extra: girder
24
- Requires-Dist: girder-large-image >=1.28.2.dev10 ; extra == 'girder'
24
+ Requires-Dist: girder-large-image >=1.28.2.dev14 ; extra == 'girder'
25
25
 
26
26
  A TIFF tilesource for large_image.
27
27
 
@@ -0,0 +1,10 @@
1
+ large_image_source_tiff/__init__.py,sha256=jviPOv6MViHA6Lfq8rm4TNFvnO_9dqho9Lt_xAQLLjQ,35736
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=xrutsp0YGeVeURN0Yf53whbYmKghpEzWC6349WhsMR8,38650
5
+ large_image_source_tiff-1.28.2.dev14.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
+ large_image_source_tiff-1.28.2.dev14.dist-info/METADATA,sha256=tPOBFIewSbYhr4K0DtfQSyqNkGEsDn0kskqcEOxXtXI,1034
7
+ large_image_source_tiff-1.28.2.dev14.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
8
+ large_image_source_tiff-1.28.2.dev14.dist-info/entry_points.txt,sha256=iZ43sIcj98SND7nDUC-_4qroBL6apyXN4iSbPXZ8LE4,166
9
+ large_image_source_tiff-1.28.2.dev14.dist-info/top_level.txt,sha256=QRx_D2oeiOOz_5FlBOAoDPF-E4Q-aFmerUWlaeP14B8,24
10
+ large_image_source_tiff-1.28.2.dev14.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- large_image_source_tiff/__init__.py,sha256=pJmuf2byaUWyTmCQpRa03V3wRfaoM7S46DUONY0aZds,34024
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=xZGz9P97LHfL5kmxVCL1ek0ry259LNp39yGls6tnpnM,38634
5
- large_image_source_tiff-1.28.2.dev10.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
6
- large_image_source_tiff-1.28.2.dev10.dist-info/METADATA,sha256=glBMrldnmGoMkRJnLhgUVVGvEYBkKQIlCfzaJSnuL74,1034
7
- large_image_source_tiff-1.28.2.dev10.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
8
- large_image_source_tiff-1.28.2.dev10.dist-info/entry_points.txt,sha256=iZ43sIcj98SND7nDUC-_4qroBL6apyXN4iSbPXZ8LE4,166
9
- large_image_source_tiff-1.28.2.dev10.dist-info/top_level.txt,sha256=QRx_D2oeiOOz_5FlBOAoDPF-E4Q-aFmerUWlaeP14B8,24
10
- large_image_source_tiff-1.28.2.dev10.dist-info/RECORD,,