From 21962be60e181ca1a49eba5e8a09ef56046988f3 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 31 Jul 2016 05:11:18 +0200 Subject: [PATCH] Adds option to get raw data from NativeImage --- atom/common/api/atom_api_native_image.cc | 10 ++++++++++ atom/common/api/atom_api_native_image.h | 1 + 2 files changed, 11 insertions(+) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 10a1c18..63501ab 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -25,6 +25,7 @@ #include "ui/gfx/geometry/size.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_util.h" +#include "third_party/skia/include/core/SkPixelRef.h" #if defined(OS_WIN) #include "atom/common/asar/archive.h" @@ -219,6 +220,14 @@ v8::Local NativeImage::ToPNG(v8::Isolate* isolate) { static_cast(png->size())).ToLocalChecked(); } +v8::Local NativeImage::ToRawBuffer(v8::Isolate* isolate) { + const SkBitmap* bitmap = image_.ToSkBitmap(); + SkPixelRef* ref = bitmap->pixelRef(); + return node::Buffer::Copy(isolate, + reinterpret_cast(ref->pixels()), + bitmap->getSafeSize()).ToLocalChecked(); +} + v8::Local NativeImage::ToJPEG(v8::Isolate* isolate, int quality) { std::vector output; gfx::JPEG1xEncodedDataFromImage(image_, quality, &output); @@ -350,6 +359,7 @@ void NativeImage::BuildPrototype( mate::ObjectTemplateBuilder(isolate, prototype) .SetMethod("toPNG", &NativeImage::ToPNG) .SetMethod("toJPEG", &NativeImage::ToJPEG) + .SetMethod("toBUFFER", &NativeImage::ToRawBuffer) .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 de4db4c..d3ddad1 100644 --- a/atom/common/api/atom_api_native_image.h +++ b/atom/common/api/atom_api_native_image.h @@ -70,6 +70,7 @@ class NativeImage : public mate::Wrappable { private: v8::Local ToPNG(v8::Isolate* isolate); v8::Local ToJPEG(v8::Isolate* isolate, int quality); + v8::Local ToRawBuffer(v8::Isolate* isolate); v8::Local GetNativeHandle( v8::Isolate* isolate, mate::Arguments* args); -- 2.7.4