| 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) {
|
|
|