large-image-source-tiff 1.26.4.dev14__tar.gz → 1.27.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (17) hide show
  1. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/PKG-INFO +1 -1
  2. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff/__init__.py +1 -1
  3. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff/tiff_reader.py +52 -40
  4. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff.egg-info/PKG-INFO +1 -1
  5. large-image-source-tiff-1.27.1/large_image_source_tiff.egg-info/requires.txt +6 -0
  6. large-image-source-tiff-1.26.4.dev14/large_image_source_tiff.egg-info/requires.txt +0 -6
  7. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/LICENSE +0 -0
  8. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/README.rst +0 -0
  9. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff/exceptions.py +0 -0
  10. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff/girder_source.py +0 -0
  11. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff.egg-info/SOURCES.txt +0 -0
  12. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff.egg-info/dependency_links.txt +0 -0
  13. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff.egg-info/entry_points.txt +0 -0
  14. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/large_image_source_tiff.egg-info/top_level.txt +0 -0
  15. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/pyproject.toml +0 -0
  16. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/setup.cfg +0 -0
  17. {large-image-source-tiff-1.26.4.dev14 → large-image-source-tiff-1.27.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: large-image-source-tiff
3
- Version: 1.26.4.dev14
3
+ Version: 1.27.1
4
4
  Summary: A TIFF tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -645,7 +645,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
645
645
  allowStyle = False
646
646
  format = TILE_FORMAT_PIL
647
647
  else:
648
- tile = dir.getTile(x, y)
648
+ tile = dir.getTile(x, y, asarray=numpyAllowed == 'always')
649
649
  format = 'JPEG'
650
650
  if isinstance(tile, PIL.Image.Image):
651
651
  format = TILE_FORMAT_PIL
@@ -53,6 +53,21 @@ libtiff_ctypes.suppress_warnings()
53
53
  libtiff_ctypes.suppress_errors()
54
54
 
55
55
 
56
+ _ctypesFormattbl = {
57
+ (8, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint8,
58
+ (8, libtiff_ctypes.SAMPLEFORMAT_INT): np.int8,
59
+ (16, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint16,
60
+ (16, libtiff_ctypes.SAMPLEFORMAT_INT): np.int16,
61
+ (16, libtiff_ctypes.SAMPLEFORMAT_IEEEFP): np.float16,
62
+ (32, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint32,
63
+ (32, libtiff_ctypes.SAMPLEFORMAT_INT): np.int32,
64
+ (32, libtiff_ctypes.SAMPLEFORMAT_IEEEFP): np.float32,
65
+ (64, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint64,
66
+ (64, libtiff_ctypes.SAMPLEFORMAT_INT): np.int64,
67
+ (64, libtiff_ctypes.SAMPLEFORMAT_IEEEFP): np.float64,
68
+ }
69
+
70
+
56
71
  def patchLibtiff():
57
72
  libtiff_ctypes.libtiff.TIFFFieldWithTag.restype = \
58
73
  ctypes.POINTER(libtiff_ctypes.TIFFFieldInfo)
@@ -286,6 +301,7 @@ class TiledTiffDirectory:
286
301
  self._tileHeight = info.get('tilelength') or info.get('rowsperstrip')
287
302
  self._imageWidth = info.get('imagewidth')
288
303
  self._imageHeight = info.get('imagelength')
304
+ self._tilesAcross = (self._imageWidth + self._tileWidth - 1) // self._tileWidth
289
305
  if not info.get('tilelength'):
290
306
  self._stripsPerTile = int(max(1, math.ceil(256.0 / self._tileHeight)))
291
307
  self._stripHeight = self._tileHeight
@@ -404,12 +420,11 @@ class TiledTiffDirectory:
404
420
  # raise InvalidOperationTiffError(
405
421
  # 'Tile x=%d, y=%d does not exist' % (x, y))
406
422
  if self._tiffInfo.get('istiled'):
407
- tileNum = libtiff_ctypes.libtiff.TIFFComputeTile(
408
- self._tiffFile, pixelX, pixelY, 0, 0).value
423
+ tileNum = pixelX // self._tileWidth + (pixelY // self._tileHeight) * self._tilesAcross
409
424
  else:
410
425
  # TIFFComputeStrip with sample=0 is just the row divided by the
411
426
  # strip height
412
- tileNum = int(pixelY // self._stripHeight)
427
+ tileNum = pixelY // self._stripHeight
413
428
  return tileNum
414
429
 
415
430
  @methodcache(key=partial(strhash, '_getTileByteCountsType'))
@@ -569,34 +584,39 @@ class TiledTiffDirectory:
569
584
  :rtype: PIL.Image
570
585
  :raises: IOTiffError
571
586
  """
572
- with self._tileLock:
573
- if self._tiffInfo.get('istiled'):
574
- tileSize = libtiff_ctypes.libtiff.TIFFTileSize(self._tiffFile).value
575
- else:
587
+ if self._tiffInfo.get('istiled'):
588
+ if not hasattr(self, '_uncompressedTileSize'):
589
+ with self._tileLock:
590
+ self._uncompressedTileSize = libtiff_ctypes.libtiff.TIFFTileSize(
591
+ self._tiffFile).value
592
+ tileSize = self._uncompressedTileSize
593
+ else:
594
+ with self._tileLock:
576
595
  stripSize = libtiff_ctypes.libtiff.TIFFStripSize(
577
596
  self._tiffFile).value
578
- stripsCount = min(self._stripsPerTile, self._stripCount - tileNum)
579
- tileSize = stripSize * self._stripsPerTile
597
+ stripsCount = min(self._stripsPerTile, self._stripCount - tileNum)
598
+ tileSize = stripSize * self._stripsPerTile
580
599
  imageBuffer = ctypes.create_string_buffer(tileSize)
581
- with self._tileLock:
582
- if self._tiffInfo.get('istiled'):
600
+ if self._tiffInfo.get('istiled'):
601
+ with self._tileLock:
583
602
  readSize = libtiff_ctypes.libtiff.TIFFReadEncodedTile(
584
603
  self._tiffFile, tileNum, imageBuffer, tileSize)
585
- else:
586
- readSize = 0
587
- for stripNum in range(stripsCount):
604
+ else:
605
+ readSize = 0
606
+ for stripNum in range(stripsCount):
607
+ with self._tileLock:
588
608
  chunkSize = libtiff_ctypes.libtiff.TIFFReadEncodedStrip(
589
609
  self._tiffFile,
590
610
  tileNum + stripNum,
591
611
  ctypes.byref(imageBuffer, stripSize * stripNum),
592
612
  stripSize).value
593
- if chunkSize <= 0:
594
- msg = 'Read an unexpected number of bytes from an encoded strip'
595
- raise IOTiffError(msg)
596
- readSize += chunkSize
597
- if readSize < tileSize:
598
- ctypes.memset(ctypes.byref(imageBuffer, readSize), 0, tileSize - readSize)
599
- readSize = tileSize
613
+ if chunkSize <= 0:
614
+ msg = 'Read an unexpected number of bytes from an encoded strip'
615
+ raise IOTiffError(msg)
616
+ readSize += chunkSize
617
+ if readSize < tileSize:
618
+ ctypes.memset(ctypes.byref(imageBuffer, readSize), 0, tileSize - readSize)
619
+ readSize = tileSize
600
620
  if readSize < tileSize:
601
621
  raise IOTiffError(
602
622
  'Read an unexpected number of bytes from an encoded tile' if readSize >= 0 else
@@ -612,23 +632,10 @@ class TiledTiffDirectory:
612
632
  self._tiffInfo.get('bitspersample'),
613
633
  self._tiffInfo.get('sampleformat') if self._tiffInfo.get(
614
634
  'sampleformat') is not None else libtiff_ctypes.SAMPLEFORMAT_UINT)
615
- formattbl = {
616
- (8, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint8,
617
- (8, libtiff_ctypes.SAMPLEFORMAT_INT): np.int8,
618
- (16, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint16,
619
- (16, libtiff_ctypes.SAMPLEFORMAT_INT): np.int16,
620
- (16, libtiff_ctypes.SAMPLEFORMAT_IEEEFP): np.float16,
621
- (32, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint32,
622
- (32, libtiff_ctypes.SAMPLEFORMAT_INT): np.int32,
623
- (32, libtiff_ctypes.SAMPLEFORMAT_IEEEFP): np.float32,
624
- (64, libtiff_ctypes.SAMPLEFORMAT_UINT): np.uint64,
625
- (64, libtiff_ctypes.SAMPLEFORMAT_INT): np.int64,
626
- (64, libtiff_ctypes.SAMPLEFORMAT_IEEEFP): np.float64,
627
- }
628
635
  image = np.ctypeslib.as_array(ctypes.cast(
629
636
  imageBuffer, ctypes.POINTER(ctypes.c_uint8)), (tileSize, )).view(
630
- formattbl[format]).reshape(
631
- (th, tw, self._tiffInfo.get('samplesperpixel')))
637
+ _ctypesFormattbl[format]).reshape(
638
+ (th, tw, self._tiffInfo['samplesperpixel']))
632
639
  if (self._tiffInfo.get('samplesperpixel') == 3 and
633
640
  self._tiffInfo.get('photometric') == libtiff_ctypes.PHOTOMETRIC_YCBCR):
634
641
  if self._tiffInfo.get('bitspersample') == 16:
@@ -754,7 +761,7 @@ class TiledTiffDirectory:
754
761
  def pixelInfo(self):
755
762
  return self._pixelInfo
756
763
 
757
- def getTile(self, x, y):
764
+ def getTile(self, x, y, asarray=False):
758
765
  """
759
766
  Get the complete JPEG image from a tile.
760
767
 
@@ -762,6 +769,8 @@ class TiledTiffDirectory:
762
769
  :type x: int
763
770
  :param y: The row index of the desired tile.
764
771
  :type y: int
772
+ :param asarray: If True, read jpeg compressed images as arrays.
773
+ :type asarray: boolean
765
774
  :return: either a buffer with a JPEG or a PIL image.
766
775
  :rtype: bytes
767
776
  :raises: InvalidOperationTiffError or IOTiffError
@@ -774,11 +783,14 @@ class TiledTiffDirectory:
774
783
  tileNum = self._toTileNum(x, y)
775
784
 
776
785
  if (not self._tiffInfo.get('istiled') or
777
- self._tiffInfo.get('compression') not in (
778
- libtiff_ctypes.COMPRESSION_JPEG, 33003, 33005, 34712) or
786
+ self._tiffInfo.get('compression') not in {
787
+ libtiff_ctypes.COMPRESSION_JPEG, 33003, 33005, 34712} or
779
788
  self._tiffInfo.get('bitspersample') != 8 or
780
789
  self._tiffInfo.get('sampleformat') not in {
781
- None, libtiff_ctypes.SAMPLEFORMAT_UINT}):
790
+ None, libtiff_ctypes.SAMPLEFORMAT_UINT} or
791
+ (asarray and self._tiffInfo.get('compression') not in {33003, 33005, 34712} and (
792
+ self._tiffInfo.get('compression') != libtiff_ctypes.COMPRESSION_JPEG or
793
+ self._tiffInfo.get('photometric') != libtiff_ctypes.PHOTOMETRIC_YCBCR))):
782
794
  return self._getUncompressedTile(tileNum)
783
795
 
784
796
  imageBuffer = io.BytesIO()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: large-image-source-tiff
3
- Version: 1.26.4.dev14
3
+ Version: 1.27.1
4
4
  Summary: A TIFF tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -0,0 +1,6 @@
1
+ large-image>=1.27.1
2
+ pylibtiff
3
+ tifftools>=1.2.0
4
+
5
+ [girder]
6
+ girder-large-image>=1.27.1
@@ -1,6 +0,0 @@
1
- large-image>=1.26.4.dev14
2
- pylibtiff
3
- tifftools>=1.2.0
4
-
5
- [girder]
6
- girder-large-image>=1.26.4.dev14