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

Unified Diff: src/codec/SkCodec.cpp

Issue 1390213002: Add subsetting to SkScanlineDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@fill-refactor
Patch Set: Created 5 years, 2 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
Index: src/codec/SkCodec.cpp
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index bafca852554db21a1e15fdda6b5b3c2a0dc2de45..20032e984d4d2b4e940f0f916f37ddf8bf6eddd7 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -111,6 +111,34 @@ bool SkCodec::rewindIfNeeded() {
return this->onRewind();
}
+SkISize SkCodec::getScaledDimensions(float desiredScale) const {
+ // Negative and zero scales are errors.
+ SkASSERT(desiredScale > 0.0f);
+ if (desiredScale <= 0.0f) {
+ return SkISize::Make(0, 0);
+ }
+
+ // Upscaling is not supported. Return the original size if the client
+ // requests an upscale.
+ if (desiredScale >= 1.0f) {
+ return this->getInfo().dimensions();
+ }
+ return this->onGetScaledDimensions(desiredScale);
+}
+
+bool SkCodec::getValidSubset(SkIRect* desiredSubset) const {
+ if (!desiredSubset) {
+ return false;
+ }
+
+ SkIRect dimensions = SkIRect::MakeSize(this->getInfo().dimensions());
+ if (!dimensions.contains(*desiredSubset)) {
+ return false;
+ }
+
+ return this->onGetValidSubset(desiredSubset);
+}
+
SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options* options, SkPMColor ctable[], int* ctableCount) {
if (kUnknown_SkColorType == info.colorType()) {
@@ -198,6 +226,7 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) {
// Reset fCurrScanline in case of failure.
fCurrScanline = -1;
+
// Ensure that valid color ptrs are passed in for kIndex8 color type
if (kIndex_8_SkColorType == dstInfo.colorType()) {
if (nullptr == ctable || nullptr == ctableCount) {
@@ -220,10 +249,14 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
if (nullptr == options) {
options = &optsStorage;
} else if (options->fSubset) {
- SkIRect subset(*options->fSubset);
- if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) {
- // FIXME: How to differentiate between not supporting subset at all
- // and not supporting this particular subset?
+ SkIRect size = SkIRect::MakeSize(dstInfo.dimensions());
+ if (!size.contains(*options->fSubset)) {
+ return kInvalidInput;
+ }
+
+ // We only support subsetting in the x-dimension for scanline decoder.
+ // Subsetting in the y-dimension can be accomplished using skipScanlines().
+ if (options->fSubset->top() != 0 || options->fSubset->height() != dstInfo.height()) {
msarett 2015/10/07 22:15:14 Alternatively we can just ignore the y-coordinates
return kUnimplemented;
}
}
@@ -233,14 +266,14 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
return kInvalidScale;
}
+ fDstInfo = dstInfo;
+ fOptions = *options;
msarett 2015/10/07 22:15:14 SkJpegCodec might need to call getSampler() in sta
scroggo 2015/10/08 20:16:07 The reason is because I did not want to update the
msarett 2015/10/09 20:03:44 Acknowledged.
const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable, ctableCount);
if (result != SkCodec::kSuccess) {
return result;
}
fCurrScanline = 0;
- fDstInfo = dstInfo;
- fOptions = *options;
return kSuccess;
}

Powered by Google App Engine
This is Rietveld 408576698