From 878d25e91eac68605b5a90b22a3274f3655301b6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 Feb 2015 14:31:51 +0800 Subject: [PATCH] Enable converting gfx::Image to Buffer --- .../native_mate_converters/image_converter.cc | 16 +++++++++++++--- .../native_mate_converters/image_converter.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/atom/common/native_mate_converters/image_converter.cc b/atom/common/native_mate_converters/image_converter.cc index 8de73db306d..2c991b9236c 100644 --- a/atom/common/native_mate_converters/image_converter.cc +++ b/atom/common/native_mate_converters/image_converter.cc @@ -16,10 +16,12 @@ #include "ui/gfx/image/image_skia.h" #include "ui/base/layout.h" -#if !defined(OS_MACOSX) +#include "atom/common/node_includes.h" namespace mate { +#if !defined(OS_MACOSX) + namespace { struct ScaleFactorPair { @@ -122,6 +124,14 @@ bool Converter::FromV8(v8::Isolate* isolate, return true; } -} // namespace mate - #endif // !defined(OS_MACOSX) + +v8::Handle Converter::ToV8(v8::Isolate* isolate, + const gfx::Image& val) { + scoped_refptr png = val.As1xPNGBytes(); + return node::Buffer::New(isolate, + reinterpret_cast(png->front()), + png->size()); +} + +} // namespace mate diff --git a/atom/common/native_mate_converters/image_converter.h b/atom/common/native_mate_converters/image_converter.h index 738b50ad741..1b1a12c3ae0 100644 --- a/atom/common/native_mate_converters/image_converter.h +++ b/atom/common/native_mate_converters/image_converter.h @@ -26,6 +26,8 @@ struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Handle val, gfx::Image* out); + static v8::Handle ToV8(v8::Isolate* isolate, + const gfx::Image& val); }; } // namespace mate