@shopify/react-native-skia 0.1.220 → 0.1.222
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -0
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -0
- package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +0 -1
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +46 -6
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +3 -3
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +8 -14
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +93 -105
- package/cpp/api/JsiSkCanvas.h +38 -1
- package/cpp/api/JsiSkImage.h +66 -1
- package/cpp/api/JsiSkImageInfo.h +19 -0
- package/cpp/utils/RNSkLog.h +3 -3
- package/cpp/utils/RNSkTypedArray.h +41 -0
- package/lib/commonjs/skia/types/Canvas.d.ts +9 -1
- package/lib/commonjs/skia/types/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Image/Image.d.ts +13 -0
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +14 -11
- package/lib/commonjs/skia/types/Image/ImageFactory.js +14 -11
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/Host.d.ts +2 -1
- package/lib/commonjs/skia/web/Host.js +10 -1
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +2 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.js +11 -0
- package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +1 -3
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.d.ts +3 -1
- package/lib/commonjs/skia/web/JsiSkImage.js +22 -0
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js +0 -4
- package/lib/commonjs/skia/web/JsiSkTypefaceFontProvider.js.map +1 -1
- package/lib/module/skia/types/Canvas.d.ts +9 -1
- package/lib/module/skia/types/Canvas.js.map +1 -1
- package/lib/module/skia/types/Image/Image.d.ts +13 -0
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +14 -11
- package/lib/module/skia/types/Image/ImageFactory.js +14 -11
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/web/Host.d.ts +2 -1
- package/lib/module/skia/web/Host.js +6 -0
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkCanvas.d.ts +2 -1
- package/lib/module/skia/web/JsiSkCanvas.js +12 -1
- package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +1 -3
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.d.ts +3 -1
- package/lib/module/skia/web/JsiSkImage.js +25 -1
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.d.ts +2 -2
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.js +0 -4
- package/lib/module/skia/web/JsiSkTypefaceFontProvider.js.map +1 -1
- package/lib/typescript/src/skia/types/Canvas.d.ts +9 -1
- package/lib/typescript/src/skia/types/Image/Image.d.ts +13 -0
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +14 -11
- package/lib/typescript/src/skia/web/Host.d.ts +2 -1
- package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +2 -1
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +3 -1
- package/lib/typescript/src/skia/web/JsiSkTypefaceFontProvider.d.ts +2 -2
- package/package.json +2 -2
- package/src/skia/types/Canvas.ts +14 -1
- package/src/skia/types/Image/Image.ts +20 -0
- package/src/skia/types/Image/ImageFactory.ts +30 -25
- package/src/skia/web/Host.ts +3 -1
- package/src/skia/web/JsiSkCanvas.ts +13 -1
- package/src/skia/web/JsiSkFontMgrFactory.ts +0 -2
- package/src/skia/web/JsiSkImage.ts +36 -3
- package/src/skia/web/JsiSkTypefaceFontProvider.ts +0 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
2
2
|
|
3
|
-
import { ckEnum, HostObject } from "./Host";
|
3
|
+
import { ckEnum, getCkEnum, HostObject } from "./Host";
|
4
4
|
import { JsiSkMatrix } from "./JsiSkMatrix";
|
5
5
|
import { JsiSkShader } from "./JsiSkShader"; // https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js
|
6
6
|
|
@@ -49,6 +49,16 @@ export class JsiSkImage extends HostObject {
|
|
49
49
|
return this.ref.width();
|
50
50
|
}
|
51
51
|
|
52
|
+
getImageInfo() {
|
53
|
+
const info = this.ref.getImageInfo();
|
54
|
+
return {
|
55
|
+
width: info.width,
|
56
|
+
height: info.height,
|
57
|
+
colorType: info.colorType.value,
|
58
|
+
alphaType: info.alphaType.value
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
52
62
|
makeShaderOptions(tx, ty, fm, mm, localMatrix) {
|
53
63
|
return new JsiSkShader(this.CanvasKit, this.ref.makeShaderOptions(ckEnum(tx), ckEnum(ty), ckEnum(fm), ckEnum(mm), localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined));
|
54
64
|
}
|
@@ -80,6 +90,20 @@ export class JsiSkImage extends HostObject {
|
|
80
90
|
return toBase64String(bytes);
|
81
91
|
}
|
82
92
|
|
93
|
+
readPixels(srcX, srcY, imageInfo) {
|
94
|
+
var _imageInfo$width, _imageInfo$height;
|
95
|
+
|
96
|
+
const info = this.getImageInfo();
|
97
|
+
const pxInfo = {
|
98
|
+
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
99
|
+
width: (_imageInfo$width = imageInfo === null || imageInfo === void 0 ? void 0 : imageInfo.width) !== null && _imageInfo$width !== void 0 ? _imageInfo$width : info.width,
|
100
|
+
height: (_imageInfo$height = imageInfo === null || imageInfo === void 0 ? void 0 : imageInfo.height) !== null && _imageInfo$height !== void 0 ? _imageInfo$height : info.height,
|
101
|
+
alphaType: getCkEnum(this.CanvasKit.AlphaType, (imageInfo !== null && imageInfo !== void 0 ? imageInfo : info).alphaType),
|
102
|
+
colorType: getCkEnum(this.CanvasKit.ColorType, (imageInfo !== null && imageInfo !== void 0 ? imageInfo : info).colorType)
|
103
|
+
};
|
104
|
+
return this.ref.readPixels(srcX !== null && srcX !== void 0 ? srcX : 0, srcY !== null && srcY !== void 0 ? srcY : 0, pxInfo);
|
105
|
+
}
|
106
|
+
|
83
107
|
makeNonTextureImage() {
|
84
108
|
return new JsiSkImage(this.CanvasKit, this.CanvasKit.MakeImageFromEncoded(this.encodeToBytes()));
|
85
109
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ckEnum","HostObject","JsiSkMatrix","JsiSkShader","toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","String","fromCharCode","apply","btoa","JsiSkImage","constructor","CanvasKit","ref","delete","height","width","makeShaderOptions","tx","ty","fm","mm","localMatrix","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","Error","encodeToBase64","makeNonTextureImage","MakeImageFromEncoded"],"sources":["JsiSkImage.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"names":["ckEnum","getCkEnum","HostObject","JsiSkMatrix","JsiSkShader","toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","String","fromCharCode","apply","btoa","JsiSkImage","constructor","CanvasKit","ref","delete","height","width","getImageInfo","info","colorType","value","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","pxInfo","colorSpace","ColorSpace","SRGB","AlphaType","ColorType","makeNonTextureImage","MakeImageFromEncoded"],"sources":["JsiSkImage.ts"],"sourcesContent":["import type {\n CanvasKit,\n ImageInfo as CKImageInfo,\n Image,\n} from \"canvaskit-wasm\";\n\nimport type {\n FilterMode,\n MipmapMode,\n SkImage,\n SkMatrix,\n SkShader,\n TileMode,\n ImageFormat,\n ImageInfo,\n} from \"../types\";\n\nimport { ckEnum, getCkEnum, HostObject } from \"./Host\";\nimport { JsiSkMatrix } from \"./JsiSkMatrix\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/htmlcanvas/util.js\nexport const toBase64String = (bytes: Uint8Array) => {\n if (typeof Buffer !== \"undefined\") {\n // Are we on node?\n return Buffer.from(bytes).toString(\"base64\");\n } else {\n // From https://stackoverflow.com/a/25644409\n // because the naive solution of\n // btoa(String.fromCharCode.apply(null, bytes));\n // would occasionally throw \"Maximum call stack size exceeded\"\n var CHUNK_SIZE = 0x8000; //arbitrary number\n var index = 0;\n var { length } = bytes;\n var result = \"\";\n var slice;\n while (index < length) {\n slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result += String.fromCharCode.apply(null, slice as any);\n index += CHUNK_SIZE;\n }\n return btoa(result);\n }\n};\n\nexport class JsiSkImage extends HostObject<Image, \"Image\"> implements SkImage {\n constructor(CanvasKit: CanvasKit, ref: Image) {\n super(CanvasKit, ref, \"Image\");\n }\n\n height() {\n return this.ref.height();\n }\n\n width() {\n return this.ref.width();\n }\n\n getImageInfo(): ImageInfo {\n const info = this.ref.getImageInfo();\n return {\n width: info.width,\n height: info.height,\n colorType: info.colorType.value,\n alphaType: info.alphaType.value,\n };\n }\n\n makeShaderOptions(\n tx: TileMode,\n ty: TileMode,\n fm: FilterMode,\n mm: MipmapMode,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderOptions(\n ckEnum(tx),\n ckEnum(ty),\n ckEnum(fm),\n ckEnum(mm),\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n makeShaderCubic(\n tx: TileMode,\n ty: TileMode,\n B: number,\n C: number,\n localMatrix?: SkMatrix\n ): SkShader {\n return new JsiSkShader(\n this.CanvasKit,\n this.ref.makeShaderCubic(\n ckEnum(tx),\n ckEnum(ty),\n B,\n C,\n localMatrix ? JsiSkMatrix.fromValue(localMatrix) : undefined\n )\n );\n }\n\n encodeToBytes(fmt?: ImageFormat, quality?: number) {\n let result: Uint8Array | null;\n if (fmt && quality) {\n result = this.ref.encodeToBytes(ckEnum(fmt), quality);\n } else if (fmt) {\n result = this.ref.encodeToBytes(ckEnum(fmt));\n } else {\n result = this.ref.encodeToBytes();\n }\n if (!result) {\n throw new Error(\"encodeToBytes failed\");\n }\n return result;\n }\n\n encodeToBase64(fmt?: ImageFormat, quality?: number) {\n const bytes = this.encodeToBytes(fmt, quality);\n return toBase64String(bytes);\n }\n\n readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {\n const info = this.getImageInfo();\n const pxInfo: CKImageInfo = {\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n width: imageInfo?.width ?? info.width,\n height: imageInfo?.height ?? info.height,\n alphaType: getCkEnum(\n this.CanvasKit.AlphaType,\n (imageInfo ?? info).alphaType\n ),\n colorType: getCkEnum(\n this.CanvasKit.ColorType,\n (imageInfo ?? info).colorType\n ),\n };\n return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);\n }\n\n dispose = () => {\n this.ref.delete();\n };\n\n makeNonTextureImage(): SkImage {\n return new JsiSkImage(\n this.CanvasKit,\n this.CanvasKit.MakeImageFromEncoded(this.encodeToBytes())!\n );\n }\n}\n"],"mappings":";;AAiBA,SAASA,MAAT,EAAiBC,SAAjB,EAA4BC,UAA5B,QAA8C,QAA9C;AACA,SAASC,WAAT,QAA4B,eAA5B;AACA,SAASC,WAAT,QAA4B,eAA5B,C,CAEA;;AACA,OAAO,MAAMC,cAAc,GAAIC,KAAD,IAAuB;EACnD,IAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;IACjC;IACA,OAAOA,MAAM,CAACC,IAAP,CAAYF,KAAZ,EAAmBG,QAAnB,CAA4B,QAA5B,CAAP;EACD,CAHD,MAGO;IACL;IACA;IACA;IACA;IACA,IAAIC,UAAU,GAAG,MAAjB,CALK,CAKoB;;IACzB,IAAIC,KAAK,GAAG,CAAZ;IACA,IAAI;MAAEC;IAAF,IAAaN,KAAjB;IACA,IAAIO,MAAM,GAAG,EAAb;IACA,IAAIC,KAAJ;;IACA,OAAOH,KAAK,GAAGC,MAAf,EAAuB;MACrBE,KAAK,GAAGR,KAAK,CAACQ,KAAN,CAAYH,KAAZ,EAAmBI,IAAI,CAACC,GAAL,CAASL,KAAK,GAAGD,UAAjB,EAA6BE,MAA7B,CAAnB,CAAR,CADqB,CAErB;;MACAC,MAAM,IAAII,MAAM,CAACC,YAAP,CAAoBC,KAApB,CAA0B,IAA1B,EAAgCL,KAAhC,CAAV;MACAH,KAAK,IAAID,UAAT;IACD;;IACD,OAAOU,IAAI,CAACP,MAAD,CAAX;EACD;AACF,CAtBM;AAwBP,OAAO,MAAMQ,UAAN,SAAyBnB,UAAzB,CAAuE;EAC5EoB,WAAW,CAACC,SAAD,EAAuBC,GAAvB,EAAmC;IAC5C,MAAMD,SAAN,EAAiBC,GAAjB,EAAsB,OAAtB;;IAD4C,iCAkGpC,MAAM;MACd,KAAKA,GAAL,CAASC,MAAT;IACD,CApG6C;EAE7C;;EAEDC,MAAM,G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AACA,SAAD,GAAcvB,IAAd,EAAoBC,SAFF;IARM,CAA5B;IAaA,OAAO,KAAKN,GAAL,CAASyB,UAAT,CAAoBC,IAApB,aAAoBA,IAApB,cAAoBA,IAApB,GAA4B,CAA5B,EAA+BC,IAA/B,aAA+BA,IAA/B,cAA+BA,IAA/B,GAAuC,CAAvC,EAA0CE,MAA1C,CAAP;EACD;;EAMDM,mBAAmB,GAAY;IAC7B,OAAO,IAAItC,UAAJ,CACL,KAAKE,SADA,EAEL,KAAKA,SAAL,CAAeqC,oBAAf,CAAoC,KAAKhB,aAAL,EAApC,CAFK,CAAP;EAID;;AA5G2E"}
|
@@ -6,8 +6,8 @@ export declare class JsiSkTypefaceFontProvider extends HostObject<TypefaceFontPr
|
|
6
6
|
private allocatedPointers;
|
7
7
|
constructor(CanvasKit: CanvasKit, ref: TypefaceFontProvider);
|
8
8
|
matchFamilyStyle(_name: string, _style: FontStyle): SkTypeface;
|
9
|
-
countFamilies():
|
10
|
-
getFamilyName(index: number):
|
9
|
+
countFamilies(): number;
|
10
|
+
getFamilyName(index: number): string;
|
11
11
|
registerFont(typeface: SkTypeface, familyName: string): void;
|
12
12
|
dispose(): void;
|
13
13
|
}
|
@@ -13,14 +13,10 @@ export class JsiSkTypefaceFontProvider extends HostObject {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
countFamilies() {
|
16
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
17
|
-
// @ts-expect-error
|
18
16
|
return this.ref.countFamilies();
|
19
17
|
}
|
20
18
|
|
21
19
|
getFamilyName(index) {
|
22
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
23
|
-
// @ts-expect-error
|
24
20
|
return this.ref.getFamilyName(index);
|
25
21
|
}
|
26
22
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["HostObject","NotImplementedOnRNWeb","JsiSkTypefaceFontProvider","constructor","CanvasKit","ref","matchFamilyStyle","_name","_style","countFamilies","getFamilyName","index","registerFont","typeface","familyName","strLen","lengthBytesUTF8","strPtr","_malloc","stringToUTF8","_registerFont","dispose","ptr","allocatedPointers","_free","delete","str","encoder","TextEncoder","utf8","encode","length","outPtr","maxBytesToWrite","heap","HEAPU8","Error","i"],"sources":["JsiSkTypefaceFontProvider.ts"],"sourcesContent":["import type { CanvasKit, TypefaceFontProvider } from \"canvaskit-wasm\";\n\nimport type { SkTypefaceFontProvider } from \"../types/Paragraph/TypefaceFontProvider\";\nimport type { FontStyle, SkTypeface } from \"../types\";\n\nimport { HostObject, NotImplementedOnRNWeb } from \"./Host\";\n\nexport class JsiSkTypefaceFontProvider\n extends HostObject<TypefaceFontProvider, \"FontMgr\">\n implements SkTypefaceFontProvider\n{\n private allocatedPointers: number[] = [];\n\n constructor(CanvasKit: CanvasKit, ref: TypefaceFontProvider) {\n super(CanvasKit, ref, \"FontMgr\");\n }\n\n matchFamilyStyle(_name: string, _style: FontStyle): SkTypeface {\n throw new NotImplementedOnRNWeb();\n }\n countFamilies() {\n
|
1
|
+
{"version":3,"names":["HostObject","NotImplementedOnRNWeb","JsiSkTypefaceFontProvider","constructor","CanvasKit","ref","matchFamilyStyle","_name","_style","countFamilies","getFamilyName","index","registerFont","typeface","familyName","strLen","lengthBytesUTF8","strPtr","_malloc","stringToUTF8","_registerFont","dispose","ptr","allocatedPointers","_free","delete","str","encoder","TextEncoder","utf8","encode","length","outPtr","maxBytesToWrite","heap","HEAPU8","Error","i"],"sources":["JsiSkTypefaceFontProvider.ts"],"sourcesContent":["import type { CanvasKit, TypefaceFontProvider } from \"canvaskit-wasm\";\n\nimport type { SkTypefaceFontProvider } from \"../types/Paragraph/TypefaceFontProvider\";\nimport type { FontStyle, SkTypeface } from \"../types\";\n\nimport { HostObject, NotImplementedOnRNWeb } from \"./Host\";\n\nexport class JsiSkTypefaceFontProvider\n extends HostObject<TypefaceFontProvider, \"FontMgr\">\n implements SkTypefaceFontProvider\n{\n private allocatedPointers: number[] = [];\n\n constructor(CanvasKit: CanvasKit, ref: TypefaceFontProvider) {\n super(CanvasKit, ref, \"FontMgr\");\n }\n\n matchFamilyStyle(_name: string, _style: FontStyle): SkTypeface {\n throw new NotImplementedOnRNWeb();\n }\n countFamilies() {\n return this.ref.countFamilies();\n }\n getFamilyName(index: number) {\n return this.ref.getFamilyName(index);\n }\n registerFont(typeface: SkTypeface, familyName: string) {\n const strLen = lengthBytesUTF8(familyName) + 1;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n const strPtr = this.CanvasKit._malloc(strLen);\n stringToUTF8(this.CanvasKit, familyName, strPtr, strLen);\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n this.ref._registerFont(typeface.ref, strPtr);\n }\n\n dispose() {\n for (const ptr of this.allocatedPointers) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n this.CanvasKit._free(ptr);\n }\n\n this.ref.delete();\n }\n}\n\nconst lengthBytesUTF8 = (str: string) => {\n // TextEncoder will give us the byte length in UTF8 form\n const encoder = new TextEncoder();\n const utf8 = encoder.encode(str);\n return utf8.length;\n};\n\nconst stringToUTF8 = (\n CanvasKit: CanvasKit,\n str: string,\n outPtr: number,\n maxBytesToWrite: number\n) => {\n // TextEncoder will give us the byte array in UTF8 form\n const encoder = new TextEncoder();\n const utf8 = encoder.encode(str);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n const heap: Int8Array = CanvasKit.HEAPU8;\n\n // Check if there's enough space\n if (utf8.length > maxBytesToWrite) {\n throw new Error(\"Not enough space to write UTF8 encoded string\");\n }\n\n // Copy the bytes\n for (let i = 0; i < utf8.length; i++) {\n heap[outPtr + i] = utf8[i];\n }\n\n // Null terminate\n if (utf8.length < maxBytesToWrite) {\n heap[outPtr + utf8.length] = 0;\n }\n};\n"],"mappings":";;AAKA,SAASA,UAAT,EAAqBC,qBAArB,QAAkD,QAAlD;AAEA,OAAO,MAAMC,yBAAN,SACGF,UAD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AHmB,EAInBC,eAJmB,KAKhB;EACH;EACA,MAAMN,OAAO,GAAG,IAAIC,WAAJ,EAAhB;EACA,MAAMC,IAAI,GAAGF,OAAO,CAACG,MAAR,CAAeJ,GAAf,CAAb,CAHG,CAIH;EACA;;EACA,MAAMQ,IAAe,GAAG9B,SAAS,CAAC+B,MAAlC,CANG,CAQH;;EACA,IAAIN,IAAI,CAACE,MAAL,GAAcE,eAAlB,EAAmC;IACjC,MAAM,IAAIG,KAAJ,CAAU,+CAAV,CAAN;EACD,CAXE,CAaH;;;EACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGR,IAAI,CAACE,MAAzB,EAAiCM,CAAC,EAAlC,EAAsC;IACpCH,IAAI,CAACF,MAAM,GAAGK,CAAV,CAAJ,GAAmBR,IAAI,CAACQ,CAAD,CAAvB;EACD,CAhBE,CAkBH;;;EACA,IAAIR,IAAI,CAACE,MAAL,GAAcE,eAAlB,EAAmC;IACjCC,IAAI,CAACF,MAAM,GAAGH,IAAI,CAACE,MAAf,CAAJ,GAA6B,CAA7B;EACD;AACF,CA3BD"}
|
@@ -2,7 +2,7 @@ import type { SkPaint } from "./Paint";
|
|
2
2
|
import type { SkRect } from "./Rect";
|
3
3
|
import type { SkFont } from "./Font";
|
4
4
|
import type { SkPath } from "./Path";
|
5
|
-
import type { SkImage, MipmapMode, FilterMode } from "./Image";
|
5
|
+
import type { SkImage, MipmapMode, FilterMode, ImageInfo } from "./Image";
|
6
6
|
import type { SkSVG } from "./SVG";
|
7
7
|
import type { SkColor } from "./Color";
|
8
8
|
import type { SkRRect } from "./RRect";
|
@@ -378,4 +378,12 @@ export interface SkCanvas {
|
|
378
378
|
* @param skp
|
379
379
|
*/
|
380
380
|
drawPicture(skp: SkPicture): void;
|
381
|
+
/** Read Image pixels
|
382
|
+
*
|
383
|
+
* @param srcX - x-axis upper left corner of the rectangle to read from
|
384
|
+
* @param srcY - y-axis upper left corner of the rectangle to read from
|
385
|
+
* @param imageInfo - describes the pixel format and dimensions of the data to read into
|
386
|
+
* @return Float32Array or Uint8Array with data or null if the read failed.
|
387
|
+
*/
|
388
|
+
readPixels(srcX: number, srcY: number, imageInfo: ImageInfo): Float32Array | Uint8Array | null;
|
381
389
|
}
|
@@ -2,6 +2,7 @@ import type { SkMatrix } from "../Matrix";
|
|
2
2
|
import type { SkJSIInstance } from "../JsiInstance";
|
3
3
|
import type { TileMode } from "../ImageFilter";
|
4
4
|
import type { SkShader } from "../Shader";
|
5
|
+
import type { ImageInfo } from "./ImageFactory";
|
5
6
|
export declare enum FilterMode {
|
6
7
|
Nearest = 0,
|
7
8
|
Linear = 1
|
@@ -25,6 +26,10 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
25
26
|
* Returns the possibly scaled width of the image.
|
26
27
|
*/
|
27
28
|
width(): number;
|
29
|
+
/**
|
30
|
+
* Returns the ImageInfo describing the image.
|
31
|
+
*/
|
32
|
+
getImageInfo(): ImageInfo;
|
28
33
|
/**
|
29
34
|
* Returns this image as a shader with the specified tiling. It will use cubic sampling.
|
30
35
|
* @param tx - tile mode in the x direction.
|
@@ -72,6 +77,14 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
72
77
|
@return base64 encoded string of data
|
73
78
|
*/
|
74
79
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
80
|
+
/** Read Image pixels
|
81
|
+
*
|
82
|
+
* @param srcX - optional x-axis upper left corner of the rectangle to read from
|
83
|
+
* @param srcY - optional y-axis upper left corner of the rectangle to read from
|
84
|
+
* @param imageInfo - optional describes the pixel format and dimensions of the data to read into
|
85
|
+
* @return Float32Array or Uint8Array with data or null if the read failed.
|
86
|
+
*/
|
87
|
+
readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo): Float32Array | Uint8Array | null;
|
75
88
|
/**
|
76
89
|
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
77
90
|
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
@@ -19,17 +19,20 @@ export declare enum ColorType {
|
|
19
19
|
RGB_101010x = 9,
|
20
20
|
BGR_101010x = 10,
|
21
21
|
BGR_101010x_XR = 11,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
RGBA_10x6 = 12,
|
23
|
+
Gray_8 = 13,
|
24
|
+
RGBA_F16Norm = 14,
|
25
|
+
RGBA_F16 = 15,
|
26
|
+
RGBA_F32 = 16,
|
27
|
+
R8G8_unorm = 17,
|
28
|
+
A16_float = 18,
|
29
|
+
R16G16_float = 19,
|
30
|
+
A16_unorm = 20,
|
31
|
+
R16G16_unorm = 21,
|
32
|
+
R16G16B16A16_unorm = 22,
|
33
|
+
SRGBA_8888 = 23,
|
34
|
+
R8_unorm = 24,
|
35
|
+
N32_SkColorType = 25
|
33
36
|
}
|
34
37
|
export interface ImageInfo {
|
35
38
|
alphaType: AlphaType;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { CanvasKit, EmbindEnumEntity } from "canvaskit-wasm";
|
1
|
+
import type { CanvasKit, EmbindEnumEntity, EmbindEnum } from "canvaskit-wasm";
|
2
2
|
import type { SkJSIInstance } from "../types";
|
3
3
|
export declare class NotImplementedOnRNWeb extends Error {
|
4
4
|
constructor(msg?: string);
|
@@ -16,5 +16,6 @@ export declare abstract class BaseHostObject<T, N extends string> extends Host i
|
|
16
16
|
export declare abstract class HostObject<T, N extends string> extends BaseHostObject<T, N> {
|
17
17
|
static fromValue<T>(value: SkJSIInstance<string>): T;
|
18
18
|
}
|
19
|
+
export declare const getCkEnum: (e: EmbindEnum, v: number) => EmbindEnumEntity;
|
19
20
|
export declare const ckEnum: (value: number) => EmbindEnumEntity;
|
20
21
|
export declare const optEnum: (value: number | undefined) => EmbindEnumEntity | undefined;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Canvas, CanvasKit } from "canvaskit-wasm";
|
2
|
-
import type { BlendMode, ClipOp, FilterMode, MipmapMode, PointMode, SaveLayerFlag, SkCanvas, SkColor, SkFont, SkImage, SkImageFilter, SkMatrix, SkPaint, SkPath, SkPicture, SkPoint, SkRect, SkRRect, SkSVG, SkTextBlob, SkVertices } from "../types";
|
2
|
+
import type { BlendMode, ClipOp, FilterMode, MipmapMode, PointMode, SaveLayerFlag, ImageInfo, SkCanvas, SkColor, SkFont, SkImage, SkImageFilter, SkMatrix, SkPaint, SkPath, SkPicture, SkPoint, SkRect, SkRRect, SkSVG, SkTextBlob, SkVertices } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
4
|
export declare class JsiSkCanvas extends HostObject<Canvas, "Canvas"> implements SkCanvas {
|
5
5
|
constructor(CanvasKit: CanvasKit, ref: Canvas);
|
@@ -42,4 +42,5 @@ export declare class JsiSkCanvas extends HostObject<Canvas, "Canvas"> implements
|
|
42
42
|
clipRRect(rrect: SkRRect, op: ClipOp, doAntiAlias: boolean): void;
|
43
43
|
concat(m: SkMatrix): void;
|
44
44
|
drawPicture(skp: SkPicture): void;
|
45
|
+
readPixels(srcX: number, srcY: number, imageInfo: ImageInfo): Float32Array | Uint8Array | null;
|
45
46
|
}
|
@@ -1,15 +1,17 @@
|
|
1
1
|
import type { CanvasKit, Image } from "canvaskit-wasm";
|
2
|
-
import type {
|
2
|
+
import type { FilterMode, MipmapMode, SkImage, SkMatrix, SkShader, TileMode, ImageFormat, ImageInfo } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
4
|
export declare const toBase64String: (bytes: Uint8Array) => string;
|
5
5
|
export declare class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
6
6
|
constructor(CanvasKit: CanvasKit, ref: Image);
|
7
7
|
height(): number;
|
8
8
|
width(): number;
|
9
|
+
getImageInfo(): ImageInfo;
|
9
10
|
makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode, localMatrix?: SkMatrix): SkShader;
|
10
11
|
makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number, localMatrix?: SkMatrix): SkShader;
|
11
12
|
encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;
|
12
13
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
14
|
+
readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo): Float32Array | Uint8Array | null;
|
13
15
|
dispose: () => void;
|
14
16
|
makeNonTextureImage(): SkImage;
|
15
17
|
}
|
@@ -6,8 +6,8 @@ export declare class JsiSkTypefaceFontProvider extends HostObject<TypefaceFontPr
|
|
6
6
|
private allocatedPointers;
|
7
7
|
constructor(CanvasKit: CanvasKit, ref: TypefaceFontProvider);
|
8
8
|
matchFamilyStyle(_name: string, _style: FontStyle): SkTypeface;
|
9
|
-
countFamilies():
|
10
|
-
getFamilyName(index: number):
|
9
|
+
countFamilies(): number;
|
10
|
+
getFamilyName(index: number): string;
|
11
11
|
registerFont(typeface: SkTypeface, familyName: string): void;
|
12
12
|
dispose(): void;
|
13
13
|
}
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
8
|
},
|
9
9
|
"title": "React Native Skia",
|
10
|
-
"version": "0.1.
|
10
|
+
"version": "0.1.222",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"files": [
|
@@ -106,7 +106,7 @@
|
|
106
106
|
"ws": "^8.11.0"
|
107
107
|
},
|
108
108
|
"dependencies": {
|
109
|
-
"canvaskit-wasm": "0.
|
109
|
+
"canvaskit-wasm": "0.39.1",
|
110
110
|
"react-reconciler": "^0.27.0"
|
111
111
|
},
|
112
112
|
"eslintIgnore": [
|
package/src/skia/types/Canvas.ts
CHANGED
@@ -2,7 +2,7 @@ import type { SkPaint } from "./Paint";
|
|
2
2
|
import type { SkRect } from "./Rect";
|
3
3
|
import type { SkFont } from "./Font";
|
4
4
|
import type { SkPath } from "./Path";
|
5
|
-
import type { SkImage, MipmapMode, FilterMode } from "./Image";
|
5
|
+
import type { SkImage, MipmapMode, FilterMode, ImageInfo } from "./Image";
|
6
6
|
import type { SkSVG } from "./SVG";
|
7
7
|
import type { SkColor } from "./Color";
|
8
8
|
import type { SkRRect } from "./RRect";
|
@@ -492,4 +492,17 @@ export interface SkCanvas {
|
|
492
492
|
* @param skp
|
493
493
|
*/
|
494
494
|
drawPicture(skp: SkPicture): void;
|
495
|
+
|
496
|
+
/** Read Image pixels
|
497
|
+
*
|
498
|
+
* @param srcX - x-axis upper left corner of the rectangle to read from
|
499
|
+
* @param srcY - y-axis upper left corner of the rectangle to read from
|
500
|
+
* @param imageInfo - describes the pixel format and dimensions of the data to read into
|
501
|
+
* @return Float32Array or Uint8Array with data or null if the read failed.
|
502
|
+
*/
|
503
|
+
readPixels(
|
504
|
+
srcX: number,
|
505
|
+
srcY: number,
|
506
|
+
imageInfo: ImageInfo
|
507
|
+
): Float32Array | Uint8Array | null;
|
495
508
|
}
|
@@ -3,6 +3,8 @@ import type { SkJSIInstance } from "../JsiInstance";
|
|
3
3
|
import type { TileMode } from "../ImageFilter";
|
4
4
|
import type { SkShader } from "../Shader";
|
5
5
|
|
6
|
+
import type { ImageInfo } from "./ImageFactory";
|
7
|
+
|
6
8
|
export enum FilterMode {
|
7
9
|
Nearest,
|
8
10
|
Linear,
|
@@ -31,6 +33,11 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
31
33
|
*/
|
32
34
|
width(): number;
|
33
35
|
|
36
|
+
/**
|
37
|
+
* Returns the ImageInfo describing the image.
|
38
|
+
*/
|
39
|
+
getImageInfo(): ImageInfo;
|
40
|
+
|
34
41
|
/**
|
35
42
|
* Returns this image as a shader with the specified tiling. It will use cubic sampling.
|
36
43
|
* @param tx - tile mode in the x direction.
|
@@ -94,6 +101,19 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
94
101
|
*/
|
95
102
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
96
103
|
|
104
|
+
/** Read Image pixels
|
105
|
+
*
|
106
|
+
* @param srcX - optional x-axis upper left corner of the rectangle to read from
|
107
|
+
* @param srcY - optional y-axis upper left corner of the rectangle to read from
|
108
|
+
* @param imageInfo - optional describes the pixel format and dimensions of the data to read into
|
109
|
+
* @return Float32Array or Uint8Array with data or null if the read failed.
|
110
|
+
*/
|
111
|
+
readPixels(
|
112
|
+
srcX?: number,
|
113
|
+
srcY?: number,
|
114
|
+
imageInfo?: ImageInfo
|
115
|
+
): Float32Array | Uint8Array | null;
|
116
|
+
|
97
117
|
/**
|
98
118
|
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
99
119
|
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
@@ -10,36 +10,41 @@ export enum AlphaType {
|
|
10
10
|
}
|
11
11
|
|
12
12
|
export enum ColorType {
|
13
|
-
Unknown,
|
14
|
-
Alpha_8,
|
15
|
-
RGB_565,
|
16
|
-
ARGB_4444,
|
17
|
-
RGBA_8888,
|
18
|
-
RGB_888x,
|
19
|
-
BGRA_8888,
|
20
|
-
RGBA_1010102,
|
21
|
-
BGRA_1010102,
|
22
|
-
RGB_101010x,
|
23
|
-
BGR_101010x,
|
24
|
-
BGR_101010x_XR,
|
25
|
-
|
26
|
-
|
27
|
-
//
|
28
|
-
RGBA_F16,
|
29
|
-
//
|
30
|
-
RGBA_F32, //!< pixel using C float for red, green, blue, alpha; in 128-bit word
|
13
|
+
Unknown, // uninitialized
|
14
|
+
Alpha_8, // pixel with alpha in 8-bit byte
|
15
|
+
RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
|
16
|
+
ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word
|
17
|
+
RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word
|
18
|
+
RGB_888x, // pixel with 8 bits each for red, green, blue; in 32-bit word
|
19
|
+
BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word
|
20
|
+
RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
|
21
|
+
BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
|
22
|
+
RGB_101010x, // pixel with 10 bits each for red, green, blue; in 32-bit word
|
23
|
+
BGR_101010x, // pixel with 10 bits each for blue, green, red; in 32-bit word
|
24
|
+
BGR_101010x_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
|
25
|
+
RGBA_10x6, // pixel with 10 used bits (most significant) followed by 6 unused
|
26
|
+
Gray_8, // pixel with grayscale level in 8-bit byte
|
27
|
+
RGBA_F16Norm, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word
|
28
|
+
RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word
|
29
|
+
RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word
|
31
30
|
|
32
31
|
// The following 6 colortypes are just for reading from - not for rendering to
|
33
|
-
R8G8_unorm,
|
32
|
+
R8G8_unorm, // pixel with a uint8_t for red and green
|
34
33
|
|
35
|
-
A16_float,
|
36
|
-
R16G16_float,
|
34
|
+
A16_float, // pixel with a half float for alpha
|
35
|
+
R16G16_float, // pixel with a half float for red and green
|
36
|
+
|
37
|
+
A16_unorm, // pixel with a little endian uint16_t for alpha
|
38
|
+
R16G16_unorm, // pixel with a little endian uint16_t for red and green
|
39
|
+
R16G16B16A16_unorm, // pixel with a little endian uint16_t for red, green, blue, and alpha
|
37
40
|
|
38
|
-
A16_unorm, //!< pixel with a little endian uint16_t for alpha
|
39
|
-
R16G16_unorm, //!< pixel with a little endian uint16_t for red and green
|
40
|
-
R16G16B16A16_unorm, //!< pixel with a little endian uint16_t for red, green, blue
|
41
|
-
// and alpha
|
42
41
|
SRGBA_8888,
|
42
|
+
R8_unorm,
|
43
|
+
|
44
|
+
// The `kN32_SkColorType` is platform dependent in the original enum,
|
45
|
+
// and TypeScript doesn't support conditional compilation natively.
|
46
|
+
// You might need to handle it differently based on your use case.
|
47
|
+
N32_SkColorType, // either BGRA_8888 or RGBA_8888 based on the platform
|
43
48
|
}
|
44
49
|
|
45
50
|
export interface ImageInfo {
|
package/src/skia/web/Host.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { CanvasKit, EmbindEnumEntity } from "canvaskit-wasm";
|
1
|
+
import type { CanvasKit, EmbindEnumEntity, EmbindEnum } from "canvaskit-wasm";
|
2
2
|
|
3
3
|
import type { SkJSIInstance } from "../types";
|
4
4
|
|
@@ -41,6 +41,8 @@ export abstract class HostObject<T, N extends string> extends BaseHostObject<
|
|
41
41
|
}
|
42
42
|
}
|
43
43
|
|
44
|
+
export const getCkEnum = (e: EmbindEnum, v: number): EmbindEnumEntity =>
|
45
|
+
Object.values(e).find(({ value }) => value === v);
|
44
46
|
export const ckEnum = (value: number): EmbindEnumEntity => ({ value });
|
45
47
|
export const optEnum = (
|
46
48
|
value: number | undefined
|
@@ -7,6 +7,7 @@ import type {
|
|
7
7
|
MipmapMode,
|
8
8
|
PointMode,
|
9
9
|
SaveLayerFlag,
|
10
|
+
ImageInfo,
|
10
11
|
SkCanvas,
|
11
12
|
SkColor,
|
12
13
|
SkFont,
|
@@ -24,7 +25,7 @@ import type {
|
|
24
25
|
SkVertices,
|
25
26
|
} from "../types";
|
26
27
|
|
27
|
-
import { ckEnum, HostObject } from "./Host";
|
28
|
+
import { ckEnum, getCkEnum, HostObject } from "./Host";
|
28
29
|
import { JsiSkPaint } from "./JsiSkPaint";
|
29
30
|
import { JsiSkRect } from "./JsiSkRect";
|
30
31
|
import { JsiSkRRect } from "./JsiSkRRect";
|
@@ -374,4 +375,15 @@ export class JsiSkCanvas
|
|
374
375
|
drawPicture(skp: SkPicture) {
|
375
376
|
this.ref.drawPicture(JsiSkPicture.fromValue(skp));
|
376
377
|
}
|
378
|
+
|
379
|
+
readPixels(srcX: number, srcY: number, imageInfo: ImageInfo) {
|
380
|
+
const pxInfo = {
|
381
|
+
width: imageInfo.width,
|
382
|
+
height: imageInfo.height,
|
383
|
+
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
384
|
+
alphaType: getCkEnum(this.CanvasKit.AlphaType, imageInfo.alphaType),
|
385
|
+
colorType: getCkEnum(this.CanvasKit.ColorType, imageInfo.colorType),
|
386
|
+
};
|
387
|
+
return this.ref.readPixels(srcX, srcY, pxInfo);
|
388
|
+
}
|
377
389
|
}
|
@@ -15,8 +15,6 @@ export class JsiSkFontMgrFactory extends Host implements FontMgrFactory {
|
|
15
15
|
if (!fontMgr) {
|
16
16
|
throw new Error("Couldn't create system font manager");
|
17
17
|
}
|
18
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
19
|
-
// @ts-expect-error
|
20
18
|
return new JsiSkFontMgr(this.CanvasKit, fontMgr);
|
21
19
|
}
|
22
20
|
}
|
@@ -1,16 +1,21 @@
|
|
1
|
-
import type {
|
1
|
+
import type {
|
2
|
+
CanvasKit,
|
3
|
+
ImageInfo as CKImageInfo,
|
4
|
+
Image,
|
5
|
+
} from "canvaskit-wasm";
|
2
6
|
|
3
7
|
import type {
|
4
|
-
ImageFormat,
|
5
8
|
FilterMode,
|
6
9
|
MipmapMode,
|
7
10
|
SkImage,
|
8
11
|
SkMatrix,
|
9
12
|
SkShader,
|
10
13
|
TileMode,
|
14
|
+
ImageFormat,
|
15
|
+
ImageInfo,
|
11
16
|
} from "../types";
|
12
17
|
|
13
|
-
import { ckEnum, HostObject } from "./Host";
|
18
|
+
import { ckEnum, getCkEnum, HostObject } from "./Host";
|
14
19
|
import { JsiSkMatrix } from "./JsiSkMatrix";
|
15
20
|
import { JsiSkShader } from "./JsiSkShader";
|
16
21
|
|
@@ -52,6 +57,16 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
52
57
|
return this.ref.width();
|
53
58
|
}
|
54
59
|
|
60
|
+
getImageInfo(): ImageInfo {
|
61
|
+
const info = this.ref.getImageInfo();
|
62
|
+
return {
|
63
|
+
width: info.width,
|
64
|
+
height: info.height,
|
65
|
+
colorType: info.colorType.value,
|
66
|
+
alphaType: info.alphaType.value,
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
55
70
|
makeShaderOptions(
|
56
71
|
tx: TileMode,
|
57
72
|
ty: TileMode,
|
@@ -110,6 +125,24 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
110
125
|
return toBase64String(bytes);
|
111
126
|
}
|
112
127
|
|
128
|
+
readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {
|
129
|
+
const info = this.getImageInfo();
|
130
|
+
const pxInfo: CKImageInfo = {
|
131
|
+
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
132
|
+
width: imageInfo?.width ?? info.width,
|
133
|
+
height: imageInfo?.height ?? info.height,
|
134
|
+
alphaType: getCkEnum(
|
135
|
+
this.CanvasKit.AlphaType,
|
136
|
+
(imageInfo ?? info).alphaType
|
137
|
+
),
|
138
|
+
colorType: getCkEnum(
|
139
|
+
this.CanvasKit.ColorType,
|
140
|
+
(imageInfo ?? info).colorType
|
141
|
+
),
|
142
|
+
};
|
143
|
+
return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);
|
144
|
+
}
|
145
|
+
|
113
146
|
dispose = () => {
|
114
147
|
this.ref.delete();
|
115
148
|
};
|
@@ -19,13 +19,9 @@ export class JsiSkTypefaceFontProvider
|
|
19
19
|
throw new NotImplementedOnRNWeb();
|
20
20
|
}
|
21
21
|
countFamilies() {
|
22
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
23
|
-
// @ts-expect-error
|
24
22
|
return this.ref.countFamilies();
|
25
23
|
}
|
26
24
|
getFamilyName(index: number) {
|
27
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
28
|
-
// @ts-expect-error
|
29
25
|
return this.ref.getFamilyName(index);
|
30
26
|
}
|
31
27
|
registerFont(typeface: SkTypeface, familyName: string) {
|