OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import <vector> |
7 | 7 |
8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
11 #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" | 12 #include "ui/gfx/image/image_skia.h" |
13 | 13 |
14 namespace gfx { | 14 namespace gfx { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 gfx::ImageSkia NSImageToImageSkia(NSImage* image) { | 17 gfx::ImageSkia NSImageToImageSkia(NSImage* image) { |
18 gfx::ImageSkia image_skia; | 18 gfx::ImageSkia image_skia; |
19 for (NSImageRep* imageRep in [image representations]) { | 19 for (NSImageRep* imageRep in [image representations]) { |
20 NSSize imageRepSize = [imageRep size]; | 20 NSSize imageRepSize = |
| 21 NSMakeSize([imageRep pixelsWide], [imageRep pixelsHigh]); |
21 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false)); | 22 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false)); |
22 if (!bitmap.isNull() && !bitmap.empty()) { | 23 if (!bitmap.isNull() && !bitmap.empty()) { |
23 float scaleFactor = imageRepSize.width / [image size].width; | 24 float scaleFactor = imageRepSize.width / [image size].width; |
24 image_skia.AddBitmapForScale(bitmap, scaleFactor); | 25 image_skia.AddBitmapForScale(bitmap, scaleFactor); |
25 } | 26 } |
26 } | 27 } |
27 return image_skia; | 28 return image_skia; |
28 } | 29 } |
29 | 30 |
30 NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { | 31 NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { |
31 if (image_skia->empty()) | 32 if (image_skia->empty()) |
32 return nil; | 33 return nil; |
33 | 34 |
34 scoped_nsobject<NSImage> image([[NSImage alloc] init]); | 35 scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
35 | 36 |
36 const std::vector<SkBitmap> bitmaps = image_skia->bitmaps(); | 37 const std::vector<SkBitmap> bitmaps = image_skia->bitmaps(); |
37 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); | 38 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); |
38 it != bitmaps.end(); ++it) { | 39 it != bitmaps.end(); ++it) { |
39 [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; | 40 [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; |
40 } | 41 } |
41 | 42 |
42 [image setSize:NSMakeSize(image_skia->width(), image_skia->height())]; | 43 [image setSize:NSMakeSize(image_skia->width(), image_skia->height())]; |
43 return [image.release() autorelease]; | 44 return [image.release() autorelease]; |
44 } | 45 } |
45 | 46 |
46 } // namespace internal | 47 } // namespace internal |
47 } // namespace gfx | 48 } // namespace gfx |
OLD | NEW |