diff options
author | Leon Scroggins <scroggo@google.com> | 2017-07-10 19:51:46 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-10 19:51:59 +0000 |
commit | 8321f7585b6aded0c35e50e9af8709b25fdce3f6 (patch) | |
tree | 9a9e3a1843c8864a9e847d0c7b59b987946f6b24 /src/codec/SkCodec.cpp | |
parent | a48ae6ec2feb32e3d781ad43353209a90059a01d (diff) |
Revert "Remove support for decoding to kIndex_8"
This reverts commit 742a3e298fda669006147e4a305bab8452369b1f.
Reason for revert: Breaking Android roll:
frameworks/base/core/jni/android/graphics/BitmapFactory.cpp:453:18: error: no member named 'fColorPtr' in 'SkAndroidCodec::AndroidOptions'
codecOptions.fColorPtr = colorPtr;
~~~~~~~~~~~~ ^
frameworks/base/core/jni/android/graphics/BitmapFactory.cpp:454:18: error: no member named 'fColorCount' in 'SkAndroidCodec::AndroidOptions'
codecOptions.fColorCount = colorCount;
~~~~~~~~~~~~ ^
Original change's description:
> Remove support for decoding to kIndex_8
>
> Fix up callsites, and remove tests that no longer make sense.
>
> Bug: skia:6828
> Change-Id: I2548c4b7528b7b1be7412563156f27b52c9d4295
> Reviewed-on: https://skia-review.googlesource.com/21664
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Leon Scroggins <scroggo@google.com>
TBR=djsollen@google.com,scroggo@google.com
Change-Id: I1bc669441f250690884e75a9a61427fdf75c6907
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:6828
Reviewed-on: https://skia-review.googlesource.com/22120
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkCodec.cpp')
-rw-r--r-- | src/codec/SkCodec.cpp | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 4bd3917880..26b31ae11f 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -167,6 +167,19 @@ bool SkCodec::rewindIfNeeded() { return this->onRewind(); } +#define CHECK_COLOR_TABLE \ + if (kIndex_8_SkColorType == info.colorType()) { \ + if (nullptr == ctable || nullptr == ctableCount) { \ + return SkCodec::kInvalidParameters; \ + } \ + } else { \ + if (ctableCount) { \ + *ctableCount = 0; \ + } \ + ctableCount = nullptr; \ + ctable = nullptr; \ + } + static void zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes, SkIRect frameRect) { if (!frameRect.intersect(dstInfo.bounds())) { @@ -192,6 +205,11 @@ SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, return kInvalidParameters; } + // index 8 is not supported beyond the first frame. + if (index < 0 || info.colorType() == kIndex_8_SkColorType) { + return kInvalidParameters; + } + if (index >= this->onGetFrameCount()) { return kIncompleteInput; } @@ -234,7 +252,8 @@ SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, Options prevFrameOptions(options); prevFrameOptions.fFrameIndex = requiredFrame; prevFrameOptions.fZeroInitialized = kNo_ZeroInitialized; - const Result result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions); + const Result result = this->getPixels(info, pixels, rowBytes, &prevFrameOptions, + nullptr, nullptr); if (result == kSuccess) { const auto* prevFrame = frameHolder->getFrame(requiredFrame); const auto disposalMethod = prevFrame->getDisposalMethod(); @@ -247,7 +266,7 @@ SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, } SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, - const Options* options) { + const Options* options, SkPMColor ctable[], int* ctableCount) { if (kUnknown_SkColorType == info.colorType()) { return kInvalidConversion; } @@ -258,6 +277,8 @@ SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t return kInvalidParameters; } + CHECK_COLOR_TABLE; + if (!this->rewindIfNeeded()) { return kCouldNotRewind; } @@ -293,7 +314,14 @@ SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t // On an incomplete decode, the subclass will specify the number of scanlines that it decoded // successfully. int rowsDecoded = 0; - const Result result = this->onGetPixels(info, pixels, rowBytes, *options, &rowsDecoded); + const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount, + &rowsDecoded); + + if (ctableCount) { + if (kIncompleteInput == result || kSuccess == result || kErrorInInput == result) { + SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); + } + } // A return value of kIncompleteInput indicates a truncated image stream. // In this case, we will fill any uninitialized memory with a default value. @@ -314,8 +342,12 @@ SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t return result; } +SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { + return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); +} + SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* pixels, - size_t rowBytes, const SkCodec::Options* options) { + size_t rowBytes, const SkCodec::Options* options, SkPMColor* ctable, int* ctableCount) { fStartedIncrementalDecode = false; if (kUnknown_SkColorType == info.colorType()) { @@ -325,6 +357,9 @@ SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* p return kInvalidParameters; } + // Ensure that valid color ptrs are passed in for kIndex8 color type + CHECK_COLOR_TABLE; + // FIXME: If the rows come after the rows of a previous incremental decode, // we might be able to skip the rewind, but only the implementation knows // that. (e.g. PNG will always need to rewind, since we called longjmp, but @@ -364,7 +399,8 @@ SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* p fDstInfo = info; fOptions = *options; - const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, fOptions); + const Result result = this->onStartIncrementalDecode(info, pixels, rowBytes, + fOptions, ctable, ctableCount); if (kSuccess == result) { fStartedIncrementalDecode = true; } else if (kUnimplemented == result) { @@ -382,9 +418,11 @@ SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, void* p SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info, - const SkCodec::Options* options) { + 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 + CHECK_COLOR_TABLE; if (!this->rewindIfNeeded()) { return kCouldNotRewind; @@ -412,7 +450,7 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info, return kInvalidScale; } - const Result result = this->onStartScanlineDecode(info, *options); + const Result result = this->onStartScanlineDecode(info, *options, ctable, ctableCount); if (result != SkCodec::kSuccess) { return result; } @@ -423,6 +461,12 @@ SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info, return kSuccess; } +#undef CHECK_COLOR_TABLE + +SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info) { + return this->startScanlineDecode(info, nullptr, nullptr, nullptr); +} + int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) { if (fCurrScanline < 0) { return 0; @@ -486,7 +530,7 @@ uint64_t SkCodec::onGetFillValue(const SkImageInfo& dstInfo) const { return (kOpaque_SkAlphaType == fSrcInfo.alphaType()) ? opaqueColor : transparentColor; } default: { - // This not only handles the kN32 case, but also k565, kGray8, since + // This not only handles the kN32 case, but also k565, kGray8, kIndex8, since // the low bits are zeros. return (kOpaque_SkAlphaType == fSrcInfo.alphaType()) ? SK_ColorBLACK : SK_ColorTRANSPARENT; @@ -539,6 +583,7 @@ static inline SkColorSpaceXform::ColorFormat select_xform_format_ct(SkColorType case kBGRA_8888_SkColorType: return SkColorSpaceXform::kBGRA_8888_ColorFormat; case kRGB_565_SkColorType: + case kIndex_8_SkColorType: #ifdef SK_PMCOLOR_IS_RGBA return SkColorSpaceXform::kRGBA_8888_ColorFormat; #else |