This commit is contained in:
Paul Betts 2016-03-13 20:18:03 -07:00
parent 5dea4b9b1c
commit 7233c83874
2 changed files with 14 additions and 9 deletions

View file

@ -198,7 +198,8 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate) template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
.SetMethod("toPng", &NativeImage::ToPNG) .SetMethod("toPng", &NativeImage::ToPNG)
.SetMethod("toJpeg", &NativeImage::ToJPEG) .SetMethod("toJpeg", &NativeImage::ToJPEG)
.SetMethod("asNativeRepresentation", &NativeImage::AsNativeRepresentation) .SetMethod("asNativeRepresentation",
&NativeImage::AsNativeRepresentation)
.SetMethod("toDataURL", &NativeImage::ToDataURL) .SetMethod("toDataURL", &NativeImage::ToDataURL)
.SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated. .SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated.
.SetMethod("isEmpty", &NativeImage::IsEmpty) .SetMethod("isEmpty", &NativeImage::IsEmpty)
@ -236,28 +237,30 @@ std::string NativeImage::ToDataURL() {
return data_url; return data_url;
} }
v8::Local<v8::Value> NativeImage::AsNativeRepresentation(v8::Isolate* isolate, mate::Arguments* args) { v8::Local<v8::Value> NativeImage::AsNativeRepresentation(
v8::Isolate* isolate,
mate::Arguments* args) {
NativeRepresentation desiredRep = NativeRepresentation::INVALID; NativeRepresentation desiredRep = NativeRepresentation::INVALID;
void* ptr = nullptr; void* ptr = nullptr;
std::string type; std::string type;
if (!args->GetNext(&type)) { if (!args->GetNext(&type)) {
args->ThrowError(); args->ThrowError();
goto out; goto out;
} }
for (const NativeRepresentationPair& item : kNativeRepresentations) { for (const NativeRepresentationPair& item : kNativeRepresentations) {
if (type.compare(item.name) == 0) { if (type.compare(item.name) == 0) {
desiredRep = item.rep; desiredRep = item.rep;
break; break;
} }
} }
if (desiredRep == NativeRepresentation::INVALID) { if (desiredRep == NativeRepresentation::INVALID) {
args->ThrowError(); args->ThrowError();
goto out; goto out;
} }
switch (desiredRep) { switch (desiredRep) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
case NativeRepresentation::AS_NSIMAGE: case NativeRepresentation::AS_NSIMAGE:
@ -268,9 +271,9 @@ v8::Local<v8::Value> NativeImage::AsNativeRepresentation(v8::Isolate* isolate, m
args->ThrowError(); args->ThrowError();
break; break;
} }
out: out:
return node::Buffer::Copy( return node::Buffer::Copy(
isolate, isolate,
reinterpret_cast<char*>(ptr), reinterpret_cast<char*>(ptr),

View file

@ -61,7 +61,9 @@ class NativeImage : public mate::Wrappable {
private: private:
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate); v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality); v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
v8::Local<v8::Value> AsNativeRepresentation(v8::Isolate* isolate, mate::Arguments* args); v8::Local<v8::Value> AsNativeRepresentation(
v8::Isolate* isolate,
mate::Arguments* args);
std::string ToDataURL(); std::string ToDataURL();
bool IsEmpty(); bool IsEmpty();
gfx::Size GetSize(); gfx::Size GetSize();