image_converter.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/common/native_mate_converters/image_converter.h"
  5. #include "atom/common/api/atom_api_native_image.h"
  6. #include "atom/common/native_mate_converters/file_path_converter.h"
  7. #include "ui/gfx/image/image_skia.h"
  8. namespace mate {
  9. bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
  10. v8::Local<v8::Value> val,
  11. gfx::ImageSkia* out) {
  12. gfx::Image image;
  13. if (!ConvertFromV8(isolate, val, &image))
  14. return false;
  15. *out = image.AsImageSkia();
  16. return true;
  17. }
  18. bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
  19. v8::Local<v8::Value> val,
  20. gfx::Image* out) {
  21. if (val->IsNull())
  22. return true;
  23. Handle<atom::api::NativeImage> native_image;
  24. if (!ConvertFromV8(isolate, val, &native_image))
  25. return false;
  26. *out = native_image->image();
  27. return true;
  28. }
  29. v8::Local<v8::Value> Converter<gfx::Image>::ToV8(v8::Isolate* isolate,
  30. const gfx::Image& val) {
  31. return ConvertToV8(isolate, atom::api::NativeImage::Create(isolate, val));
  32. }
  33. } // namespace mate