Esempio n. 1
0
 def get_tile(self, level, column, row, original_file_source=False, file_mimetype=None):
     cache = CacheDriverFactory().get_cache('openslide')
     cache_params = {
         'image_id': self.image_id,
         'level': level,
         'column': column,
         'row': row,
         'tile_size': settings.DEEPZOOM_TILE_SIZE,
         'image_format': settings.DEEPZOOM_FORMAT
     }
     if cache_params['image_format'].lower() == 'jpeg':
         cache_params['image_quality'] = settings.DEEPZOOM_JPEG_QUALITY
     # get tile from cache
     tile = cache.tile_from_cache(**cache_params)
     # if tile is not in cache build id ...
     if tile is None:
         slide = self._get_deepzoom_wrapper(original_file_source, file_mimetype)
         if slide:
             dzi_tile = slide.get_tile(level, (column, row))
             tile_buffer = StringIO()
             tile_conf = {
                 'format': settings.DEEPZOOM_FORMAT
             }
             if tile_conf['format'].lower() == 'jpeg':
                 tile_conf['quality'] = settings.DEEPZOOM_JPEG_QUALITY
             dzi_tile.save(tile_buffer, **tile_conf)
             tile = Image.open(tile_buffer)
             # ... and store it into the cache
             cache_params['image_obj'] = tile
             cache.tile_to_cache(**cache_params)
     return tile, settings.DEEPZOOM_FORMAT
Esempio n. 2
0
 def get_tile(self, level, column, row, original_file_source=False, file_mimetype=None):
     self._check_source_type(original_file_source)
     cache = CacheDriverFactory().get_cache('omero')
     cache_params = {
         'image_id': self.image_id,
         'level': level,
         'column': column,
         'row': row,
         'tile_size': settings.DEEPZOOM_TILE_SIZE,
         'image_format': settings.DEEPZOOM_FORMAT
     }
     if cache_params['image_format'].lower() == 'jpeg':
         cache_params['image_quality'] = settings.DEEPZOOM_JPEG_QUALITY
     tile = cache.tile_from_cache(**cache_params)
     if tile is None:
         ome_img = self._get_image_object()
         ome_level = self._get_best_downscale_level(level, ome_img)
         tile = self._get_ome_tile(ome_img, ome_level, level, row=column, column=row)
         cache_params['image_obj'] = tile
         cache.tile_to_cache(**cache_params)
     return tile, settings.DEEPZOOM_FORMAT