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 = | 20 NSSize imageRepSize = [imageRep size]; |
21 NSMakeSize([imageRep pixelsWide], [imageRep pixelsHigh]); | |
22 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false)); | 21 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false)); |
23 if (!bitmap.isNull() && !bitmap.empty()) { | 22 if (!bitmap.isNull() && !bitmap.empty()) { |
24 float scaleFactor = imageRepSize.width / [image size].width; | 23 float scaleFactor = imageRepSize.width / [image size].width; |
25 image_skia.AddBitmapForScale(bitmap, scaleFactor); | 24 image_skia.AddBitmapForScale(bitmap, scaleFactor); |
26 } | 25 } |
27 } | 26 } |
28 return image_skia; | 27 return image_skia; |
29 } | 28 } |
30 | 29 |
31 NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { | 30 NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { |
32 if (image_skia->empty()) | 31 if (image_skia->empty()) |
33 return nil; | 32 return nil; |
34 | 33 |
35 scoped_nsobject<NSImage> image([[NSImage alloc] init]); | 34 scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
36 | 35 |
37 const std::vector<SkBitmap> bitmaps = image_skia->bitmaps(); | 36 const std::vector<SkBitmap> bitmaps = image_skia->bitmaps(); |
38 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); | 37 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); |
39 it != bitmaps.end(); ++it) { | 38 it != bitmaps.end(); ++it) { |
40 [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; | 39 [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; |
41 } | 40 } |
42 | 41 |
43 [image setSize:NSMakeSize(image_skia->width(), image_skia->height())]; | 42 [image setSize:NSMakeSize(image_skia->width(), image_skia->height())]; |
44 return [image.release() autorelease]; | 43 return [image.release() autorelease]; |
45 } | 44 } |
46 | 45 |
47 } // namespace internal | 46 } // namespace internal |
48 } // namespace gfx | 47 } // namespace gfx |
OLD | NEW |