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

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

Issue 2592983002: [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: Wait for load in CaptureScreenshotTest to fix android bot. Created 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
Avi (use Gerrit) 2017/01/09 16:57:33 It's 2017.
Eric Seckler 2017/01/11 15:58:44 Done.
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_util.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/mac/scoped_nsobject.h"
10 #include "ui/gfx/image/image.h"
11
12 namespace gfx {
13
14 bool JPEG1xEncodedDataFromImage(const Image& image,
15 int quality,
16 std::vector<unsigned char>* dst) {
17 if (!image.HasRepresentation(gfx::Image::kImageRepCocoa))
18 return JPEG1xEncodedDataFromSkiaRepresentation(image, quality, dst);
19
20 NSImage* nsImage = image.ToNSImage();
21
22 CGImageRef cgImage =
23 [nsImage CGImageForProposedRect:nil context:nil hints:nil];
24 base::scoped_nsobject<NSBitmapImageRep> rep(
25 [[NSBitmapImageRep alloc] initWithCGImage:cgImage]);
26
27 float compressionFactor = quality / 100.0;
28 NSDictionary* options = [NSDictionary
29 dictionaryWithObject:[NSNumber numberWithFloat:compressionFactor]
30 forKey:NSImageCompressionFactor];
Avi (use Gerrit) 2017/01/09 16:57:33 NSDictionary* options = @{ NSImageCompressionFacto
Eric Seckler 2017/01/11 15:58:44 Done.
31 NSData* data =
32 [rep representationUsingType:NSJPEGFileType properties:options];
33
34 if ([data length] == 0)
35 return false;
36
37 dst->resize([data length]);
38 [data getBytes:&dst->at(0) length:[data length]];
39 return true;
40 }
41
42 } // end namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698