@shopify/react-native-skia 0.1.219 → 0.1.221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/jestEnv.mjs +23 -0
- package/jestSetup.mjs +22 -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 +5 -4
- 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
@@ -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,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) {
|