def __process_tilelevel0(self, media_id): """Create the (0,0,0) tile, and save it to the TileStore using the media indentifier media_id. __process_tilelevel0(string) -> None Precondition: tile_id is valid """ self.__process_tilelevel1((media_id, 1, 0, 0)) self.__process_tilelevel1((media_id, 1, 0, 1)) tile0 = Image.open(TileStore.get_tile_path( (media_id, 1, 0, 0), filext=self.filext)) \ .resize((128,128), Image.BILINEAR) tile1 = Image.open(TileStore.get_tile_path( (media_id, 1, 0, 1), filext=self.filext)) \ .resize((128,128), Image.BILINEAR) tile = Image.new('RGB', (256,128)) tile.paste(tile0, (0, 0, 128, 128)) tile.paste(tile1, (128, 0, 256, 128)) filename = TileStore.get_tile_path( (media_id, 0, 0, 0), True, filext=self.filext) tile.save(filename)
def __process_tilelevel1(self, tile_id): """Create the tile identified by tile_id by merging the four sub-tiles and resizing to 256x256, and save it to the TileStore. __process_tilelevel1(tuple<string,int,int,int>) -> None Precondition: the tilelevel component of tile_id is 1 Precondition: tile_id is valid """ media_id, tilelevel, row, col = tile_id self.__process_big_tile((media_id, 1, 0, col)) tile00 = Image.open(TileStore.get_tile_path( (media_id, 2, 0, 0 + col*2), filext=self.filext)) \ .resize((128,128), Image.BILINEAR) tile01 = Image.open(TileStore.get_tile_path( (media_id, 2, 0, 1 + col*2), filext=self.filext)) \ .resize((128,128), Image.BILINEAR) tile10 = Image.open(TileStore.get_tile_path( (media_id, 2, 1, 0 + col*2), filext=self.filext)) \ .resize((128,128), Image.BILINEAR) tile11 = Image.open(TileStore.get_tile_path( (media_id, 2, 1, 1 + col*2), filext=self.filext)) \ .resize((128,128), Image.BILINEAR) tile = Image.new('RGB', (256,256)) tile.paste(tile00, (0, 0, 128, 128)) tile.paste(tile01, (128, 0, 256, 128)) tile.paste(tile10, (0, 128, 128, 256)) tile.paste(tile11, (128, 128, 256, 256)) filename = TileStore.get_tile_path( tile_id, True, filext=self.filext) tile.save(filename)
def __savetile(self, tile, tilelevel, row, col): """Save the given tile to disk. __save(Tile, int, int, int) -> None """ tile_id = (self.__media_id, tilelevel, row, col) filename = TileStore.get_tile_path( tile_id, True, self.__outpath, self.__filext) tile.save(filename) self.__progress += 1.0/self.__numtiles self.__logger.info("%3d%% tiled", int(self.__progress*100))
def _load(self, tile_id): filename = TileStore.get_tile_path( tile_id, True, filext=self.filext) if not os.path.exists(filename): ## tile has not been retrieved yet self._load_dynamic(tile_id, filename) try: return QtGui.QImage(filename) except Exception: self._logger.exception("error loading tile, " "assuming it is unavailable") return None
def _load(self, tile_id): media_id, tilelevel, row, col = tile_id maxtilelevel = TileStore.get_metadata(media_id, 'maxtilelevel') if tilelevel > maxtilelevel: return None filename = TileStore.get_tile_path(tile_id) try: tile = Image.open(filename) tile.load() return tile except IOError: return None
Precondition: tile_id is valid """ media_id, tilelevel, row, col = big_tile_id tmpfile = self.__download(big_tile_id) try: big_tile = Image.open(tmpfile) except Exception, e: self._logger.exception("unable to load %s" % tmpfile) else: for x in [0,1]: for y in [0,1]: tile= big_tile.crop((x*256, y*256, (x+1)*256, (y+1)*256)) tile_id = (media_id, tilelevel+1, row*2 + y, col*2 + x) filename = TileStore.get_tile_path( tile_id, True, filext=self.filext) tile.save(filename) try: os.unlink(tmpfile) except: self._logger.exception("unable to unlink temporary file " "'%s'" % tmpfile) def __process_tilelevel1(self, tile_id): """Create the tile identified by tile_id by merging the four sub-tiles and resizing to 256x256, and save it to the TileStore. __process_tilelevel1(tuple<string,int,int,int>) -> None