summaryrefslogtreecommitdiffstats
path: root/base/gfx
diff options
context:
space:
mode:
authornick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-23 18:28:24 +0000
committernick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-23 18:28:24 +0000
commitaa310e9f8b2e3d5c8efc4ad977ee43e3e9349606 (patch)
tree3f89d116d7850b430c65fd5daabb86792956177e /base/gfx
parent569b1106f62d531c11f857f08961f41efe2b272e (diff)
downloadchromium_src-aa310e9f8b2e3d5c8efc4ad977ee43e3e9349606.zip
chromium_src-aa310e9f8b2e3d5c8efc4ad977ee43e3e9349606.tar.gz
chromium_src-aa310e9f8b2e3d5c8efc4ad977ee43e3e9349606.tar.bz2
Add a PNGEncoder helper function that takes an SkBitmap,
which is how PNGEncode is used almost everywhere. This should be strictly no functional change, except for the ImageFilterPeer::DataReady case, where we now take an SkAutoLockPixels where previously we did not. Review URL: http://codereview.chromium.org/18347 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8561 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rwxr-xr-x[-rw-r--r--]base/gfx/png_encoder.cc12
-rwxr-xr-x[-rw-r--r--]base/gfx/png_encoder.h10
2 files changed, 22 insertions, 0 deletions
diff --git a/base/gfx/png_encoder.cc b/base/gfx/png_encoder.cc
index 7b44a52..3349fd6 100644..100755
--- a/base/gfx/png_encoder.cc
+++ b/base/gfx/png_encoder.cc
@@ -5,6 +5,7 @@
#include "base/basictypes.h"
#include "base/gfx/png_encoder.h"
#include "base/logging.h"
+#include "skia/include/SkBitmap.h"
extern "C" {
#include "png.h"
@@ -191,3 +192,14 @@ bool PNGEncoder::Encode(const unsigned char* input, ColorFormat format,
return true;
}
+// static
+bool PNGEncoder::EncodeBGRASkBitmap(const SkBitmap& input,
+ bool discard_transparency,
+ std::vector<unsigned char>* output) {
+ SkAutoLockPixels input_lock(input);
+ DCHECK(input.empty() || input.bytesPerPixel() == 4);
+ return Encode(static_cast<unsigned char*>(input.getPixels()),
+ PNGEncoder::FORMAT_BGRA, input.width(), input.height(),
+ input.rowBytes(), discard_transparency, output);
+}
+
diff --git a/base/gfx/png_encoder.h b/base/gfx/png_encoder.h
index e346bd0..7d284be 100644..100755
--- a/base/gfx/png_encoder.h
+++ b/base/gfx/png_encoder.h
@@ -9,6 +9,8 @@
#include "base/basictypes.h"
+class SkBitmap;
+
// Interface for encoding PNG data. This is a wrapper around libpng,
// which has an inconvenient interface for callers. This is currently designed
// for use in tests only (where we control the files), so the handling isn't as
@@ -51,6 +53,14 @@ class PNGEncoder {
bool discard_transparency,
std::vector<unsigned char>* output);
+ // Call PNGEncoder::Encode on the supplied SkBitmap |input|, which is assumed
+ // to be BGRA, 32 bits per pixel. The params |discard_transparency| and
+ // |output| are passed directly to Encode; refer to Encode for more
+ // information. During the call, an SkAutoLockPixels lock is held on |input|.
+ static bool EncodeBGRASkBitmap(const SkBitmap& input,
+ bool discard_transparency,
+ std::vector<unsigned char>* output);
+
private:
DISALLOW_EVIL_CONSTRUCTORS(PNGEncoder);
};