OLD | NEW |
(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 |
OLD | NEW |