@shopify/react-native-skia 0.1.221 → 0.1.222

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,6 +56,9 @@ public:
56
56
  void surfaceSizeChanged(int width, int height) override {
57
57
  std::static_pointer_cast<RNSkOpenGLCanvasProvider>(T::getCanvasProvider())
58
58
  ->surfaceSizeChanged(width, height);
59
+ // This is only need for the first time to frame, this renderImmediate call
60
+ // will invoke updateTexImage for the previous frame
61
+ RNSkView::renderImmediate();
59
62
  }
60
63
 
61
64
  float getPixelDensity() override {
@@ -39,6 +39,7 @@ bool RNSkOpenGLCanvasProvider::renderToCanvas(
39
39
  if (!_surfaceHolder->makeCurrent()) {
40
40
  return false;
41
41
  }
42
+ _surfaceHolder->updateTexImage();
42
43
 
43
44
  // Draw into canvas using callback
44
45
  cb(surface->getCanvas());
@@ -187,7 +187,6 @@ public:
187
187
  RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
188
188
  return false;
189
189
  }
190
- return true;
191
190
  }
192
191
  return true;
193
192
  }
@@ -6,6 +6,8 @@
6
6
  #include <jni.h>
7
7
 
8
8
  #include <android/native_window_jni.h>
9
+ #include <android/surface_texture.h>
10
+ #include <android/surface_texture_jni.h>
9
11
  #include <condition_variable>
10
12
  #include <memory>
11
13
  #include <thread>
@@ -42,12 +44,34 @@ public:
42
44
  */
43
45
  class WindowSurfaceHolder {
44
46
  public:
45
- WindowSurfaceHolder(jobject surface, int width, int height)
46
- : _width(width), _height(height),
47
- _window(ANativeWindow_fromSurface(facebook::jni::Environment::current(),
48
- surface)) {}
47
+ WindowSurfaceHolder(jobject jSurfaceTexture, int width, int height)
48
+ : _width(width), _height(height) {
49
+ JNIEnv *env = facebook::jni::Environment::current();
50
+ _jSurfaceTexture = env->NewGlobalRef(jSurfaceTexture);
51
+ jclass surfaceClass = env->FindClass("android/view/Surface");
52
+ jmethodID surfaceConstructor = env->GetMethodID(
53
+ surfaceClass, "<init>", "(Landroid/graphics/SurfaceTexture;)V");
54
+ // Create a new Surface instance
55
+ jobject jSurface =
56
+ env->NewObject(surfaceClass, surfaceConstructor, jSurfaceTexture);
57
+
58
+ jclass surfaceTextureClass = env->GetObjectClass(_jSurfaceTexture);
59
+ _updateTexImageMethod =
60
+ env->GetMethodID(surfaceTextureClass, "updateTexImage", "()V");
61
+
62
+ // Acquire the native window from the Surface
63
+ _window = ANativeWindow_fromSurface(env, jSurface);
64
+ // Clean up local references
65
+ env->DeleteLocalRef(jSurface);
66
+ env->DeleteLocalRef(surfaceClass);
67
+ env->DeleteLocalRef(surfaceTextureClass);
68
+ }
49
69
 
50
- ~WindowSurfaceHolder() { ANativeWindow_release(_window); }
70
+ ~WindowSurfaceHolder() {
71
+ JNIEnv *env = facebook::jni::Environment::current();
72
+ env->DeleteGlobalRef(_jSurfaceTexture);
73
+ ANativeWindow_release(_window);
74
+ }
51
75
 
52
76
  int getWidth() { return _width; }
53
77
  int getHeight() { return _height; }
@@ -57,6 +81,20 @@ public:
57
81
  */
58
82
  sk_sp<SkSurface> getSurface();
59
83
 
84
+ void updateTexImage() {
85
+ JNIEnv *env = facebook::jni::Environment::current();
86
+
87
+ // Call updateTexImage on the SurfaceTexture object
88
+ env->CallVoidMethod(_jSurfaceTexture, _updateTexImageMethod);
89
+
90
+ // Check for exceptions
91
+ if (env->ExceptionCheck()) {
92
+ RNSkLogger::logToConsole(
93
+ "updateTexImage() failed. The exception above can safely be ignored");
94
+ env->ExceptionClear();
95
+ }
96
+ }
97
+
60
98
  /**
61
99
  * Resizes the surface
62
100
  * @param width
@@ -92,9 +130,11 @@ public:
92
130
  }
93
131
 
94
132
  private:
95
- ANativeWindow *_window = nullptr;
133
+ ANativeWindow *_window;
96
134
  sk_sp<SkSurface> _skSurface = nullptr;
135
+ jobject _jSurfaceTexture = nullptr;
97
136
  EGLSurface _glSurface = EGL_NO_SURFACE;
137
+ jmethodID _updateTexImageMethod = nullptr;
98
138
  int _width = 0;
99
139
  int _height = 0;
100
140
  };
@@ -52,13 +52,13 @@ public class PlatformContext {
52
52
  Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
53
53
  @Override
54
54
  public void doFrame(long frameTimeNanos) {
55
+ if (_drawLoopActive) {
56
+ Choreographer.getInstance().postFrameCallback(this);
57
+ }
55
58
  if (_isPaused) {
56
59
  return;
57
60
  }
58
61
  notifyDrawLoop();
59
- if (_drawLoopActive) {
60
- postFrameLoop();
61
- }
62
62
  }
63
63
  };
64
64
  Choreographer.getInstance().postFrameCallback(frameCallback);
@@ -4,16 +4,11 @@ import android.content.Context;
4
4
  import android.graphics.SurfaceTexture;
5
5
  import android.util.Log;
6
6
  import android.view.MotionEvent;
7
- import android.view.Surface;
8
7
  import android.view.TextureView;
9
8
 
10
- import com.facebook.jni.annotations.DoNotStrip;
11
9
  import com.facebook.react.views.view.ReactViewGroup;
12
10
 
13
11
  public abstract class SkiaBaseView extends ReactViewGroup implements TextureView.SurfaceTextureListener {
14
-
15
- @DoNotStrip
16
- private Surface mSurface;
17
12
  private TextureView mTexture;
18
13
 
19
14
  private String tag = "SkiaView";
@@ -30,12 +25,8 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
30
25
  }
31
26
 
32
27
  public void destroySurface() {
33
- if (mSurface != null) {
34
- Log.i(tag, "destroySurface");
35
- surfaceDestroyed();
36
- mSurface.release();
37
- mSurface = null;
38
- }
28
+ Log.i(tag, "destroySurface");
29
+ surfaceDestroyed();
39
30
  }
40
31
 
41
32
  private void createSurfaceTexture() {
@@ -138,8 +129,7 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
138
129
  @Override
139
130
  public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
140
131
  Log.i(tag, "onSurfaceTextureAvailable " + width + "/" + height);
141
- mSurface = new Surface(surface);
142
- surfaceAvailable(mSurface, width, height);
132
+ surfaceAvailable(surface, width, height);
143
133
  }
144
134
 
145
135
  @Override
@@ -153,6 +143,10 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
153
143
  Log.i(tag, "onSurfaceTextureDestroyed");
154
144
  // https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)
155
145
  destroySurface();
146
+ // Because of React Native Screens (which dettach the view), we always keep the surface alive.
147
+ // If not, Texture view will recreate the texture surface by itself and
148
+ // we will lose the fast first time to frame.
149
+ // We only delete the surface when the view is dropped (destroySurface invoked by SkiaBaseViewManager);
156
150
  createSurfaceTexture();
157
151
  return false;
158
152
  }
@@ -181,4 +175,4 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
181
175
  protected abstract void registerView(int nativeId);
182
176
 
183
177
  protected abstract void unregisterView();
184
- }
178
+ }
@@ -1,11 +1,10 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import static android.view.View.VISIBLE;
4
-
5
3
  import android.graphics.Bitmap;
6
4
  import android.graphics.Canvas;
7
5
  import android.graphics.Matrix;
8
6
  import android.graphics.Paint;
7
+ import android.graphics.drawable.Drawable;
9
8
  import android.os.Build;
10
9
  import android.os.Handler;
11
10
  import android.os.Looper;
@@ -15,14 +14,12 @@ import android.view.SurfaceView;
15
14
  import android.view.TextureView;
16
15
  import android.view.View;
17
16
  import android.view.ViewGroup;
18
-
19
17
  import androidx.annotation.NonNull;
20
-
21
18
  import com.facebook.react.bridge.ReactContext;
22
19
  import com.facebook.react.uimanager.UIManagerModule;
20
+ import com.facebook.react.views.view.ReactViewGroup;
23
21
 
24
- import java.util.ArrayList;
25
- import java.util.List;
22
+ import java.lang.reflect.Method;
26
23
  import java.util.concurrent.CountDownLatch;
27
24
  import java.util.concurrent.TimeUnit;
28
25
 
@@ -42,143 +39,134 @@ public class ViewScreenshotService {
42
39
  return null;
43
40
  }
44
41
 
45
- // Measure and get size of view
46
42
  int width = view.getWidth();
47
43
  int height = view.getHeight();
48
-
49
44
  if (width <= 0 || height <= 0) {
50
45
  return null;
51
46
  }
52
47
 
53
- // The following code is taken from react-native-view-shot to be able to handle and
54
- // correctly render all kinds of views, also including TextureViews and SurfaceViews
55
48
  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
49
+ final Canvas canvas = new Canvas(bitmap);
50
+ final Paint paint = createPaint();
51
+
52
+ canvas.save();
53
+ canvas.translate(-view.getLeft(), -view.getTop());
54
+ renderViewToCanvas(canvas, view, paint, 1.0f); // Initial opacity
55
+ canvas.restore();
56
+
57
+ return bitmap;
58
+ }
56
59
 
60
+ private static Paint createPaint() {
57
61
  final Paint paint = new Paint();
58
62
  paint.setAntiAlias(true);
59
63
  paint.setFilterBitmap(true);
60
64
  paint.setDither(true);
61
-
62
- // Render the main view and its children
63
- final Canvas canvas = new Canvas(bitmap);
64
-
65
- // Renders view with child views to canvas
66
- renderViewToCanvas(canvas, view, paint);
67
-
68
- return bitmap;
65
+ return paint;
69
66
  }
70
67
 
71
- private static void renderViewToCanvas(Canvas canvas, View view, Paint paint) {
72
- // Apply transformations for the current view
68
+ private static void renderViewToCanvas(Canvas canvas, View view, Paint paint, float parentOpacity) {
69
+ float combinedOpacity = parentOpacity * view.getAlpha();
73
70
  canvas.save();
74
71
  applyTransformations(canvas, view);
75
72
 
76
- // Draw children if the view has children
77
- if ((view instanceof ViewGroup)) {
78
- // Draw children
73
+ if (view instanceof ViewGroup) {
79
74
  ViewGroup group = (ViewGroup) view;
75
+ drawBackgroundIfPresent(canvas, view, combinedOpacity);
76
+ drawChildren(canvas, group, paint, combinedOpacity);
77
+ } else {
78
+ drawView(canvas, view, paint, combinedOpacity);
79
+ }
80
80
 
81
- // Hide visible children - this needs to be done because view.draw(canvas)
82
- // will render all visible non-texture/surface views directly - causing
83
- // views to be rendered twice - once by view.draw() and once when we
84
- // enumerate children. We therefore need to turn off rendering of visible
85
- // children before we call view.draw:
86
- List<View> visibleChildren = new ArrayList<>();
87
- for (int i = 0; i < group.getChildCount(); i++) {
88
- View child = group.getChildAt(i);
89
- if (child.getVisibility() == VISIBLE) {
90
- visibleChildren.add(child);
91
- child.setVisibility(View.INVISIBLE);
92
- }
93
- }
81
+ canvas.restore();
82
+ }
94
83
 
95
- // Draw ourselves
96
- canvas.saveLayerAlpha(null, Math.round(view.getAlpha() * 255));
97
- view.draw(canvas);
84
+ private static void drawBackgroundIfPresent(Canvas canvas, View view, float opacity) {
85
+ Drawable bg = view.getBackground();
86
+ if (bg != null) {
87
+ canvas.saveLayerAlpha(null, Math.round(opacity * 255));
88
+ bg.draw(canvas);
98
89
  canvas.restore();
90
+ }
91
+ }
99
92
 
100
- // Enable children again
101
- for (int i = 0; i < visibleChildren.size(); i++) {
102
- View child = visibleChildren.get(i);
103
- child.setVisibility(VISIBLE);
93
+ private static void drawChildren(Canvas canvas, ViewGroup group, Paint paint, float parentOpacity) {
94
+ // Handle clipping for ReactViewGroup
95
+ if (group instanceof ReactViewGroup) {
96
+ try {
97
+ Class[] cArg = new Class[1];
98
+ cArg[0] = Canvas.class;
99
+ Method method = ReactViewGroup.class.getDeclaredMethod("dispatchOverflowDraw", cArg);
100
+ method.setAccessible(true);
101
+ method.invoke(group, canvas);
102
+ } catch (Exception e) {
103
+ Log.e(TAG, "couldn't invoke dispatchOverflowDraw() on ReactViewGroup", e);
104
104
  }
105
+ }
106
+ for (int i = 0; i < group.getChildCount(); i++) {
107
+ View child = group.getChildAt(i);
108
+ if (child.getVisibility() != View.VISIBLE) continue;
109
+
110
+ if (child instanceof TextureView) {
111
+ drawTextureView(canvas, (TextureView) child, paint, parentOpacity);
112
+ } else if (child instanceof SurfaceView) {
113
+ drawSurfaceView(canvas, (SurfaceView) child, paint, parentOpacity);
114
+ } else {
115
+ renderViewToCanvas(canvas, child, paint, parentOpacity);
116
+ }
117
+ }
118
+ }
105
119
 
106
- // Draw children
107
- for (int i = 0; i < group.getChildCount(); i++) {
108
- View child = group.getChildAt(i);
109
-
110
- // skip all invisible to user child views
111
- if (child.getVisibility() != VISIBLE) continue;
120
+ private static void drawView(Canvas canvas, View view, Paint paint, float opacity) {
121
+ canvas.saveLayerAlpha(null, Math.round(opacity * 255));
122
+ view.draw(canvas);
123
+ canvas.restore();
124
+ }
112
125
 
113
- // skip any child that we don't know how to process
114
- if (child instanceof TextureView) {
115
- final TextureView tvChild = (TextureView) child;
116
- tvChild.setOpaque(false); // <-- switch off background fill
126
+ private static void drawTextureView(Canvas canvas, TextureView tv, Paint paint, float opacity) {
127
+ tv.setOpaque(false);
128
+ Bitmap childBitmapBuffer = tv.getBitmap(Bitmap.createBitmap(tv.getWidth(), tv.getHeight(), Bitmap.Config.ARGB_8888));
129
+ canvas.save();
130
+ applyTransformations(canvas, tv);
131
+ paint.setAlpha(Math.round(opacity * 255)); // Set paint alpha based on opacity
132
+ canvas.drawBitmap(childBitmapBuffer, 0, 0, paint);
133
+ canvas.restore();
134
+ }
117
135
 
136
+ private static void drawSurfaceView(Canvas canvas, SurfaceView sv, Paint paint, float opacity) {
137
+ final CountDownLatch latch = new CountDownLatch(1);
138
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
139
+ Bitmap childBitmapBuffer = Bitmap.createBitmap(sv.getWidth(), sv.getHeight(), Bitmap.Config.ARGB_8888);
140
+ try {
141
+ PixelCopy.request(sv, childBitmapBuffer, copyResult -> {
118
142
  canvas.save();
119
- applyTransformations(canvas, child);
120
-
121
- // TextureView should use bitmaps with matching size,
122
- // otherwise content of the TextureView will be scaled to provided bitmap dimensions
123
- final Bitmap childBitmapBuffer = tvChild.getBitmap(Bitmap.createBitmap(child.getWidth(), child.getHeight(), Bitmap.Config.ARGB_8888));
143
+ applyTransformations(canvas, sv);
144
+ paint.setAlpha(Math.round(opacity * 255)); // Set paint alpha based on opacity
124
145
  canvas.drawBitmap(childBitmapBuffer, 0, 0, paint);
125
-
126
146
  canvas.restore();
127
-
128
- } else if (child instanceof SurfaceView) {
129
- final SurfaceView svChild = (SurfaceView) child;
130
- final CountDownLatch latch = new CountDownLatch(1);
131
-
132
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
133
- final Bitmap childBitmapBuffer = Bitmap.createBitmap(child.getWidth(), child.getHeight(), Bitmap.Config.ARGB_8888);
134
- try {
135
- PixelCopy.request(svChild, childBitmapBuffer, copyResult -> {
136
- canvas.save();
137
- applyTransformations(canvas, child);
138
- canvas.drawBitmap(childBitmapBuffer, 0, 0, paint);
139
- canvas.restore();
140
- latch.countDown();
141
- }, new Handler(Looper.getMainLooper()));
142
- latch.await(SURFACE_VIEW_READ_PIXELS_TIMEOUT, TimeUnit.SECONDS);
143
- } catch (Exception e) {
144
- Log.e(TAG, "Cannot PixelCopy for " + svChild, e);
145
- }
146
- } else {
147
- Bitmap cache = svChild.getDrawingCache();
148
- if (cache != null) {
149
- canvas.save();
150
- applyTransformations(canvas, child);
151
- canvas.drawBitmap(svChild.getDrawingCache(), 0, 0, paint);
152
- canvas.restore();
153
- }
154
- }
155
- } else {
156
- // Regular views needs to be rendered again to ensure correct z-index
157
- // order with texture views and surface views.
158
- renderViewToCanvas(canvas, child, paint);
159
- }
147
+ latch.countDown();
148
+ }, new Handler(Looper.getMainLooper()));
149
+ latch.await(SURFACE_VIEW_READ_PIXELS_TIMEOUT, TimeUnit.SECONDS);
150
+ } catch (Exception e) {
151
+ Log.e(TAG, "Cannot PixelCopy for " + sv, e);
160
152
  }
161
153
  } else {
162
- // Draw ourselves
163
- view.draw(canvas);
154
+ Bitmap cache = sv.getDrawingCache();
155
+ if (cache != null) {
156
+ canvas.save();
157
+ applyTransformations(canvas, sv);
158
+ paint.setAlpha(Math.round(opacity * 255)); // Set paint alpha based on opacity
159
+ canvas.drawBitmap(cache, 0, 0, paint);
160
+ canvas.restore();
161
+ }
164
162
  }
165
-
166
- // Restore canvas
167
- canvas.restore();
168
163
  }
169
164
 
170
165
  @NonNull
171
166
  private static void applyTransformations(final Canvas c, @NonNull final View view) {
172
- // Get the transformation matrix of the view
173
167
  final Matrix matrix = view.getMatrix();
174
-
175
- // Create a new matrix for translation
176
168
  final Matrix translateMatrix = new Matrix();
177
- final float dx = view.getLeft() + view.getPaddingLeft();
178
- final float dy = view.getTop() + view.getPaddingTop();
179
- translateMatrix.setTranslate(dx, dy);
180
-
181
- // Pre-concatenate the current matrix of the canvas with the translation and transformation matrices of the view
169
+ translateMatrix.setTranslate(view.getLeft() + view.getPaddingLeft(), view.getTop() + view.getPaddingTop());
182
170
  c.concat(translateMatrix);
183
171
  c.concat(matrix);
184
172
  }
@@ -7,7 +7,7 @@
7
7
  #include <jsi/jsi.h>
8
8
  #include <string>
9
9
 
10
- #ifdef ANDROID
10
+ #if defined(ANDROID) || defined(__ANDROID__)
11
11
  #include <android/log.h>
12
12
  #endif
13
13
 
@@ -26,7 +26,7 @@ public:
26
26
  * @param message Message to be written out
27
27
  */
28
28
  static void logToConsole(std::string message) {
29
- #ifdef ANDROID
29
+ #if defined(ANDROID) || defined(__ANDROID__)
30
30
  __android_log_write(ANDROID_LOG_INFO, "RNSkia", message.c_str());
31
31
  #endif
32
32
 
@@ -46,7 +46,7 @@ public:
46
46
 
47
47
  static char buffer[512];
48
48
  vsnprintf(buffer, sizeof(buffer), fmt, args);
49
- #ifdef ANDROID
49
+ #if defined(ANDROID) || defined(__ANDROID__)
50
50
  __android_log_write(ANDROID_LOG_INFO, "RNSkia", buffer);
51
51
  #endif
52
52
  #ifdef TARGET_OS_IPHONE
@@ -105,12 +105,6 @@ class JsiSkImage extends _Host.HostObject {
105
105
 
106
106
  readPixels(srcX, srcY, imageInfo) {
107
107
  const info = this.getImageInfo();
108
- console.log({
109
- alphaType: (0, _Host.ckEnum)(info.alphaType),
110
- colorType: (0, _Host.ckEnum)(info.colorType),
111
- realAlphaType: this.CanvasKit.AlphaType.Opaque.value,
112
- realColorType: this.CanvasKit.ColorType.RGBA_8888.value
113
- });
114
108
  const pxInfo = {
115
109
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
116
110
  width: (imageInfo === null || imageInfo === void 0 ? void 0 : imageInfo.width) ?? info.width,
@@ -1 +1 @@
1
- {"version":3,"names":["toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","String","fromCharCode","apply","btoa","JsiSkImage","HostObject","constructor","CanvasKit","ref","delete","height","width","getImageInfo","info","colorType","value","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","JsiSkShader","ckEnum","JsiSkMatrix","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","console","log","realAlphaType","AlphaType","Opaque","realColorType","ColorType","RGBA_8888","pxInfo","colorSpace","ColorSpace","SRGB","getCkEnum","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 console.log({\n alphaType: ckEnum(info.alphaType),\n colorType: ckEnum(info.colorType),\n realAlphaType: this.CanvasKit.AlphaType.Opaque.value,\n realColorType: this.CanvasKit.ColorType.RGBA_8888.value,\n });\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;;AACA;;AACA;;;;AAEA;AACO,MAAMA,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;;;;AAwBA,MAAMQ,UAAN,SAAyBC,gBAAzB,CAAuE;EAC5EC,WAAW,CAACC,SAAD,EAAuBC,GAAvB,EAAmC;IAC5C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AAG;MAC1BC,UAAU,EAAE,KAAK1C,SAAL,CAAe2C,UAAf,CAA0BC,IADZ;MAE1BxC,KAAK,EAAE,CAAA4B,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE5B,KAAX,KAAoBE,IAAI,CAACF,KAFN;MAG1BD,MAAM,EAAE,CAAA6B,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE7B,MAAX,KAAqBG,IAAI,CAACH,MAHR;MAI1BM,SAAS,EAAE,IAAAoC,eAAA,EACT,KAAK7C,SAAL,CAAeoC,SADN,EAET,CAACJ,SAAS,IAAI1B,IAAd,EAAoBG,SAFX,CAJe;MAQ1BF,SAAS,EAAE,IAAAsC,eAAA,EACT,KAAK7C,SAAL,CAAeuC,SADN,EAET,CAACP,SAAS,IAAI1B,IAAd,EAAoBC,SAFX;IARe,CAA5B;IAaA,OAAO,KAAKN,GAAL,CAAS4B,UAAT,CAAoBC,IAAI,IAAI,CAA5B,EAA+BC,IAAI,IAAI,CAAvC,EAA0CU,MAA1C,CAAP;EACD;;EAMDK,mBAAmB,GAAY;IAC7B,OAAO,IAAIjD,UAAJ,CACL,KAAKG,SADA,EAEL,KAAKA,SAAL,CAAe+C,oBAAf,CAAoC,KAAKvB,aAAL,EAApC,CAFK,CAAP;EAID;;AAlH2E"}
1
+ {"version":3,"names":["toBase64String","bytes","Buffer","from","toString","CHUNK_SIZE","index","length","result","slice","Math","min","String","fromCharCode","apply","btoa","JsiSkImage","HostObject","constructor","CanvasKit","ref","delete","height","width","getImageInfo","info","colorType","value","alphaType","makeShaderOptions","tx","ty","fm","mm","localMatrix","JsiSkShader","ckEnum","JsiSkMatrix","fromValue","undefined","makeShaderCubic","B","C","encodeToBytes","fmt","quality","Error","encodeToBase64","readPixels","srcX","srcY","imageInfo","pxInfo","colorSpace","ColorSpace","SRGB","getCkEnum","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;;AACA;;AACA;;;;AAEA;AACO,MAAMA,cAAc,GAAIC,KAAD,IAAuB;EACnD,IAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;IACjC;IACA,OAAOA,MAAM,CAACC,IAAP,CAAY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HostObject {
94
94
  var _imageInfo$width, _imageInfo$height;
95
95
 
96
96
  const info = this.getImageInfo();
97
- console.log({
98
- alphaType: ckEnum(info.alphaType),
99
- colorType: ckEnum(info.colorType),
100
- realAlphaType: this.CanvasKit.AlphaType.Opaque.value,
101
- realColorType: this.CanvasKit.ColorType.RGBA_8888.value
102
- });
103
97
  const pxInfo = {
104
98
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
105
99
  width: (_imageInfo$width = imageInfo === null || imageInfo === void 0 ? void 0 : imageInfo.width) !== null && _imageInfo$width !== void 0 ? _imageInfo$width : info.width,
@@ -1 +1 @@
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","console","log","realAlphaType","AlphaType","Opaque","realColorType","ColorType","RGBA_8888","pxInfo","colorSpace","ColorSpace","SRGB","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 console.log({\n alphaType: ckEnum(info.alphaType),\n colorType: ckEnum(info.colorType),\n realAlphaType: this.CanvasKit.AlphaType.Opaque.value,\n realColorType: this.CanvasKit.ColorType.RGBA_8888.value,\n });\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;M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P;EACD;;EAMDI,mBAAmB,GAAY;IAC7B,OAAO,IAAI5C,UAAJ,CACL,KAAKE,SADA,EAEL,KAAKA,SAAL,CAAe2C,oBAAf,CAAoC,KAAKtB,aAAL,EAApC,CAFK,CAAP;EAID;;AAlH2E"}
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;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,SAAF,uBAAEA,SAAS,CAAE1B,MAAb,iEAAuBG,IAAI,CAACH,MAHR;MAI1BM,SAAS,EAAE/B,SAAS,CAClB,KAAKsB,SAAL,CAAekC,SADG,EAElB,CAACL,SAAD,aAACA,SAAD,cAACA,SAAD,GAAcvB,IAAd,EAAoBG,SAFF,CAJM;MAQ1BF,SAAS,EAAE7B,SAAS,CAClB,KAAKsB,SAAL,CAAemC,SADG,EAElB,CAACN,SAAD,aAACA,SAAD,cAACA,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"}
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.221",
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": [
@@ -127,12 +127,6 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
127
127
 
128
128
  readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo) {
129
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
130
  const pxInfo: CKImageInfo = {
137
131
  colorSpace: this.CanvasKit.ColorSpace.SRGB,
138
132
  width: imageInfo?.width ?? info.width,