aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-12-08 16:20:58 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-09 01:36:48 +0000
commit25eef6b342a007f76802950a683b4a339761c42e (patch)
tree4136ef0c2869ae2818be5bb03008df627c258240 /src
parent42b6cffaad4897d1d5a45bf9087a3b1a881591f4 (diff)
centralize encoding to SkData
Bug: skia: Change-Id: If3a9a6de54cf76d03e4d159b54b07a4ea6d5cda9 Reviewed-on: https://skia-review.googlesource.com/83020 Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/image/SkImage.cpp9
-rw-r--r--src/images/SkImageEncoder.cpp10
2 files changed, 12 insertions, 7 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index ba28cda6ee..b9dc2e6cc5 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -23,7 +23,6 @@
#include "SkPixelSerializer.h"
#include "SkReadPixelsRec.h"
#include "SkSpecialImage.h"
-#include "SkStream.h"
#include "SkString.h"
#include "SkSurface.h"
@@ -98,8 +97,7 @@ sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) cons
SkBitmap bm;
SkColorSpace* legacyColorSpace = nullptr;
if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) {
- SkDynamicMemoryWStream buf;
- return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData() : nullptr;
+ return SkEncodeBitmap(bm, type, quality);
}
return nullptr;
}
@@ -118,12 +116,9 @@ sk_sp<SkData> SkImage::encodeToData(SkPixelSerializer* serializer) const {
if (serializer) {
return serializer->encodeToData(pmap);
} else {
- SkDynamicMemoryWStream buf;
- return SkEncodeImage(&buf, pmap, SkEncodedImageFormat::kPNG, 100)
- ? buf.detachAsData() : nullptr;
+ return SkEncodePixmap(pmap, SkEncodedImageFormat::kPNG, 100);
}
}
-
return nullptr;
}
diff --git a/src/images/SkImageEncoder.cpp b/src/images/SkImageEncoder.cpp
index 52ad03283a..7472a02f51 100644
--- a/src/images/SkImageEncoder.cpp
+++ b/src/images/SkImageEncoder.cpp
@@ -79,3 +79,13 @@ bool SkEncoder::encodeRows(int numRows) {
return true;
}
+
+sk_sp<SkData> SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality) {
+ SkDynamicMemoryWStream stream;
+ return SkEncodeImage(&stream, src, format, quality) ? stream.detachAsData() : nullptr;
+}
+
+sk_sp<SkData> SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality) {
+ SkPixmap pixmap;
+ return src.peekPixels(&pixmap) ? SkEncodePixmap(pixmap, format, quality) : nullptr;
+}