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

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

Issue 10799014: Add support for PNG representation in gfx::Image (Closed) Base URL: http://git.chromium.org/chromium/src.git@bookmark-sync
Patch Set: Created 8 years, 5 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/image/image.h"
6
7 #import <AppKit/AppKit.h>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_nsobject.h"
11
12 namespace gfx {
13 namespace internal {
14
15 void PNGFromNSImage(NSImage* nsimage, std::vector<unsigned char>* png) {
16 CGImageRef cgimage = [nsimage CGImageForProposedRect:NULL
Robert Sesek 2012/07/24 18:59:17 These functions should only be indented 2 spaces.
Robert Sesek 2012/07/24 18:59:17 Why do you need to go through CGImage? Can you not
cjhopman 2012/07/25 21:13:29 Done.
cjhopman 2012/07/25 21:13:29 I really don't know about this stuff, so here's so
Robert Sesek 2012/07/31 14:07:16 Thanks for the links. This looks right, then.
17 context:nil
18 hints:nil];
19 scoped_nsobject<NSBitmapImageRep> nsbitmap(
Robert Sesek 2012/07/24 18:59:17 naming: ns_bitmap and cg_image
cjhopman 2012/07/25 21:13:29 Done.
20 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]);
21 NSData* nsdata = [nsbitmap representationUsingType:NSPNGFileType
22 properties:nil];
23 const unsigned char* bytes =
24 static_cast<const unsigned char*>([nsdata bytes]);
25 png->assign(bytes, bytes + [nsdata length]);
26 }
27
28 NSImage* NSImageFromPNG(const std::vector<unsigned char>& png) {
29 scoped_nsobject<NSData> nsdata(
30 [[NSData alloc] initWithBytes:&png.front()
31 length:png.size()]);
32 scoped_nsobject<NSImage> image([[NSImage alloc] initWithData:nsdata]);
33 if (!image) {
34 LOG(WARNING) << "Unable to decode PNG, returning empty bitmap.";
35 image.reset([[NSImage alloc] initWithSize:NSMakeSize(1, 1)]);
36 }
37 return image.release();
38 }
39
40 } // namespace internal
41 } // namespace gfx
42
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698