def getFrameAt(self, index):
        if self.fImages.get(index, False) is not False:
            return self.fImages[index]

        rb = self.imageInfo.minRowBytes()
        bmap = skia.Bitmap()
        bmap.allocPixels(self.imageInfo)

        reqFrame = self.fInfos[index].fRequiredFrame

        opts = skia.Codec.Options()
        opts.fFrameIndex = index
        opts.fPriorFrame = reqFrame if reqFrame != index - 1 else skia.Codec.kNoFrame

        if reqFrame != skia.Codec.kNoFrame:
            pmap = skia.Pixmap()
            if self.fImages.get(reqFrame, False):
                self.fImages.get(reqFrame).readPixels(pmap, 0, 0)
            bmap.writePixels(pmap)

        result = self.decGif.getPixels(self.imageInfo, bmap.getPixels(),
                                       bmap.rowBytes(), opts)

        if result == skia.Codec.Result.kSuccess:
            self.fImages[index] = skia.Image.MakeFromBitmap(bmap)
            return self.fImages[index]
        return False
예제 #2
0
def test_Bitmap_array_interface(color_type, shape, dtype):
    from PIL import Image
    bitmap = skia.Bitmap()
    bitmap.allocPixels(
        skia.ImageInfo.Make(16, 32, color_type, skia.kUnpremul_AlphaType))
    assert not bitmap.isNull()
    assert isinstance(Image.fromarray(bitmap), Image.Image)
예제 #3
0
	def getFrameAt(self,index):
		if self.fImages.get(index,False) != False:
			return self.fImages[index]

		rb = self.imageInfo.minRowBytes()
        #Carefull with the lifetime of this
		bmap = skia.Bitmap()
		bmap.allocPixels(self.imageInfo)

		opts = skia.Codec.Options()
		opts.fFrameIndex = index
		reqFrame = self.fInfos[index].fRequiredFrame

		if reqFrame != skia.Codec.kNoFrame:
			#copy image data from required frame
			pmap = skia.Pixmap()
			self.fImages[reqFrame].readPixels(pmap,0,0)
			bmap.installPixels(pmap)
			
		
		result = self.decGif.getPixels(self.imageInfo,bmap.getPixels(),bmap.rowBytes(),opts)

		if result == skia.Codec.Result.kSuccess:
			self.fImages[index] = skia.Image.MakeFromBitmap(bmap)
			return self.fImages[index]
		return False
예제 #4
0
def test_Bitmap_buffer_shape_dtype(color_type, shape, dtype):
    bitmap = skia.Bitmap()
    bitmap.allocPixels(
        skia.ImageInfo.Make(16, 32, color_type, skia.kUnpremul_AlphaType))
    assert not bitmap.isNull()
    array = np.array(bitmap, copy=False)
    assert array.shape == shape
    assert array.dtype == dtype
    def loadStaticFrame(self):
        if self.fImages.get(0, False) is not False:
            return self.fImages[0]

        rb = self.imageInfo.minRowBytes()
        bmap = skia.Bitmap()
        bmap.allocPixels(self.imageInfo)
        result = self.decGif.getPixels(self.imageInfo, bmap.getPixels(),
                                       bmap.rowBytes())
        if result == skia.Codec.Result.kSuccess:
            self.fImages[0] = skia.Image.MakeFromBitmap(bmap)
            return self.fImages[0]
        return False
예제 #6
0
def test_Bitmap_init(args):
    assert isinstance(skia.Bitmap(*args), skia.Bitmap)
예제 #7
0
def test_Bitmap_extractAlpha(bitmap):
    dst = skia.Bitmap()
    assert isinstance(bitmap.extractAlpha(dst), bool)
예제 #8
0
def test_Bitmap_extractSubset(bitmap):
    dst = skia.Bitmap()
    assert isinstance(bitmap.extractSubset(dst, skia.IRect(50, 50)), bool)
예제 #9
0
def test_Bitmap_allocN32Pixels():
    bitmap = skia.Bitmap()
예제 #10
0
def test_Bitmap_tryAllocN32Pixels():
    bitmap = skia.Bitmap()
    assert isinstance(bitmap.tryAllocN32Pixels(100, 100, True), bool)
예제 #11
0
def test_Bitmap_allocPixelsFlags(info):
    bitmap = skia.Bitmap()
    bitmap.allocPixelsFlags(info, skia.Bitmap.kZeroPixels_AllocFlag)
예제 #12
0
def test_Bitmap_tryAllocPixelsFlags(info):
    bitmap = skia.Bitmap()
    assert isinstance(
        bitmap.tryAllocPixelsFlags(info, skia.Bitmap.kZeroPixels_AllocFlag),
        bool)
예제 #13
0
def bitmap(info):
    bitmap = skia.Bitmap()
    bitmap.allocPixels(info)
    return bitmap
예제 #14
0
def test_Image_asLegacyBitmap(image):
    bitmap = skia.Bitmap()
    assert isinstance(image.asLegacyBitmap(bitmap), bool)
예제 #15
0
def bitmap():
    yield skia.Bitmap()
예제 #16
0
def bitmap(info):
    bitmap = skia.Bitmap()
    bitmap.allocPixels(info)
    assert not bitmap.isNull()
    yield bitmap
예제 #17
0
        32,
        16,
    ), np.uint16),
])
def test_Bitmap_array_interface(color_type, shape, dtype):
    from PIL import Image
    bitmap = skia.Bitmap()
    bitmap.allocPixels(
        skia.ImageInfo.Make(16, 32, color_type, skia.kUnpremul_AlphaType))
    assert not bitmap.isNull()
    assert isinstance(Image.fromarray(bitmap), Image.Image)


@pytest.mark.parametrize('args', [
    tuple(),
    (skia.Bitmap(), ),
])
def test_Bitmap_init(args):
    assert isinstance(skia.Bitmap(*args), skia.Bitmap)


def test_Bitmap_swap(bitmap):
    other = skia.Bitmap()
    bitmap.swap(other)


def test_Bitmap_pixmap(bitmap):
    assert isinstance(bitmap.pixmap(), skia.Pixmap)


def test_Bitmap_info(bitmap):
예제 #18
0
def test_Surface_peekPixels(surface):
    assert isinstance(surface.peekPixels(skia.Pixmap()), bool)


@pytest.mark.parametrize('args', [
    (skia.Pixmap(), 0, 0),
    (
        skia.ImageInfo.MakeN32Premul(320, 240),
        bytearray(240 * 320 * 4),
        320 * 4,
    ),
    (
        skia.ImageInfo.MakeN32Premul(320, 240),
        np.zeros((240, 320, 4), dtype=np.uint8),
    ),
    (skia.Bitmap(), 0, 0),
])
def test_Surface_readPixels(surface, args):
    assert isinstance(surface.readPixels(*args), bool)


def test_Surface_asyncRescaleAndReadPixels(surface):
    info = skia.ImageInfo.MakeN32Premul(100, 100)
    def assert_result(result):
        assert isinstance(result, (type(None), skia.Surface.AsyncReadResult))
    surface.asyncRescaleAndReadPixels(
        info, (100, 100), skia.Surface.RescaleGamma.kSrc,
        skia.kNone_FilterQuality, assert_result)
    surface.flushAndSubmit()

예제 #19
0
def test_Image_MakeFromBitmap():
    bitmap = skia.Bitmap()
    bitmap.allocPixels(skia.ImageInfo().MakeN32Premul(100, 100))
    assert isinstance(skia.Image.MakeFromBitmap(bitmap), skia.Image)
예제 #20
0
def test_Bitmap_swap(bitmap):
    other = skia.Bitmap()
    bitmap.swap(other)