// Copyright (c) 2015 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. #ifndef ATOM_COMMON_API_ATOM_API_NATIVE_IMAGE_H_ #define ATOM_COMMON_API_ATOM_API_NATIVE_IMAGE_H_ #include #include "native_mate/handle.h" #include "native_mate/wrappable.h" #include "ui/gfx/image/image.h" class GURL; namespace base { class FilePath; } namespace gfx { class Size; } namespace mate { class Arguments; } namespace atom { namespace api { class NativeImage : public mate::Wrappable { public: static mate::Handle CreateEmpty(v8::Isolate* isolate); static mate::Handle Create( v8::Isolate* isolate, const gfx::Image& image); static mate::Handle CreateFromPNG( v8::Isolate* isolate, const char* buffer, size_t length); static mate::Handle CreateFromJPEG( v8::Isolate* isolate, const char* buffer, size_t length); static mate::Handle CreateFromPath( v8::Isolate* isolate, const base::FilePath& path); static mate::Handle CreateFromBuffer( mate::Arguments* args, v8::Local buffer); static mate::Handle CreateFromDataURL( v8::Isolate* isolate, const GURL& url); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); const gfx::Image& image() const { return image_; } protected: NativeImage(v8::Isolate* isolate, const gfx::Image& image); ~NativeImage() override; private: v8::Local ToPNG(v8::Isolate* isolate); v8::Local ToJPEG(v8::Isolate* isolate, int quality); v8::Local GetNativeHandle( v8::Isolate* isolate, mate::Arguments* args); std::string ToDataURL(); bool IsEmpty(); gfx::Size GetSize(); // Mark the image as template image. void SetTemplateImage(bool setAsTemplate); // Determine if the image is a template image. bool IsTemplateImage(); gfx::Image image_; DISALLOW_COPY_AND_ASSIGN(NativeImage); }; } // namespace api } // namespace atom #endif // ATOM_COMMON_API_ATOM_API_NATIVE_IMAGE_H_