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

Unified Diff: src/images/SkImageEncoder.cpp

Issue 1507123002: default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-10 (Thursday) 13:15:57 EST Created 5 years 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.cpp ('k') | src/ports/SkImageDecoder_empty.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 cc1b73baa52150de72f20c1543634503d83770f9..22bbc57c2f593a083734311f0c2dadb5f4994947 100644
--- a/src/images/SkImageEncoder.cpp
+++ b/src/images/SkImageEncoder.cpp
@@ -7,6 +7,8 @@
#include "SkImageEncoder.h"
#include "SkBitmap.h"
+#include "SkPixelSerializer.h"
+#include "SkPixmap.h"
#include "SkStream.h"
#include "SkTemplates.h"
@@ -57,6 +59,30 @@ SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels,
if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
return nullptr;
}
- SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
- return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr;
+ bm.setImmutable();
+ return SkImageEncoder::EncodeData(bm, t, quality);
+}
+
+SkData* SkImageEncoder::EncodeData(const SkPixmap& pixmap,
+ Type t, int quality) {
+ SkBitmap bm;
+ if (!bm.installPixels(pixmap)) {
+ return nullptr;
+ }
+ bm.setImmutable();
+ return SkImageEncoder::EncodeData(bm, t, quality);
+}
+
+namespace {
+class ImageEncoderPixelSerializer final : public SkPixelSerializer {
+protected:
+ bool onUseEncodedData(const void*, size_t) override { return true; }
+ SkData* onEncode(const SkPixmap& pmap) override {
+ return SkImageEncoder::EncodeData(pmap, SkImageEncoder::kPNG_Type, 100);
+ }
+};
+} // namespace
+
+SkPixelSerializer* SkImageEncoder::CreatePixelSerializer() {
+ return new ImageEncoderPixelSerializer;
}
« no previous file with comments | « src/image/SkImage.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698