| OLD | NEW |
| 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" | 10 #include "ui/gfx/codec/png_codec.h" |
| 11 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.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 scoped_ptr<SkBitmap> favicon_bitmap(new SkBitmap()); | 16 SkBitmap favicon_bitmap; |
| 17 if (gfx::PNGCodec::Decode(input, input_size, favicon_bitmap.get())) | 17 if (gfx::PNGCodec::Decode(input, input_size, &favicon_bitmap)) |
| 18 return new Image(favicon_bitmap.release()); | 18 return new Image(favicon_bitmap); |
| 19 | 19 |
| 20 return NULL; | 20 return NULL; |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool PNGEncodedDataFromImage(const Image& image, | 23 bool PNGEncodedDataFromImage(const Image& image, |
| 24 std::vector<unsigned char>* dst) { | 24 std::vector<unsigned char>* dst) { |
| 25 const SkBitmap& bitmap = *image.ToSkBitmap(); | 25 const SkBitmap& bitmap = *image.ToSkBitmap(); |
| 26 return gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, dst); | 26 return gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, dst); |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool JPEGEncodedDataFromImage(const Image& image, int quality, | 29 bool JPEGEncodedDataFromImage(const Image& image, int quality, |
| 30 std::vector<unsigned char>* dst) { | 30 std::vector<unsigned char>* dst) { |
| 31 const SkBitmap& bitmap = *image.ToSkBitmap(); | 31 const SkBitmap& bitmap = *image.ToSkBitmap(); |
| 32 SkAutoLockPixels bitmap_lock(bitmap); | 32 SkAutoLockPixels bitmap_lock(bitmap); |
| 33 | 33 |
| 34 if (!bitmap.readyToDraw()) | 34 if (!bitmap.readyToDraw()) |
| 35 return false; | 35 return false; |
| 36 | 36 |
| 37 return gfx::JPEGCodec::Encode( | 37 return gfx::JPEGCodec::Encode( |
| 38 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 38 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 39 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), | 39 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), |
| 40 bitmap.height(), | 40 bitmap.height(), |
| 41 static_cast<int>(bitmap.rowBytes()), quality, | 41 static_cast<int>(bitmap.rowBytes()), quality, |
| 42 dst); | 42 dst); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } | 45 } |
| OLD | NEW |