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

Side by Side Diff: ui/gfx/image/image_util.cc

Issue 10928093: Adds an iOS implementation of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@skia
Patch Set: Moar GYP and TODOs. Created 8 years, 3 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 | « ui/gfx/image/image_util.h ('k') | ui/gfx/image/image_util_ios.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/image/image_util.h" 5 #include "ui/gfx/image/image_util.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/gfx/codec/jpeg_codec.h" 9 #include "ui/gfx/codec/jpeg_codec.h"
10 #include "ui/gfx/image/image.h" 10 #include "ui/gfx/image/image.h"
11 #include "ui/gfx/image/image_skia.h" 11 #include "ui/gfx/image/image_skia.h"
12 12
13 namespace gfx { 13 namespace gfx {
14 14
15 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) { 15 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) {
16 Image* image = new Image(input, input_size); 16 Image* image = new Image(input, input_size);
17 return image; 17 return image;
18 } 18 }
19 19
20 bool PNGEncodedDataFromImage(const Image& image,
21 std::vector<unsigned char>* dst) {
22 *dst = *image.ToImagePNG();
23 return !dst->empty();
24 }
25
26 // The iOS implementations of the JPEG functions are in image_util_ios.mm.
27 #if !defined(OS_IOS)
20 Image ImageFromJPEGEncodedData(const unsigned char* input, size_t input_size) { 28 Image ImageFromJPEGEncodedData(const unsigned char* input, size_t input_size) {
21 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size)); 29 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size));
22 if (bitmap.get()) 30 if (bitmap.get())
23 return Image(*bitmap); 31 return Image(*bitmap);
24 32
25 return Image(); 33 return Image();
26 } 34 }
27 35
28 bool PNGEncodedDataFromImage(const Image& image,
29 std::vector<unsigned char>* dst) {
30 *dst = *image.ToImagePNG();
31 return !dst->empty();
32 }
33
34 bool JPEGEncodedDataFromImage(const Image& image, int quality, 36 bool JPEGEncodedDataFromImage(const Image& image, int quality,
35 std::vector<unsigned char>* dst) { 37 std::vector<unsigned char>* dst) {
36 const SkBitmap& bitmap = *image.ToSkBitmap(); 38 const SkBitmap& bitmap = *image.ToSkBitmap();
37 SkAutoLockPixels bitmap_lock(bitmap); 39 SkAutoLockPixels bitmap_lock(bitmap);
38 40
39 if (!bitmap.readyToDraw()) 41 if (!bitmap.readyToDraw())
40 return false; 42 return false;
41 43
42 return gfx::JPEGCodec::Encode( 44 return gfx::JPEGCodec::Encode(
43 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 45 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
44 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), 46 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(),
45 bitmap.height(), 47 bitmap.height(),
46 static_cast<int>(bitmap.rowBytes()), quality, 48 static_cast<int>(bitmap.rowBytes()), quality,
47 dst); 49 dst);
48 } 50 }
51 #endif // !defined(OS_IOS)
49 52
50 } 53 }
OLDNEW
« no previous file with comments | « ui/gfx/image/image_util.h ('k') | ui/gfx/image/image_util_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698