Skip to content

Commit

Permalink
fix(🕸️): make makeNonTextureImage substantially faster on web (#2326)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Apr 1, 2024
1 parent eda4900 commit e6e6add
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions package/src/skia/web/JsiSkImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,20 @@ export class JsiSkImage extends HostObject<Image, "Image"> 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);
}
}

0 comments on commit e6e6add

Please sign in to comment.