From 5b0c348ecc85d08ac03e171b6d3ce2fc4e687fc1 Mon Sep 17 00:00:00 2001 From: "rohitrao@chromium.org" Date: Fri, 17 Jun 2011 02:06:57 +0000 Subject: 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 --- ui/gfx/image/image_util.cc | 28 ++++++++++++++++++++++++++++ ui/gfx/image/image_util.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 ui/gfx/image/image_util.cc create mode 100644 ui/gfx/image/image_util.h (limited to 'ui/gfx/image') 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 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* 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 + +#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* dst); + +} + +#endif // UI_GFX_IMAGE_IMAGE_UTIL_H_ -- cgit v1.1