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

Unified Diff: ui/gfx/image/image_png.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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698