aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkReadBuffer.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-05-29 15:41:27 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-29 20:42:17 +0000
commitf2c736400f03f8fe7fe356962c979f23df4d5f6b (patch)
tree809d21837d0701569cccd0e21f23e2ac5574007a /src/core/SkReadBuffer.cpp
parent4f078f7cfac6580dce6e213c022708922739ac6d (diff)
support image-subsets in serialization
A follow-on API change *could* be to extend the SerialProcs to pass subset information up to the client, in case they want to handle the subsetting step themselves. Bug: skia:7983 Change-Id: I36d3f1ce439886384495485c3be3c591d611a135 Reviewed-on: https://skia-review.googlesource.com/130543 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkReadBuffer.cpp')
-rw-r--r--src/core/SkReadBuffer.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp
index 0c2edf622d..3491428658 100644
--- a/src/core/SkReadBuffer.cpp
+++ b/src/core/SkReadBuffer.cpp
@@ -282,14 +282,28 @@ uint32_t SkReadBuffer::getArrayCount() {
return fError ? 0 : *(uint32_t*)fReader.peek();
}
+/* Format:
+ * (subset) width, height
+ * (subset) origin x, y
+ * size (31bits)
+ * data [ encoded, with raw width/height ]
+ */
sk_sp<SkImage> SkReadBuffer::readImage() {
if (fInflator) {
SkImage* img = fInflator->getImage(this->read32());
return img ? sk_ref_sp(img) : nullptr;
}
- int width = this->read32();
- int height = this->read32();
+ SkIRect bounds;
+ if (this->isVersionLT(kStoreImageBounds_Version)) {
+ bounds.fLeft = bounds.fTop = 0;
+ bounds.fRight = this->read32();
+ bounds.fBottom = this->read32();
+ } else {
+ this->readIRect(&bounds);
+ }
+ const int width = bounds.width();
+ const int height = bounds.height();
if (width <= 0 || height <= 0) { // SkImage never has a zero dimension
this->validate(false);
return nullptr;
@@ -338,6 +352,11 @@ sk_sp<SkImage> SkReadBuffer::readImage() {
if (!image) {
image = SkImage::MakeFromEncoded(std::move(data));
}
+ if (image) {
+ if (bounds.x() || bounds.y() || width < image->width() || height < image->height()) {
+ image = image->makeSubset(bounds);
+ }
+ }
// Question: are we correct to return an "empty" image instead of nullptr, if the decoder
// failed for some reason?
return image ? image : MakeEmptyImage(width, height);