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

Side by Side Diff: ios/chrome/browser/suggestions/ios_image_decoder_impl.mm

Issue 2111573002: Add ios_image_decoder_impl.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo in ios_chrome.gyp Created 4 years, 5 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 | « ios/chrome/browser/suggestions/ios_image_decoder_impl.h ('k') | ios/chrome/ios_chrome.gyp » ('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 2016 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 "ios/chrome/browser/suggestions/ios_image_decoder_impl.h"
6
7 #include <UIKit/UIKit.h>
8
9 #include "base/callback.h"
10 #include "ui/gfx/image/image.h"
11
12 namespace suggestions {
13
14 IOSImageDecoderImpl::IOSImageDecoderImpl() {}
15
16 IOSImageDecoderImpl::~IOSImageDecoderImpl() {}
17
18 void IOSImageDecoderImpl::DecodeImage(
19 const std::string& image_data,
20 const image_fetcher::ImageDecodedCallback& callback) {
21 // Convert the |image_data| std::string to a NSData buffer.
22 NSData* data =
23 [NSData dataWithBytesNoCopy:const_cast<char*>(image_data.c_str())
24 length:image_data.length()
25 freeWhenDone:NO];
26
27 // Decode the Image using UIImage.
28 if (data) {
29 // Most likely always returns 1x images.
30 UIImage* ui_image = [UIImage imageWithData:data scale:1];
31 if (ui_image) {
32 gfx::Image gfx_image(ui_image);
33 callback.Run(gfx_image);
34 return;
35 }
36 }
37 gfx::Image empty_image;
38 callback.Run(empty_image);
39 }
40
41 } // namespace suggestions
OLDNEW
« no previous file with comments | « ios/chrome/browser/suggestions/ios_image_decoder_impl.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698