Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: ui/gfx/image/image_mac.mm

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 gfx::ImageSkia NSImageToImageSkia(NSImage* image) {
18 gfx::ImageSkia image_skia;
15 for (NSImageRep* imageRep in [image representations]) { 19 for (NSImageRep* imageRep in [image representations]) {
16 scoped_ptr<SkBitmap> bitmap(new SkBitmap( 20 NSSize imageRepSize = [imageRep size];
17 gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], false))); 21 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false));
18 if (bitmap->isNull()) 22 if (!bitmap.isNull() && !bitmap.empty()) {
19 return false; 23 float scaleFactor = imageRepSize.width / [image size].width;
20 bitmaps->push_back(bitmap.release()); 24 image_skia.AddBitmapForScale(bitmap, scaleFactor);
25 }
21 } 26 }
22 return true; 27 return image_skia;
28 }
29
30 NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) {
31 if (image_skia->empty())
32 return nil;
33
34 scoped_nsobject<NSImage> image([[NSImage alloc] init]);
35
36 const std::vector<SkBitmap> bitmaps = image_skia->bitmaps();
37 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin();
38 it != bitmaps.end(); ++it) {
39 [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)];
40 }
41
42 [image setSize:NSMakeSize(image_skia->width(), image_skia->height())];
43 return [image.release() autorelease];
23 } 44 }
24 45
25 } // namespace internal 46 } // namespace internal
26 } // namespace gfx 47 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698