Beispiel #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
Beispiel #2
0
 def get_thumbnail(self, size, original_file_source=False, file_mimeype=None):
     cache = CacheDriverFactory().get_cache('openslide')
     # get thumbnail from cache
     thumb = cache.thumbnail_from_cache(self.image_id, size,
                                        settings.DEEPZOOM_FORMAT)
     # if thumbnail is not in cache build it ....
     if thumb is None:
         self.logger.info('No thumbnail loaded from cache, building it')
         slide = self._get_openslide_wrapper(original_file_source, file_mimeype)
         if slide:
             thumb = slide.get_thumbnail((size, size))
             # ... and store it into the cache
             cache.thumbnail_to_cache(self.image_id, thumb, size,
                                      settings.DEEPZOOM_FORMAT)
     else:
         self.logger.info('Thumbnail loaded from cache')
     return thumb, settings.DEEPZOOM_FORMAT
Beispiel #3
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
Beispiel #4
0
 def get_thumbnail(self, size, original_file_source=False, file_mimeype=None):
     self._check_source_type(original_file_source)
     cache = CacheDriverFactory().get_cache('omero')
     thumbnail = cache.thumbnail_from_cache(self.image_id, size,
                                            settings.DEEPZOOM_FORMAT)
     if thumbnail is None:
         self.logger.info('No thumbnail loaded from cache, building it')
         # we want the thumbnail of the image, not the one of the highest resolution image in fileset
         ome_img = self._get_image_object(get_biggest_in_fileset=False)
         if ome_img:
             if ome_img.getSizeX() >= ome_img.getSizeY():
                 th_size = (size, )
             else:
                 th_w = size * (float(ome_img.getSizeX()) / ome_img.getSizeY())
                 th_size = (th_w, size)
             thumbnail_buffer = StringIO(ome_img.getThumbnail(size=th_size))
             thumbnail = Image.open(thumbnail_buffer)
             cache.thumbnail_to_cache(self.image_id, thumbnail, size,
                                      settings.DEEPZOOM_FORMAT)
     else:
         self.logger.info('Thumbnail loaded from cache')
     return thumbnail, settings.DEEPZOOM_FORMAT