From 37f5ef571225c95518d5fd3b78ba8c4994338cb2 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 4 Aug 2016 19:36:01 +0200 Subject: [PATCH] add getBitmap to NativeImage --- atom/common/api/atom_api_native_image.cc | 13 +++++++++++++ atom/common/api/atom_api_native_image.h | 1 + 2 files changed, 14 insertions(+) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index bd97ea338504..6aeb2fbebb70 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -228,6 +228,18 @@ v8::Local NativeImage::ToBitmap(v8::Isolate* isolate) { bitmap->getSafeSize()).ToLocalChecked(); } +void noop(char*, void*) {} + +v8::Local NativeImage::GetBitmap(v8::Isolate* isolate) { + const SkBitmap* bitmap = image_.ToSkBitmap(); + SkPixelRef* ref = bitmap->pixelRef(); + return node::Buffer::New(isolate, + reinterpret_cast(ref->pixels()), + bitmap->getSafeSize(), + &noop, + nullptr).ToLocalChecked(); +} + v8::Local NativeImage::ToJPEG(v8::Isolate* isolate, int quality) { std::vector output; gfx::JPEG1xEncodedDataFromImage(image_, quality, &output); @@ -361,6 +373,7 @@ void NativeImage::BuildPrototype( .SetMethod("toPNG", &NativeImage::ToPNG) .SetMethod("toJPEG", &NativeImage::ToJPEG) .SetMethod("toBitmap", &NativeImage::ToBitmap) + .SetMethod("getBitmap", &NativeImage::GetBitmap) .SetMethod("getNativeHandle", &NativeImage::GetNativeHandle) .SetMethod("toDataURL", &NativeImage::ToDataURL) .SetMethod("isEmpty", &NativeImage::IsEmpty) diff --git a/atom/common/api/atom_api_native_image.h b/atom/common/api/atom_api_native_image.h index d6fddd10763d..743a3c599b7e 100644 --- a/atom/common/api/atom_api_native_image.h +++ b/atom/common/api/atom_api_native_image.h @@ -71,6 +71,7 @@ class NativeImage : public mate::Wrappable { v8::Local ToPNG(v8::Isolate* isolate); v8::Local ToJPEG(v8::Isolate* isolate, int quality); v8::Local ToBitmap(v8::Isolate* isolate); + v8::Local GetBitmap(v8::Isolate* isolate); v8::Local GetNativeHandle( v8::Isolate* isolate, mate::Arguments* args);