aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-20 16:33:41 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-20 16:33:41 +0000
commit4b0757b7489ee5d6bd7149bbcdb0b2af6b7a21cb (patch)
treed408b82779c2362f9888888456e0441995648fce /src/images
parent845220b8179a73c8ec3e53b6dcc11ee3d30ad6a4 (diff)
add encodeData() to SkImageEncoder, and add encoding to SkImage
BUG= R=scroggo@google.com Review URL: https://codereview.chromium.org/15002004 git-svn-id: http://skia.googlecode.com/svn/trunk@9193 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images')
-rw-r--r--src/images/SkImageEncoder.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/images/SkImageEncoder.cpp b/src/images/SkImageEncoder.cpp
index 4b52fcdc8c..5f5ffb82a2 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;
+}
+