OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 <UIKit/UIKit.h> | |
6 | |
7 #include "ui/gfx/image/image.h" | |
8 #include "ui/gfx/image/image_util.h" | |
9 | |
10 #include "base/logging.h" | |
11 | |
12 namespace gfx { | |
13 | |
14 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) { | |
Robert Sesek
2012/09/13 16:14:24
Wait, why this and gfx::internal::CreateUIImageFro
rohitrao (ping after 24h)
2012/09/13 17:57:57
Legacy code. These util functions were written be
| |
15 NSData* data = [NSData dataWithBytes:input length:input_size]; | |
16 UIImage* image = [[UIImage alloc] initWithData:data]; | |
17 if (!image) | |
18 return NULL; | |
19 | |
20 return new Image(image); | |
21 } | |
22 | |
23 | |
24 bool PNGEncodedDataFromImage(const Image& image, | |
Robert Sesek
2012/09/13 16:14:24
And why this and gfx::internal::PNGFromUIImage?
| |
25 std::vector<unsigned char>* dst) { | |
26 NSData* data = UIImagePNGRepresentation(image.ToUIImage()); | |
27 | |
28 if (!data || [data length] == 0) | |
Robert Sesek
2012/09/13 16:14:24
nit: extra check, and on line 41
rohitrao (ping after 24h)
2012/09/13 17:57:57
Done.
| |
29 return false; | |
30 | |
31 dst->resize([data length]); | |
32 [data getBytes:(&dst->at(0)) length:[data length]]; | |
Robert Sesek
2012/09/13 16:14:24
nit: extra parens, and on line 45
rohitrao (ping after 24h)
2012/09/13 17:57:57
Done.
| |
33 return true; | |
34 } | |
35 | |
36 bool JPEGEncodedDataFromImage(const Image& image, | |
37 int quality, | |
38 std::vector<unsigned char>* dst) { | |
39 NSData* data = UIImageJPEGRepresentation(image.ToUIImage(), quality / 100.0); | |
40 | |
41 if (!data || [data length] == 0) | |
42 return false; | |
43 | |
44 dst->resize([data length]); | |
45 [data getBytes:(&dst->at(0)) length:[data length]]; | |
46 return true; | |
47 } | |
48 | |
49 } // end namespace gfx | |
OLD | NEW |