@shopify/react-native-skia 0.1.220 → 0.1.221
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkCanvas.h +38 -1
- package/cpp/api/JsiSkImage.h +66 -1
- package/cpp/api/JsiSkImageInfo.h +19 -0
- 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 +28 -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 +31 -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 +42 -3
- package/src/skia/web/JsiSkTypefaceFontProvider.ts +0 -4
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,30 @@ 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
|
+
console.log({
|
131
|
+
alphaType: ckEnum(info.alphaType),
|
132
|
+
colorType: ckEnum(info.colorType),
|
133
|
+
realAlphaType: this.CanvasKit.AlphaType.Opaque.value,
|
134
|
+
realColorType: this.CanvasKit.ColorType.RGBA_8888.value,
|
135
|
+
});
|
136
|
+
const pxInfo: CKImageInfo = {
|
137
|
+
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
138
|
+
width: imageInfo?.width ?? info.width,
|
139
|
+
height: imageInfo?.height ?? info.height,
|
140
|
+
alphaType: getCkEnum(
|
141
|
+
this.CanvasKit.AlphaType,
|
142
|
+
(imageInfo ?? info).alphaType
|
143
|
+
),
|
144
|
+
colorType: getCkEnum(
|
145
|
+
this.CanvasKit.ColorType,
|
146
|
+
(imageInfo ?? info).colorType
|
147
|
+
),
|
148
|
+
};
|
149
|
+
return this.ref.readPixels(srcX ?? 0, srcY ?? 0, pxInfo);
|
150
|
+
}
|
151
|
+
|
113
152
|
dispose = () => {
|
114
153
|
this.ref.delete();
|
115
154
|
};
|
@@ -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) {
|