aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
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;
+}