From e6e6addd2e22fd1b01cb261bd5c79160b06b7b95 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Mon, 1 Apr 2024 14:57:56 +0200 Subject: [PATCH] =?UTF-8?q?fix(=F0=9F=95=B8=EF=B8=8F):=20make=20makeNonTex?= =?UTF-8?q?tureImage=20substantially=20faster=20on=20web=20(#2326)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/src/skia/web/JsiSkImage.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/package/src/skia/web/JsiSkImage.ts b/package/src/skia/web/JsiSkImage.ts index eb5e3e6c52..76c307aed1 100644 --- a/package/src/skia/web/JsiSkImage.ts +++ b/package/src/skia/web/JsiSkImage.ts @@ -151,9 +151,20 @@ export class JsiSkImage extends HostObject implements SkImage { }; makeNonTextureImage(): SkImage { - return new JsiSkImage( - this.CanvasKit, - this.CanvasKit.MakeImageFromEncoded(this.encodeToBytes())! - ); + const partialInfo = this.ref.getImageInfo(); + const colorSpace = this.ref.getColorSpace(); + const info = { + ...partialInfo, + colorSpace, + }; + const pixels = this.ref.readPixels(0, 0, info) as Uint8Array | null; + if (!pixels) { + throw new Error("Could not create image from bytes"); + } + const img = this.CanvasKit.MakeImage(info, pixels, info.width * 4); + if (!img) { + throw new Error("Could not create image from bytes"); + } + return new JsiSkImage(this.CanvasKit, img); } }