aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 9dcf3d74dc..8cb526746c 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -94,21 +94,21 @@ sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode
return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix);
}
-SkData* SkImage::encode(SkEncodedImageFormat type, int quality) const {
+sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) const {
SkBitmap bm;
SkColorSpace* legacyColorSpace = nullptr;
if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) {
SkDynamicMemoryWStream buf;
- return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData().release() : nullptr;
+ return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData() : nullptr;
}
return nullptr;
}
-SkData* SkImage::encode(SkPixelSerializer* serializer) const {
- sk_sp<SkData> encoded(this->refEncoded());
+sk_sp<SkData> SkImage::encodeToData(SkPixelSerializer* serializer) const {
+ sk_sp<SkData> encoded(this->refEncodedData());
if (encoded &&
(!serializer || serializer->useEncodedData(encoded->data(), encoded->size()))) {
- return encoded.release();
+ return encoded;
}
SkBitmap bm;
@@ -116,19 +116,19 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const {
SkColorSpace* legacyColorSpace = nullptr;
if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && bm.peekPixels(&pmap)) {
if (serializer) {
- return serializer->encode(pmap);
+ return serializer->encodeToData(pmap);
} else {
SkDynamicMemoryWStream buf;
return SkEncodeImage(&buf, pmap, SkEncodedImageFormat::kPNG, 100)
- ? buf.detachAsData().release() : nullptr;
+ ? buf.detachAsData() : nullptr;
}
}
return nullptr;
}
-SkData* SkImage::refEncoded() const {
- return as_IB(this)->onRefEncoded();
+sk_sp<SkData> SkImage::refEncodedData() const {
+ return sk_sp<SkData>(as_IB(this)->onRefEncoded());
}
sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
@@ -138,6 +138,23 @@ sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* su
return SkImage::MakeFromGenerator(SkImageGenerator::MakeFromEncoded(encoded), subset);
}
+#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODE_API
+SkData* SkImage::encode(SkEncodedImageFormat format, int quality) const {
+ return this->encodeToData(format, quality).release();
+}
+SkData* SkImage::encode(SkPixelSerializer* serial) const {
+ return this->encodeToData(serial).release();
+}
+SkData* SkImage::refEncoded() const {
+ return this->refEncodedData().release();
+}
+SkData* SkPixelSerializer::encode(const SkPixmap& pixmap) {
+ return this->encodeToData(pixmap).release();
+}
+#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
const char* SkImage::toString(SkString* str) const {
str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
this->isOpaque() ? "opaque" : "");