#include "base/files/file_util.h"
#include "base/strings/pattern.h"
#include "base/strings/string_util.h"
-#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "net/base/data_url.h"
#include "third_party/skia/include/core/SkPixelRef.h"
new NativeImage(isolate, gfx::Image(cropped)));
}
+void NativeImage::AddRepresentation(const mate::Dictionary& options) {
+ int width = 0;
+ int height = 0;
+ float scale_factor = 1.0f;
+ options.Get("width", &width);
+ options.Get("height", &height);
+ options.Get("scaleFactor", &scale_factor);
+
+ v8::Local<v8::Value> buffer;
+ if (options.Get("buffer", &buffer) && node::Buffer::HasInstance(buffer)) {
+ gfx::ImageSkia image_skia = image_.AsImageSkia();
+ AddImageSkiaRep(
+ &image_skia,
+ reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
+ node::Buffer::Length(buffer),
+ width, height, scale_factor);
+
+ if (IsEmpty()) {
+ gfx::Image image(image_skia);
+ image_.SwapRepresentations(&image);
+ }
+ }
+}
#if !defined(OS_MACOSX)
void NativeImage::SetTemplateImage(bool setAsTemplate) {
.SetMethod("resize", &NativeImage::Resize)
.SetMethod("crop", &NativeImage::Crop)
.SetMethod("getAspectRatio", &NativeImage::GetAspectRatio)
+ .SetMethod("addRepresentation", &NativeImage::AddRepresentation)
// TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
.SetMethod("toPng", &NativeImage::ToPNG)
.SetMethod("toJpeg", &NativeImage::ToJPEG);
#include <string>
#include "base/values.h"
+#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
#include "ui/gfx/geometry/rect.h"
bool IsEmpty();
gfx::Size GetSize();
float GetAspectRatio();
+ void AddRepresentation(const mate::Dictionary& options);
// Mark the image as template image.
void SetTemplateImage(bool setAsTemplate);