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 "third_party/skia/include/core/SkBitmap.h" |
| 6 #include "ui/gfx/image/image_png.h" |
| 7 #include "ui/gfx/codec/png_codec.h" |
| 8 |
| 9 #include <algorithm> |
| 10 |
| 11 #include "base/logging.h" |
| 12 |
| 13 namespace gfx { |
| 14 |
| 15 ImagePNG::ImagePNG(const std::vector<unsigned char>& input) |
| 16 : image_(new base::RefCountedBytes(input)) { |
| 17 } |
| 18 |
| 19 ImagePNG::ImagePNG(const unsigned char* input, size_t input_size) |
| 20 : image_(new base::RefCountedBytes()) { |
| 21 image_->data().assign(input, input + input_size); |
| 22 } |
| 23 |
| 24 ImagePNG::ImagePNG(const ImagePNG& other) |
| 25 : image_(other.image_) { |
| 26 } |
| 27 |
| 28 ImagePNG& ImagePNG::operator=(const ImagePNG& other) { |
| 29 image_ = other.image_; |
| 30 return *this; |
| 31 } |
| 32 |
| 33 ImagePNG::~ImagePNG() { |
| 34 } |
| 35 |
| 36 ImagePNG::ImagePNG() : image_(new base::RefCountedBytes()) { |
| 37 } |
| 38 |
| 39 ImagePNG ImagePNG::FromSkBitmap(const SkBitmap* bitmap) { |
| 40 ImagePNG image; |
| 41 if (!gfx::PNGCodec::EncodeBGRASkBitmap( |
| 42 *bitmap, false, &image.image_->data())) { |
| 43 LOG(WARNING) << "Unable to encode bitmap, returning empty PNG."; |
| 44 image.image_->data().clear(); |
| 45 } |
| 46 return image; |
| 47 } |
| 48 |
| 49 bool ImagePNG::empty() const { |
| 50 return image_->data().empty(); |
| 51 } |
| 52 |
| 53 const std::vector<unsigned char>& ImagePNG::Image() const { |
| 54 return image_->data(); |
| 55 } |
| 56 |
| 57 } // namespace gfx |
OLD | NEW |