summaryrefslogtreecommitdiffstats
path: root/ui/gfx/image
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-17 02:06:57 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-17 02:06:57 +0000
commit5b0c348ecc85d08ac03e171b6d3ce2fc4e687fc1 (patch)
treeb0ab89290a2cc53a3da5d97743fbd72294134502 /ui/gfx/image
parentd30f790cdde4ef74de9518e3699c22605556ffd6 (diff)
downloadchromium_src-5b0c348ecc85d08ac03e171b6d3ce2fc4e687fc1.zip
chromium_src-5b0c348ecc85d08ac03e171b6d3ce2fc4e687fc1.tar.gz
chromium_src-5b0c348ecc85d08ac03e171b6d3ce2fc4e687fc1.tar.bz2
Refactor FaviconHandler to move code into delegate
methods. BUG=None TEST=None Review URL: http://codereview.chromium.org/7172028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89437 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/image')
-rw-r--r--ui/gfx/image/image_util.cc28
-rw-r--r--ui/gfx/image/image_util.h30
2 files changed, 58 insertions, 0 deletions
diff --git a/ui/gfx/image/image_util.cc b/ui/gfx/image/image_util.cc
new file mode 100644
index 0000000..eaa1958
--- /dev/null
+++ b/ui/gfx/image/image_util.cc
@@ -0,0 +1,28 @@
+// Copyright (c) 2011 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 "ui/gfx/image/image_util.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/image/image.h"
+
+namespace gfx {
+
+Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) {
+ scoped_ptr<SkBitmap> favicon_bitmap(new SkBitmap());
+ if (gfx::PNGCodec::Decode(input, input_size, favicon_bitmap.get()))
+ return new Image(favicon_bitmap.release());
+
+ return NULL;
+}
+
+bool PNGEncodedDataFromImage(const Image& image,
+ std::vector<unsigned char>* dst) {
+ const SkBitmap& bitmap = image;
+ return gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, dst);
+}
+
+}
diff --git a/ui/gfx/image/image_util.h b/ui/gfx/image/image_util.h
new file mode 100644
index 0000000..b207830
--- /dev/null
+++ b/ui/gfx/image/image_util.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 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.
+
+#ifndef UI_GFX_IMAGE_IMAGE_UTIL_H_
+#define UI_GFX_IMAGE_IMAGE_UTIL_H_
+#pragma once
+
+#include <vector>
+
+#include "base/basictypes.h"
+
+namespace gfx {
+class Image;
+}
+
+namespace gfx {
+
+// Creates an image from the given PNG-encoded input. The caller owns the
+// returned Image. If there was an error creating the image, returns NULL.
+Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size);
+
+// Fills the |dst| vector with PNG-encoded bytes based on the given Image.
+// Returns true if the Image was encoded successfully.
+bool PNGEncodedDataFromImage(const Image& image,
+ std::vector<unsigned char>* dst);
+
+}
+
+#endif // UI_GFX_IMAGE_IMAGE_UTIL_H_