@@ -160,6 +160,57 @@ def get_thumbnail(self, size):
160160 return thumb
161161
162162
163+ class _OpenSlideMap (Mapping ):
164+ def __init__ (self , osr ):
165+ self ._osr = osr
166+
167+ def __repr__ (self ):
168+ return f'<{ self .__class__ .__name__ } { dict (self )!r} >'
169+
170+ def __len__ (self ):
171+ return len (self ._keys ())
172+
173+ def __iter__ (self ):
174+ return iter (self ._keys ())
175+
176+ def _keys (self ):
177+ # Private method; always returns list.
178+ raise NotImplementedError ()
179+
180+
181+ class _PropertyMap (_OpenSlideMap ):
182+ def _keys (self ):
183+ return lowlevel .get_property_names (self ._osr )
184+
185+ def __getitem__ (self , key ):
186+ v = lowlevel .get_property_value (self ._osr , key )
187+ if v is None :
188+ raise KeyError ()
189+ return v
190+
191+
192+ class _AssociatedImageMap (_OpenSlideMap ):
193+ def __init__ (self , osr , profile ):
194+ _OpenSlideMap .__init__ (self , osr )
195+ self ._profile = profile
196+
197+ def _keys (self ):
198+ return lowlevel .get_associated_image_names (self ._osr )
199+
200+ def __getitem__ (self , key ):
201+ if key not in self ._keys ():
202+ raise KeyError ()
203+ image = lowlevel .read_associated_image (self ._osr , key )
204+ if lowlevel .read_associated_image_icc_profile .available :
205+ profile = lowlevel .read_associated_image_icc_profile (self ._osr , key )
206+ if profile == self ._profile :
207+ # reuse profile copy from main image to save memory
208+ profile = self ._profile
209+ if profile is not None :
210+ image .info ['icc_profile' ] = profile
211+ return image
212+
213+
163214class OpenSlide (AbstractSlide ):
164215 """An open whole-slide image.
165216
@@ -267,58 +318,6 @@ def set_cache(self, cache):
267318 raise TypeError ('Not a cache object' )
268319 lowlevel .set_cache (self ._osr , llcache )
269320
270-
271- class _OpenSlideMap (Mapping ):
272- def __init__ (self , osr ):
273- self ._osr = osr
274-
275- def __repr__ (self ):
276- return f'<{ self .__class__ .__name__ } { dict (self )!r} >'
277-
278- def __len__ (self ):
279- return len (self ._keys ())
280-
281- def __iter__ (self ):
282- return iter (self ._keys ())
283-
284- def _keys (self ):
285- # Private method; always returns list.
286- raise NotImplementedError ()
287-
288-
289- class _PropertyMap (_OpenSlideMap ):
290- def _keys (self ):
291- return lowlevel .get_property_names (self ._osr )
292-
293- def __getitem__ (self , key ):
294- v = lowlevel .get_property_value (self ._osr , key )
295- if v is None :
296- raise KeyError ()
297- return v
298-
299-
300- class _AssociatedImageMap (_OpenSlideMap ):
301- def __init__ (self , osr , profile ):
302- _OpenSlideMap .__init__ (self , osr )
303- self ._profile = profile
304-
305- def _keys (self ):
306- return lowlevel .get_associated_image_names (self ._osr )
307-
308- def __getitem__ (self , key ):
309- if key not in self ._keys ():
310- raise KeyError ()
311- image = lowlevel .read_associated_image (self ._osr , key )
312- if lowlevel .read_associated_image_icc_profile .available :
313- profile = lowlevel .read_associated_image_icc_profile (self ._osr , key )
314- if profile == self ._profile :
315- # reuse profile copy from main image to save memory
316- profile = self ._profile
317- if profile is not None :
318- image .info ['icc_profile' ] = profile
319- return image
320-
321-
322321class OpenSlideCache :
323322 """An in-memory tile cache.
324323
0 commit comments