示例#1
0
 def test_one_point(self):
     img = Image.new('RGB', (100, 100), color='#ff0000')
     draw = ImageDraw.Draw(img)
     draw.point((99, 99))
     del draw
     
     assert not is_single_color_image(img)
示例#2
0
 def test_solid_paletted_image(self):
     img = Image.new('P', (100, 100), color=20)
     palette = []
     for i in range(256):
         palette.extend((i, i//2, i%3))
     img.putpalette(palette)
     eq_(is_single_color_image(img), (20, 10, 2))
示例#3
0
 def test_solid_paletted_image(self):
     img = Image.new("P", (100, 100), color=20)
     palette = []
     for i in range(256):
         palette.extend((i, i // 2, i % 3))
     img.putpalette(palette)
     assert is_single_color_image(img) == (20, 10, 2)
示例#4
0
    def set_tile(self, tile):
        x, y, z = tile.coord
        assert self.grid[0] <= x < self.grid[2]
        assert self.grid[1] <= y < self.grid[3]


        color = is_single_color_image(tile.source.as_image())

        with tile_buffer(tile) as buf:
            _data = buffer(buf.read())

        if color:
            data = None
            _color = ''.join('%02x' % v for v in color)
            self.unique_tiles.set_data(_data, _color)
        else:
            #get value of cStringIO-Object and store it to a buffer
            data = _data
            _color = None

        timestamp = int(time.time())
        cursor = self.db.cursor()
        stmt = "INSERT INTO %s (x, y, data, date_added, unique_tile) VALUES (?,?,?,?,?)" % (self.table_name)
        try:
            cursor.execute(stmt, (x, y, data, timestamp, _color))
        except (sqlite3.IntegrityError, sqlite3.OperationalError) as e:
            #tile is already present, updating data
            stmt = "UPDATE %s SET data = ?, date_added = ?, unique_tile = ? WHERE x = ? AND y = ?" % (self.table_name)
            try:
                cursor.execute(stmt, (data, timestamp, _color, x, y))
            except sqlite3.OperationalError as e:
                #database is locked
                print(e)
                return False
        return True
示例#5
0
    def test_one_point(self):
        img = Image.new("RGB", (100, 100), color="#ff0000")
        draw = ImageDraw.Draw(img)
        draw.point((99, 99))
        del draw

        assert not is_single_color_image(img)
示例#6
0
文件: file.py 项目: vartagg/mapproxy
    def store_tile(self, tile):
        """
        Add the given `tile` to the file cache. Stores the `Tile.source` to
        `FileCache.tile_location`.
        """
        if tile.stored:
            return

        tile_loc = self.tile_location(tile, create_dir=True)

        if self.link_single_color_images:
            color = is_single_color_image(tile.source.as_image())
            if color:
                self._store_single_color_tile(tile, tile_loc, color)
            else:
                self._store(tile, tile_loc)
        else:
            self._store(tile, tile_loc)
示例#7
0
 def store_tile(self, tile):
     """
     Add the given `tile` to the file cache. Stores the `Tile.source` to
     `FileCache.tile_location`.
     """
     if tile.stored:
         return
     
     tile_loc = self.tile_location(tile, create_dir=True)
     
     if self.link_single_color_images:
         color = is_single_color_image(tile.source.as_image())
         if color:
             self._store_single_color_tile(tile, tile_loc, color)
         else:
             self._store(tile, tile_loc)
     else:
         self._store(tile, tile_loc)
示例#8
0
    def set_tile(self, tile):
        x, y, z = tile.coord
        assert self.grid[0] <= x < self.grid[2]
        assert self.grid[1] <= y < self.grid[3]

        color = is_single_color_image(tile.source.as_image())

        with tile_buffer(tile) as buf:
            _data = buffer(buf.read())

        if color:
            data = None
            _color = ''.join('%02x' % v for v in color)
            self.unique_tiles.set_data(_data, _color)
        else:
            #get value of cStringIO-Object and store it to a buffer
            data = _data
            _color = None

        timestamp = int(time.time())
        cursor = self.db.cursor()
        stmt = "INSERT INTO %s (x, y, data, date_added, unique_tile) VALUES (?,?,?,?,?)" % (
            self.table_name)
        try:
            cursor.execute(stmt, (x, y, data, timestamp, _color))
        except (sqlite3.IntegrityError, sqlite3.OperationalError) as e:
            #tile is already present, updating data
            stmt = "UPDATE %s SET data = ?, date_added = ?, unique_tile = ? WHERE x = ? AND y = ?" % (
                self.table_name)
            try:
                cursor.execute(stmt, (data, timestamp, _color, x, y))
            except sqlite3.OperationalError as e:
                #database is locked
                print(e)
                return False
        return True
示例#9
0
 def test_solid_w_alpha(self):
     img = Image.new('RGBA', (100, 100), color='#ff0102')
     eq_(is_single_color_image(img), (255, 1, 2, 255))
示例#10
0
 def test_solid(self):
     img = Image.new('RGB', (100, 100), color='#ff0102')
     eq_(is_single_color_image(img), (255, 1, 2))
示例#11
0
 def test_solid_w_alpha(self):
     img = Image.new("RGBA", (100, 100), color="#ff0102")
     assert is_single_color_image(img) == (255, 1, 2, 255)
示例#12
0
 def test_solid_w_alpha(self):
     img = Image.new('RGBA', (100, 100), color='#ff0102')
     eq_(is_single_color_image(img), (255, 1, 2, 255))
示例#13
0
 def test_solid(self):
     img = Image.new('RGB', (100, 100), color='#ff0102')
     eq_(is_single_color_image(img), (255, 1, 2))