Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: src/images/SkImageEncoder.cpp

Issue 15002004: add encodeData() to SkImageEncoder, and add encoding to SkImage (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | tools/skhello.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
+
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | tools/skhello.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698