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..7ac0abeb833b52a4a09c54f56da6dbfbdf180165 100644 |
--- a/ui/gfx/image/image_mac.mm |
+++ b/ui/gfx/image/image_mac.mm |
@@ -3,23 +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) { |
+gfx::ImageSkia 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()) |
- return false; |
- bitmaps->push_back(bitmap.release()); |
+ NSSize imageRepSize = [imageRep size]; |
+ SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false)); |
+ if (!bitmap.isNull() && !bitmap.empty()) { |
+ float scaleFactor = imageRepSize.width / [image size].width; |
+ image_skia.AddBitmapForScale(bitmap, scaleFactor); |
+ } |
} |
- return true; |
+ return image_skia; |
+} |
+ |
+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 |