large-image-source-openjpeg 1.27.5.dev6__py3-none-any.whl → 1.30.7.dev12__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,6 @@ from importlib.metadata import PackageNotFoundError
25
25
  from importlib.metadata import version as _importlib_version
26
26
  from xml.etree import ElementTree
27
27
 
28
- import glymur
29
28
  import PIL.Image
30
29
 
31
30
  import large_image
@@ -41,6 +40,23 @@ except PackageNotFoundError:
41
40
  # package is not installed
42
41
  pass
43
42
 
43
+ glymur = None
44
+
45
+
46
+ def _lazyImport():
47
+ """
48
+ Import the glymur module. This is done when needed rather than in the module
49
+ initialization because it is slow.
50
+ """
51
+ global glymur
52
+
53
+ if glymur is None:
54
+ try:
55
+ import glymur
56
+ except ImportError:
57
+ msg = 'glymur module not found.'
58
+ raise TileSourceError(msg)
59
+
44
60
 
45
61
  warnings.filterwarnings('ignore', category=UserWarning, module='glymur')
46
62
 
@@ -57,11 +73,13 @@ class OpenjpegFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
57
73
  None: SourcePriority.MEDIUM,
58
74
  'jp2': SourcePriority.PREFERRED,
59
75
  'jpf': SourcePriority.PREFERRED,
76
+ 'j2c': SourcePriority.PREFERRED,
60
77
  'j2k': SourcePriority.PREFERRED,
61
78
  'jpx': SourcePriority.PREFERRED,
62
79
  }
63
80
  mimeTypes = {
64
81
  None: SourcePriority.FALLBACK,
82
+ 'image/j2c': SourcePriority.PREFERRED,
65
83
  'image/jp2': SourcePriority.PREFERRED,
66
84
  'image/jpx': SourcePriority.PREFERRED,
67
85
  }
@@ -88,6 +106,7 @@ class OpenjpegFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
88
106
  """
89
107
  super().__init__(path, **kwargs)
90
108
 
109
+ _lazyImport()
91
110
  self._largeImagePath = str(self._getLargeImagePath())
92
111
  self._pixelInfo = {}
93
112
  try:
@@ -97,14 +116,14 @@ class OpenjpegFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
97
116
  raise FileNotFoundError
98
117
  msg = 'File cannot be opened via Glymur and OpenJPEG (no shape).'
99
118
  raise TileSourceError(msg)
100
- except (glymur.jp2box.InvalidJp2kError, struct.error):
119
+ except (glymur.jp2box.InvalidJp2kError, struct.error, IndexError):
101
120
  msg = 'File cannot be opened via Glymur and OpenJPEG.'
102
121
  raise TileSourceError(msg)
103
122
  except FileNotFoundError:
104
123
  if not os.path.isfile(self._largeImagePath):
105
124
  raise TileSourceFileNotFoundError(self._largeImagePath) from None
106
125
  raise
107
- glymur.set_option('lib.num_threads', large_image.tilesource.utilities.cpu_count())
126
+ glymur.set_option('lib.num_threads', large_image.config.cpu_count())
108
127
  self._openjpegHandles = queue.LifoQueue()
109
128
  for _ in range(self._maxOpenHandles - 1):
110
129
  self._openjpegHandles.put(None)
@@ -113,7 +132,11 @@ class OpenjpegFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
113
132
  self.sizeY, self.sizeX = self._openjpeg.shape[:2]
114
133
  except IndexError as exc:
115
134
  raise TileSourceError('File cannot be opened via Glymur and OpenJPEG: %r' % exc)
116
- self.levels = int(self._openjpeg.codestream.segment[2].num_res) + 1
135
+ try:
136
+ self.levels = int(self._openjpeg.codestream.segment[2].num_res) + 1
137
+ except Exception:
138
+ msg = 'File cannot be opened via Glymur and OpenJPEG.'
139
+ raise TileSourceError(msg)
117
140
  self._minlevel = 0
118
141
  self.tileWidth = self.tileHeight = 2 ** int(math.ceil(max(
119
142
  math.log(float(self.sizeX)) / math.log(2) - self.levels + 1,
@@ -228,7 +251,7 @@ class OpenjpegFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
228
251
 
229
252
  def _readbox(self, box):
230
253
  if box.length > 16 * 1024 * 1024:
231
- return
254
+ return None
232
255
  try:
233
256
  fp = builtins.open(self._largeImagePath, 'rb')
234
257
  headerLength = 16
@@ -256,7 +279,7 @@ class OpenjpegFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
256
279
  x0, y0, x1, y1, step = self._xyzToCorners(x, y, z)
257
280
  scale = None
258
281
  if self._minlevel - z > self._maxSkippedLevels:
259
- tile = self._getTileFromEmptyLevel(x, y, z, **kwargs)
282
+ tile, _format = self._getTileFromEmptyLevel(x, y, z, **kwargs)
260
283
  tile = _imageToNumpy(tile)[0]
261
284
  else:
262
285
  if z < self._minlevel:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: large-image-source-openjpeg
3
- Version: 1.27.5.dev6
3
+ Version: 1.30.7.dev12
4
4
  Summary: An Openjpeg tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -15,12 +15,26 @@ Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
18
19
  Requires-Python: >=3.8
20
+ Description-Content-Type: text/x-rst
19
21
  License-File: LICENSE
20
- Requires-Dist: large-image >=1.27.5.dev6
21
- Requires-Dist: glymur >=0.8.18
22
+ Requires-Dist: large-image>=1.30.7.dev12
23
+ Requires-Dist: glymur>=0.8.18
22
24
  Provides-Extra: girder
23
- Requires-Dist: girder-large-image >=1.27.5.dev6 ; extra == 'girder'
25
+ Requires-Dist: girder-large-image>=1.30.7.dev12; extra == "girder"
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: keywords
33
+ Dynamic: license
34
+ Dynamic: provides-extra
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
24
38
 
25
39
  An Openjpeg tilesource for large_image.
26
40
 
@@ -0,0 +1,8 @@
1
+ large_image_source_openjpeg/__init__.py,sha256=Dv7pT3AieJqrAVP95aOkC8chDwoXc5z5Kx4Fp1rJIJI,11712
2
+ large_image_source_openjpeg/girder_source.py,sha256=Ve15utmsZ_CJrDXIAQD2ea2yHybE1vuWbbPJMeXQCMI,1246
3
+ large_image_source_openjpeg-1.30.7.dev12.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
4
+ large_image_source_openjpeg-1.30.7.dev12.dist-info/METADATA,sha256=vnNeIpi3aqsGbYY_XjPobyJViFAtUk6uRsbHlSDFWxk,1361
5
+ large_image_source_openjpeg-1.30.7.dev12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
+ large_image_source_openjpeg-1.30.7.dev12.dist-info/entry_points.txt,sha256=lTM4P2JqjANt_gPtcbMYTJVCmfPts_VxB8bQyfhryjI,190
7
+ large_image_source_openjpeg-1.30.7.dev12.dist-info/top_level.txt,sha256=y6bw5gBWfdaFWXtjiCH0vaHRtP8WNBhq8ugIKnwzEL0,28
8
+ large_image_source_openjpeg-1.30.7.dev12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- large_image_source_openjpeg/__init__.py,sha256=5JzJZcosfZsYLybE2QhlcTe2w3s8qI5Cng6ibx8oHRk,11089
2
- large_image_source_openjpeg/girder_source.py,sha256=Ve15utmsZ_CJrDXIAQD2ea2yHybE1vuWbbPJMeXQCMI,1246
3
- large_image_source_openjpeg-1.27.5.dev6.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
4
- large_image_source_openjpeg-1.27.5.dev6.dist-info/METADATA,sha256=64rfF5UqmwM-URmSwRE40AM48Lnv_jRjIYMzvvtaYeM,1018
5
- large_image_source_openjpeg-1.27.5.dev6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- large_image_source_openjpeg-1.27.5.dev6.dist-info/entry_points.txt,sha256=lTM4P2JqjANt_gPtcbMYTJVCmfPts_VxB8bQyfhryjI,190
7
- large_image_source_openjpeg-1.27.5.dev6.dist-info/top_level.txt,sha256=y6bw5gBWfdaFWXtjiCH0vaHRtP8WNBhq8ugIKnwzEL0,28
8
- large_image_source_openjpeg-1.27.5.dev6.dist-info/RECORD,,