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

Unified Diff: ui/gfx/image/image_util_mac.mm

Issue 2592983002: [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: Disabled test on MacOS >=10.11, added ref to bug. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/image/image_util.cc ('k') | ui/snapshot/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_util_mac.mm
diff --git a/ui/gfx/image/image_util_mac.mm b/ui/gfx/image/image_util_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5be20b0f639ec202869b6d764bd767acdfe0f57f
--- /dev/null
+++ b/ui/gfx/image/image_util_mac.mm
@@ -0,0 +1,40 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/image/image_util.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/mac/scoped_nsobject.h"
+#include "ui/gfx/image/image.h"
+
+namespace gfx {
+
+bool JPEG1xEncodedDataFromImage(const Image& image,
+ int quality,
+ std::vector<unsigned char>* dst) {
+ if (!image.HasRepresentation(gfx::Image::kImageRepCocoa))
+ return JPEG1xEncodedDataFromSkiaRepresentation(image, quality, dst);
+
+ NSImage* nsImage = image.ToNSImage();
+
+ CGImageRef cgImage =
+ [nsImage CGImageForProposedRect:nil context:nil hints:nil];
+ base::scoped_nsobject<NSBitmapImageRep> rep(
+ [[NSBitmapImageRep alloc] initWithCGImage:cgImage]);
+
+ float compressionFactor = quality / 100.0;
+ NSDictionary* options = @{ NSImageCompressionFactor : @(compressionFactor)};
+ NSData* data =
+ [rep representationUsingType:NSJPEGFileType properties:options];
+
+ if ([data length] == 0)
+ return false;
+
+ dst->resize([data length]);
+ [data getBytes:&dst->at(0) length:[data length]];
+ return true;
+}
+
+} // end namespace gfx
« 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