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

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

Issue 2650903003: Revert of [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: 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
« no previous file with comments | « ui/gfx/image/image_util.cc ('k') | ui/snapshot/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017 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_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 = @{ NSImageCompressionFactor : @(compressionFactor)};
29 NSData* data =
30 [rep representationUsingType:NSJPEGFileType properties:options];
31
32 if ([data length] == 0)
33 return false;
34
35 dst->resize([data length]);
36 [data getBytes:&dst->at(0) length:[data length]];
37 return true;
38 }
39
40 } // end namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_util.cc ('k') | ui/snapshot/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698