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

Unified Diff: components/suggestions/image_encoder_ios.mm

Issue 641513003: [Suggestions] Introduce a different image encoder/decoder for iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest Created 6 years, 2 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
Index: components/suggestions/image_encoder_ios.mm
diff --git a/components/suggestions/image_encoder_ios.mm b/components/suggestions/image_encoder_ios.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5e8733b68787ced97aa7e790f0db619ae564e7df
--- /dev/null
+++ b/components/suggestions/image_encoder_ios.mm
@@ -0,0 +1,34 @@
+// Copyright 2014 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 "components/suggestions/image_encoder_ios.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/mac/scoped_cftyperef.h"
+#include "skia/ext/skia_utils_ios.h"
+
+namespace suggestions {
+
+SkBitmap* DecodeJPEGToSkBitmap(const std::vector<unsigned char>& encoded_data) {
+ NSData* data =
+ [NSData dataWithBytes:encoded_data.data() length:encoded_data.size()];
+ UIImage* image =
+ [UIImage imageWithData:data scale:1.0];
+ return new SkBitmap(gfx::CGImageToSkBitmap(image.CGImage, [image size], YES));
+}
+
+bool EncodeSkBitmapToJPEG(const SkBitmap& bitmap,
+ std::vector<unsigned char>* dest) {
+ base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
+ CGColorSpaceCreateDeviceRGB());
+ UIImage* image =
+ gfx::SkBitmapToUIImageWithColorSpace(bitmap, 1 /* scale */, color_space);
+ NSData* data = UIImageJPEGRepresentation(image, 1.0);
+ const char* bytes = reinterpret_cast<const char*>([data bytes]);
+ dest->assign(bytes, bytes + [data length]);
+ return true;
+}
+
+} // namespace suggestions

Powered by Google App Engine
This is Rietveld 408576698