| Index: ui/gfx/image/image_png.cc
|
| diff --git a/ui/gfx/image/image_png.cc b/ui/gfx/image/image_png.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..76d2824cf332371e8be6ef255a6838ab60f1f143
|
| --- /dev/null
|
| +++ b/ui/gfx/image/image_png.cc
|
| @@ -0,0 +1,57 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| +#include "ui/gfx/image/image_png.h"
|
| +#include "ui/gfx/codec/png_codec.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace gfx {
|
| +
|
| +ImagePNG::ImagePNG(const std::vector<unsigned char>& input)
|
| + : image_(new base::RefCountedBytes(input)) {
|
| +}
|
| +
|
| +ImagePNG::ImagePNG(const unsigned char* input, size_t input_size)
|
| + : image_(new base::RefCountedBytes()) {
|
| + image_->data().assign(input, input + input_size);
|
| +}
|
| +
|
| +ImagePNG::ImagePNG(const ImagePNG& other)
|
| + : image_(other.image_) {
|
| +}
|
| +
|
| +ImagePNG& ImagePNG::operator=(const ImagePNG& other) {
|
| + image_ = other.image_;
|
| + return *this;
|
| +}
|
| +
|
| +ImagePNG::~ImagePNG() {
|
| +}
|
| +
|
| +ImagePNG::ImagePNG() : image_(new base::RefCountedBytes()) {
|
| +}
|
| +
|
| +ImagePNG ImagePNG::FromSkBitmap(const SkBitmap* bitmap) {
|
| + ImagePNG image;
|
| + if (!gfx::PNGCodec::EncodeBGRASkBitmap(
|
| + *bitmap, false, &image.image_->data())) {
|
| + LOG(WARNING) << "Unable to encode bitmap, returning empty PNG.";
|
| + image.image_->data().clear();
|
| + }
|
| + return image;
|
| +}
|
| +
|
| +bool ImagePNG::empty() const {
|
| + return image_->data().empty();
|
| +}
|
| +
|
| +const std::vector<unsigned char>& ImagePNG::Image() const {
|
| + return image_->data();
|
| +}
|
| +
|
| +} // namespace gfx
|
|
|