large-image-source-tiff 1.30.6__tar.gz → 1.30.6.dev2__tar.gz
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.
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/PKG-INFO +3 -3
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff/__init__.py +15 -28
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff/tiff_reader.py +11 -35
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff.egg-info/PKG-INFO +3 -3
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff.egg-info/requires.txt +2 -2
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/setup.py +2 -1
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/LICENSE +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/README.rst +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff/exceptions.py +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff/girder_source.py +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff.egg-info/SOURCES.txt +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff.egg-info/dependency_links.txt +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff.egg-info/entry_points.txt +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/large_image_source_tiff.egg-info/top_level.txt +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/pyproject.toml +0 -0
- {large_image_source_tiff-1.30.6 → large_image_source_tiff-1.30.6.dev2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: large-image-source-tiff
|
3
|
-
Version: 1.30.6
|
3
|
+
Version: 1.30.6.dev2
|
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
|
22
|
+
Requires-Dist: large-image>=1.30.6.dev2
|
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"
|
28
|
+
Requires-Dist: girder-large-image>=1.30.6.dev2; extra == "girder"
|
29
29
|
|
30
30
|
A TIFF tilesource for large_image.
|
31
31
|
|
@@ -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(
|
333
|
+
associated.append(idx)
|
335
334
|
continue
|
336
|
-
|
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
|
-
|
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
|
422
|
-
self._addAssociatedImage(dirNum
|
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
|
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
|
-
|
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
|
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
|
797
|
-
#
|
798
|
-
#
|
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
|
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
|
-
|
450
|
+
elif tileByteCountsLibtiffType == \
|
451
451
|
libtiff_ctypes.TIFFDataType.TIFF_SHORT:
|
452
452
|
return ctypes.c_uint16
|
453
|
-
|
454
|
-
|
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
|
-
|
532
|
+
elif bytesRead < rawTileSize:
|
532
533
|
msg = 'Buffer underflow when reading tile'
|
533
534
|
raise IOTiffError(msg)
|
534
|
-
|
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,
|
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,
|
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
|
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
|
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
1
|
Metadata-Version: 2.1
|
2
2
|
Name: large-image-source-tiff
|
3
|
-
Version: 1.30.6
|
3
|
+
Version: 1.30.6.dev2
|
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
|
22
|
+
Requires-Dist: large-image>=1.30.6.dev2
|
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"
|
28
|
+
Requires-Dist: girder-large-image>=1.30.6.dev2; extra == "girder"
|
29
29
|
|
30
30
|
A TIFF tilesource for large_image.
|
31
31
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|