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

Side by Side Diff: skia/ext/skia_utils_mac.mm

Issue 6117006: Mac: Explicitly set the colorspace on SkBitmap -> CGImageRef conversions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 11 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
« skia/ext/skia_utils_mac.h ('K') | « skia/ext/skia_utils_mac.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "skia/ext/skia_utils_mac.h" 5 #include "skia/ext/skia_utils_mac.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 fromRect:NSZeroRect 160 fromRect:NSZeroRect
161 operation:NSCompositeCopy 161 operation:NSCompositeCopy
162 fraction:1.0]; 162 fraction:1.0];
163 163
164 // Done drawing, restore context. 164 // Done drawing, restore context.
165 [NSGraphicsContext restoreGraphicsState]; 165 [NSGraphicsContext restoreGraphicsState];
166 166
167 return bitmap; 167 return bitmap;
168 } 168 }
169 169
170 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { 170 NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap,
171 CGColorSpaceRef colorSpace) {
171 if (skiaBitmap.isNull()) 172 if (skiaBitmap.isNull())
172 return nil; 173 return nil;
173 174
174 // First convert SkBitmap to CGImageRef. 175 // First convert SkBitmap to CGImageRef.
175 CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap); 176 CGImageRef cgimage = SkCreateCGImageRefWithColorspace(
177 skiaBitmap, colorSpace);
viettrungluu 2011/01/12 19:02:11 I believe you can format this more nicely.
176 178
177 // Now convert to NSImage. 179 // Now convert to NSImage.
178 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] 180 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
179 initWithCGImage:cgimage] autorelease]; 181 initWithCGImage:cgimage] autorelease];
180 CFRelease(cgimage); 182 CFRelease(cgimage);
181 NSImage* image = [[[NSImage alloc] init] autorelease]; 183 NSImage* image = [[[NSImage alloc] init] autorelease];
182 [image addRepresentation:bitmap]; 184 [image addRepresentation:bitmap];
183 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; 185 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())];
184 return image; 186 return image;
185 } 187 }
186 188
189 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) {
viettrungluu 2011/01/12 19:02:11 Do you put implementations in random order just to
190 base::mac::ScopedCFTypeRef<CGColorSpaceRef> colorSpace(
191 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
192 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get());
193 }
194
187 SkBitmap AppplicationIconAtSize(int size) { 195 SkBitmap AppplicationIconAtSize(int size) {
188 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; 196 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
189 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); 197 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true);
190 } 198 }
191 199
192 } // namespace gfx 200 } // namespace gfx
OLDNEW
« skia/ext/skia_utils_mac.h ('K') | « skia/ext/skia_utils_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698