2015-02-11 08:03:19 +00:00
|
|
|
// 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_
|
|
|
|
|
2015-02-12 06:32:51 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-02-11 08:03:19 +00:00
|
|
|
#include "native_mate/handle.h"
|
|
|
|
#include "native_mate/wrappable.h"
|
|
|
|
#include "ui/gfx/image/image.h"
|
|
|
|
|
2015-02-12 06:27:53 +00:00
|
|
|
class GURL;
|
|
|
|
|
2015-02-11 10:41:06 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2015-02-11 08:49:43 +00:00
|
|
|
namespace gfx {
|
|
|
|
class Size;
|
|
|
|
}
|
|
|
|
|
2015-02-12 07:19:05 +00:00
|
|
|
namespace mate {
|
|
|
|
class Arguments;
|
|
|
|
}
|
|
|
|
|
2015-02-11 08:03:19 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
class NativeImage : public mate::Wrappable {
|
|
|
|
public:
|
2015-02-12 05:55:45 +00:00
|
|
|
static mate::Handle<NativeImage> CreateEmpty(v8::Isolate* isolate);
|
2015-02-11 10:02:59 +00:00
|
|
|
static mate::Handle<NativeImage> Create(
|
|
|
|
v8::Isolate* isolate, const gfx::Image& image);
|
|
|
|
static mate::Handle<NativeImage> CreateFromPNG(
|
2015-02-12 06:27:53 +00:00
|
|
|
v8::Isolate* isolate, const char* buffer, size_t length);
|
2015-02-11 10:02:59 +00:00
|
|
|
static mate::Handle<NativeImage> CreateFromJPEG(
|
2015-02-12 06:27:53 +00:00
|
|
|
v8::Isolate* isolate, const char* buffer, size_t length);
|
2015-02-11 10:41:06 +00:00
|
|
|
static mate::Handle<NativeImage> CreateFromPath(
|
|
|
|
v8::Isolate* isolate, const base::FilePath& path);
|
2015-02-12 07:19:05 +00:00
|
|
|
static mate::Handle<NativeImage> CreateFromBuffer(
|
2015-05-22 11:11:22 +00:00
|
|
|
mate::Arguments* args, v8::Local<v8::Value> buffer);
|
2015-02-12 06:27:53 +00:00
|
|
|
static mate::Handle<NativeImage> CreateFromDataURL(
|
|
|
|
v8::Isolate* isolate, const GURL& url);
|
2015-02-11 08:03:19 +00:00
|
|
|
|
2015-02-11 11:22:41 +00:00
|
|
|
// The default constructor should only be used by image_converter.cc.
|
|
|
|
NativeImage();
|
|
|
|
|
|
|
|
const gfx::Image& image() const { return image_; }
|
|
|
|
|
2015-02-11 08:03:19 +00:00
|
|
|
protected:
|
2015-02-11 10:02:59 +00:00
|
|
|
explicit NativeImage(const gfx::Image& image);
|
2015-02-11 08:03:19 +00:00
|
|
|
virtual ~NativeImage();
|
|
|
|
|
|
|
|
// mate::Wrappable:
|
|
|
|
mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
|
|
|
|
private:
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
|
|
|
|
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
2015-02-12 06:32:51 +00:00
|
|
|
std::string ToDataURL();
|
2015-02-11 08:49:43 +00:00
|
|
|
bool IsEmpty();
|
|
|
|
gfx::Size GetSize();
|
2015-02-11 08:03:19 +00:00
|
|
|
|
2015-04-13 03:53:24 +00:00
|
|
|
// Mark the image as template image.
|
|
|
|
void SetTemplateImage(bool setAsTemplate);
|
|
|
|
|
2015-02-11 08:03:19 +00:00
|
|
|
gfx::Image image_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NativeImage);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_COMMON_API_ATOM_API_NATIVE_IMAGE_H_
|