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

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

Issue 10799014: Add support for PNG representation in gfx::Image (Closed) Base URL: http://git.chromium.org/chromium/src.git@bookmark-sync
Patch Set: Created 8 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
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/codec/png_codec.h"
11 #include "ui/gfx/image/image.h" 10 #include "ui/gfx/image/image.h"
11 #include "ui/gfx/image/image_png.h"
12 #include "ui/gfx/image/image_skia.h"
12 13
13 namespace gfx { 14 namespace gfx {
14 15
15 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) { 16 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) {
16 SkBitmap bitmap; 17 Image* image = new Image(ImagePNG(input, input_size));
17 if (gfx::PNGCodec::Decode(input, input_size, &bitmap)) 18 // Check if image can be converted to an ImageSkia and return NULL if
18 return new Image(bitmap); 19 // conversion fails.
19 20 if (image->ToImageSkia()->empty())
20 return NULL; 21 return NULL;
22 return image;
21 } 23 }
22 24
23 Image ImageFromJPEGEncodedData(const unsigned char* input, size_t input_size) { 25 Image ImageFromJPEGEncodedData(const unsigned char* input, size_t input_size) {
24 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size)); 26 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size));
25 if (bitmap.get()) 27 if (bitmap.get())
26 return Image(*bitmap); 28 return Image(*bitmap);
27 29
28 return Image(); 30 return Image();
29 } 31 }
30 32
31 bool PNGEncodedDataFromImage(const Image& image, 33 bool PNGEncodedDataFromImage(const Image& image,
32 std::vector<unsigned char>* dst) { 34 std::vector<unsigned char>* dst) {
33 const SkBitmap& bitmap = *image.ToSkBitmap(); 35 *dst = image.ToImagePNG()->Image();
34 return gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, dst); 36 return !dst->empty();
35 } 37 }
36 38
37 bool JPEGEncodedDataFromImage(const Image& image, int quality, 39 bool JPEGEncodedDataFromImage(const Image& image, int quality,
38 std::vector<unsigned char>* dst) { 40 std::vector<unsigned char>* dst) {
39 const SkBitmap& bitmap = *image.ToSkBitmap(); 41 const SkBitmap& bitmap = *image.ToSkBitmap();
40 SkAutoLockPixels bitmap_lock(bitmap); 42 SkAutoLockPixels bitmap_lock(bitmap);
41 43
42 if (!bitmap.readyToDraw()) 44 if (!bitmap.readyToDraw())
43 return false; 45 return false;
44 46
45 return gfx::JPEGCodec::Encode( 47 return gfx::JPEGCodec::Encode(
46 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 48 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
47 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), 49 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(),
48 bitmap.height(), 50 bitmap.height(),
49 static_cast<int>(bitmap.rowBytes()), quality, 51 static_cast<int>(bitmap.rowBytes()), quality,
50 dst); 52 dst);
51 } 53 }
52 54
53 } 55 }
OLDNEW
« ui/gfx/image/image_png.h ('K') | « ui/gfx/image/image_unittest.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698