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
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)
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
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
def test_Bitmap_init(args): assert isinstance(skia.Bitmap(*args), skia.Bitmap)
def test_Bitmap_extractAlpha(bitmap): dst = skia.Bitmap() assert isinstance(bitmap.extractAlpha(dst), bool)
def test_Bitmap_extractSubset(bitmap): dst = skia.Bitmap() assert isinstance(bitmap.extractSubset(dst, skia.IRect(50, 50)), bool)
def test_Bitmap_allocN32Pixels(): bitmap = skia.Bitmap()
def test_Bitmap_tryAllocN32Pixels(): bitmap = skia.Bitmap() assert isinstance(bitmap.tryAllocN32Pixels(100, 100, True), bool)
def test_Bitmap_allocPixelsFlags(info): bitmap = skia.Bitmap() bitmap.allocPixelsFlags(info, skia.Bitmap.kZeroPixels_AllocFlag)
def test_Bitmap_tryAllocPixelsFlags(info): bitmap = skia.Bitmap() assert isinstance( bitmap.tryAllocPixelsFlags(info, skia.Bitmap.kZeroPixels_AllocFlag), bool)
def bitmap(info): bitmap = skia.Bitmap() bitmap.allocPixels(info) return bitmap
def test_Image_asLegacyBitmap(image): bitmap = skia.Bitmap() assert isinstance(image.asLegacyBitmap(bitmap), bool)
def bitmap(): yield skia.Bitmap()
def bitmap(info): bitmap = skia.Bitmap() bitmap.allocPixels(info) assert not bitmap.isNull() yield bitmap
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):
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()
def test_Image_MakeFromBitmap(): bitmap = skia.Bitmap() bitmap.allocPixels(skia.ImageInfo().MakeN32Premul(100, 100)) assert isinstance(skia.Image.MakeFromBitmap(bitmap), skia.Image)
def test_Bitmap_swap(bitmap): other = skia.Bitmap() bitmap.swap(other)