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

Unified Diff: src/codec/SkCodec.cpp

Issue 1321433002: Add subsetting to SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-scan
Patch Set: Rebase - it compiles but I'm sure everything is broken 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
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodecPriv.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec.cpp
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 917df317fb3552e4ee72b005693c340fbfa9dcf6..64b2ad6602880454953b68ee10374ab0334587e9 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -111,6 +111,59 @@ 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;
+ }
+
+ if (!is_valid_subset(desiredSubset, this->getInfo().dimensions())) {
+ return false;
+ }
+
+ return this->onGetValidSubset(desiredSubset);
+}
+
+bool SkCodec::getScaledSubsetDimensions(float desiredScale, Options* options) const {
+ // Negative and zero scales are errors.
+ SkASSERT(desiredScale > 0.0f);
+ if (desiredScale <= 0.0f) {
+ return false;
+ }
+
+ // Upscaling is not supported. We will suggest a full decode if
+ // upscaling is requested.
+ if (desiredScale >= 1.0f) {
+ desiredScale = 1.0f;
+ }
+
+ // If the client is not requesting a subset decode,
+ // getScaledDimensions() should be used.
+ if (nullptr == options->fSubset) {
+ return false;
+ }
+
+ if (!is_valid_subset(options->fSubset, this->getInfo().dimensions())) {
+ return false;
+ }
+
+ return this->onGetScaledSubsetDimensions(desiredScale, options);
+}
+
SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options* options, SkPMColor ctable[], int* ctableCount) {
if (kUnknown_SkColorType == info.colorType()) {
@@ -195,9 +248,17 @@ SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
}
SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
- const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) {
+ const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount, int subsetLeft,
+ int subsetWidth) {
// Reset fCurrScanline in case of failure.
fCurrScanline = -1;
+
+ // Ensure that the subset parameters are valid
+ if (0 > subsetLeft || subsetLeft >= dstInfo.width() || 0 > subsetWidth ||
+ subsetLeft + subsetWidth > dstInfo.width()) {
+ return kInvalidParameters;
+ }
+
// Ensure that valid color ptrs are passed in for kIndex8 color type
if (kIndex_8_SkColorType == dstInfo.colorType()) {
if (nullptr == ctable || nullptr == ctableCount) {
@@ -233,7 +294,8 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
return kInvalidScale;
}
- const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable, ctableCount);
+ const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable, ctableCount,
+ subsetLeft, subsetWidth);
if (result != SkCodec::kSuccess) {
return result;
}
@@ -244,8 +306,13 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
return kSuccess;
}
+SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
+ const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) {
+ return this->startScanlineDecode(dstInfo, options, ctable, ctableCount, 0, dstInfo.width());
+}
+
SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo) {
- return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr);
+ return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr, 0, dstInfo.width());
}
int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) {
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodecPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698