Index: ui/gfx/image/image_mac.mm |
diff --git a/ui/gfx/image/image_mac.mm b/ui/gfx/image/image_mac.mm |
index 55b4aa4338d23413207c2b66a1da26f1806cac60..68b5a44627df6380e2f326c711fe4f907d1881a2 100644 |
--- a/ui/gfx/image/image_mac.mm |
+++ b/ui/gfx/image/image_mac.mm |
@@ -3,24 +3,44 @@ |
// found in the LICENSE file. |
#import <AppKit/AppKit.h> |
+#import <vector> |
+#include "base/memory/scoped_nsobject.h" |
#include "base/memory/scoped_ptr.h" |
#include "skia/ext/skia_utils_mac.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/gfx/image/image_skia.h" |
namespace gfx { |
namespace internal { |
-bool NSImageToSkBitmaps(NSImage* image, std::vector<const SkBitmap*>* bitmaps) { |
+bool NSImageToImageSkia(NSImage* image, gfx::ImageSkia* image_skia) { |
for (NSImageRep* imageRep in [image representations]) { |
- scoped_ptr<SkBitmap> bitmap(new SkBitmap( |
- gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], false))); |
- if (bitmap->isNull()) |
+ SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], |
+ false)); |
+ if (bitmap.isNull()) |
return false; |
- bitmaps->push_back(bitmap.release()); |
+ float scale_factor = [imageRep size].width / [image size].width; |
+ image_skia->AddBitmapForScale(bitmap, scale_factor); |
} |
return true; |
} |
+NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { |
+ if (image_skia->empty()) |
+ return nil; |
+ |
+ scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
+ |
+ const std::vector<SkBitmap>& bitmaps = image_skia->bitmaps(); |
+ for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); |
+ it != bitmaps.end(); ++it) { |
+ [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; |
+ } |
+ |
+ [image setSize: NSMakeSize(image_skia->width(), image_skia->height())]; |
+ return [image.release() autorelease]; |
+} |
+ |
} // namespace internal |
} // namespace gfx |