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..23a8e7b465e592a7be7fbfff7ef593aff1858194 |
--- /dev/null |
+++ b/ui/gfx/image/image_util_mac.mm |
@@ -0,0 +1,42 @@ |
+// 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.
|
+// 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 = [NSDictionary |
+ dictionaryWithObject:[NSNumber numberWithFloat:compressionFactor] |
+ forKey:NSImageCompressionFactor]; |
Avi (use Gerrit)
2017/01/09 16:57:33
NSDictionary* options = @{ NSImageCompressionFacto
Eric Seckler
2017/01/11 15:58:44
Done.
|
+ 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 |