}
#endif
+void Noop(char*, void*) {
+}
+
} // namespace
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
bitmap->getSafeSize()).ToLocalChecked();
}
-void noop(char*, void*) {}
-
-v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
- const SkBitmap* bitmap = image_.ToSkBitmap();
- SkPixelRef* ref = bitmap->pixelRef();
- return node::Buffer::New(isolate,
- reinterpret_cast<char*>(ref->pixels()),
- bitmap->getSafeSize(),
- &noop,
- nullptr).ToLocalChecked();
-}
-
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
std::vector<unsigned char> output;
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
return data_url;
}
+v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
+ const SkBitmap* bitmap = image_.ToSkBitmap();
+ SkPixelRef* ref = bitmap->pixelRef();
+ return node::Buffer::New(isolate,
+ reinterpret_cast<char*>(ref->pixels()),
+ bitmap->getSafeSize(),
+ &Noop,
+ nullptr).ToLocalChecked();
+}
+
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
mate::Arguments* args) {
#if defined(OS_MACOSX)
#### `image.toBitmap()`
-Returns a [Buffer][buffer] that contains a copy of the image's raw pixel data.
+Returns a [Buffer][buffer] that contains a copy of the image's raw bitmap pixel
+data.
#### `image.toDataURL()`
#### `image.getBitmap()`
-Returns a [Buffer][buffer] that contains the image's raw pixel data. The pixel
-data is not owned by the `Buffer` object.
+Returns a [Buffer][buffer] that contains the image's raw bitmap pixel data.
+
+The difference between `getBitmap()` and `toBitmap()` is, `getBitmap()` does not
+copy the bitmap data, so you have to use the returned Buffer immediately in
+current event loop tick, otherwise the data might be changed or destroyed.
#### `image.getNativeHandle()` _macOS_