Index: src/images/SkImageEncoder.cpp |
diff --git a/src/images/SkImageEncoder.cpp b/src/images/SkImageEncoder.cpp |
index 4b52fcdc8c89708852de7da460510aa904ea4455..5f5ffb82a2901ed16bf28124b2e9af8586d0e02c 100644 |
--- a/src/images/SkImageEncoder.cpp |
+++ b/src/images/SkImageEncoder.cpp |
@@ -1,4 +1,3 @@ |
- |
/* |
* Copyright 2009 The Android Open Source Project |
* |
@@ -6,7 +5,6 @@ |
* found in the LICENSE file. |
*/ |
- |
#include "SkImageEncoder.h" |
#include "SkBitmap.h" |
#include "SkStream.h" |
@@ -27,6 +25,15 @@ bool SkImageEncoder::encodeFile(const char file[], const SkBitmap& bm, |
return this->onEncode(&stream, bm, quality); |
} |
+SkData* SkImageEncoder::encodeData(const SkBitmap& bm, int quality) { |
+ SkDynamicMemoryWStream stream; |
+ quality = SkMin32(100, SkMax32(0, quality)); |
+ if (this->onEncode(&stream, bm, quality)) { |
+ return stream.copyToData(); |
+ } |
+ return NULL; |
+} |
+ |
bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, |
int quality) { |
SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
@@ -34,7 +41,13 @@ bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, |
} |
bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t, |
- int quality) { |
+ int quality) { |
SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
return enc.get() && enc.get()->encodeStream(stream, bm, quality); |
} |
+ |
+SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) { |
+ SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
+ return enc.get() ? enc.get()->encodeData(bm, quality) : NULL; |
+} |
+ |