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

Unified Diff: src/core/SkReadBuffer.cpp

Issue 2039813007: Add raw pixel serialization fallback for SkImages that cannot be encoded. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixed only on Mac Created 4 years, 6 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 | « no previous file | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkReadBuffer.cpp
diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp
index f55a5b043b3f44b554929205e35f1c97152a1e67..54f684acaa7379633f7cefb9193c1d3f010f2e38 100644
--- a/src/core/SkReadBuffer.cpp
+++ b/src/core/SkReadBuffer.cpp
@@ -276,12 +276,29 @@ SkImage* SkReadBuffer::readImage() {
return nullptr;
}
- sk_sp<SkData> encoded(this->readByteArrayAsData());
- if (encoded->size() == 0) {
- // The image could not be encoded at serialization time - return an empty placeholder.
+ auto placeholder = [=] {
return SkImage::MakeFromGenerator(
new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))).release();
+ };
+
+ uint32_t encoded_size = this->getArrayCount();
+ if (encoded_size == 0) {
+ // The image could not be encoded at serialization time - return an empty placeholder.
+ (void)this->readUInt(); // Swallow that encoded_size == 0 sentinel.
+ return placeholder();
}
+ if (encoded_size == 1) {
+ // We had to encode the image as raw pixels via SkBitmap.
+ (void)this->readUInt(); // Swallow that encoded_size == 1 sentinel.
+ SkBitmap bm;
+ if (SkBitmap::ReadRawPixels(this, &bm)) {
+ return SkImage::MakeFromBitmap(bm).release();
+ }
+ return placeholder();
+ }
+
+ // The SkImage encoded itself.
+ sk_sp<SkData> encoded(this->readByteArrayAsData());
int originX = this->read32();
int originY = this->read32();
« no previous file with comments | « no previous file | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698