OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
| 6 #import <vector> |
6 | 7 |
| 8 #include "base/memory/scoped_nsobject.h" |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "ui/gfx/image/image_skia.h" |
10 | 13 |
11 namespace gfx { | 14 namespace gfx { |
12 namespace internal { | 15 namespace internal { |
13 | 16 |
14 bool NSImageToSkBitmaps(NSImage* image, std::vector<const SkBitmap*>* bitmaps) { | 17 bool NSImageToImageSkia(NSImage* image, gfx::ImageSkia* image_skia) { |
15 for (NSImageRep* imageRep in [image representations]) { | 18 for (NSImageRep* imageRep in [image representations]) { |
16 scoped_ptr<SkBitmap> bitmap(new SkBitmap( | 19 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], |
17 gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], false))); | 20 false)); |
18 if (bitmap->isNull()) | 21 if (bitmap.isNull()) |
19 return false; | 22 return false; |
20 bitmaps->push_back(bitmap.release()); | 23 float scale_factor = [imageRep size].width / [image size].width; |
| 24 image_skia->AddBitmapForScale(bitmap, scale_factor); |
21 } | 25 } |
22 return true; | 26 return true; |
23 } | 27 } |
24 | 28 |
| 29 NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { |
| 30 if (image_skia->empty()) |
| 31 return nil; |
| 32 |
| 33 scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
| 34 |
| 35 const std::vector<SkBitmap>& bitmaps = image_skia->bitmaps(); |
| 36 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); |
| 37 it != bitmaps.end(); ++it) { |
| 38 [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; |
| 39 } |
| 40 |
| 41 [image setSize: NSMakeSize(image_skia->width(), image_skia->height())]; |
| 42 return [image.release() autorelease]; |
| 43 } |
| 44 |
25 } // namespace internal | 45 } // namespace internal |
26 } // namespace gfx | 46 } // namespace gfx |
OLD | NEW |