diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-06-07 09:31:23 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-07 15:43:07 +0000 |
commit | 91f0f7332f37de42ee2fc417fb401af3a4e9dfde (patch) | |
tree | 7eda76fc11131429e2091981ec860864561b638e /src | |
parent | 89c8fecb62e664749211668dff2148bbc27090cc (diff) |
Fix alpha issues in SkGifCodec
- Call conversion_possible with the proper alpha type for the frame.
- Always use kUnpremul for the transform. Previously we used the alpha
type for the first frame. If it was opaque and a later frame was not,
this would be incorrect.
Also fix Codec_frames test. Most of the tests were not running due to
a return statement in a loop. Change that to continue, and correct
errors in the test. Provide better debugging information.
Change-Id: Icd40c09526b1d599168bfe90d93d8ddcdd9ca20f
Reviewed-on: https://skia-review.googlesource.com/18935
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/codec/SkGifCodec.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp index 3f4e551fc8..f0495bc4b3 100644 --- a/src/codec/SkGifCodec.cpp +++ b/src/codec/SkGifCodec.cpp @@ -163,6 +163,7 @@ int SkGifCodec::onGetRepetitionCount() { } static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType; +static const SkAlphaType kXformAlphaType = kUnpremul_SkAlphaType; void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex) { SkColorType colorTableColorType = dstInfo.colorType(); @@ -178,7 +179,8 @@ void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex fCurrColorTable.reset(new SkColorTable(&color, 1)); } else if (this->colorXform() && !this->xformOnDecode()) { SkPMColor dstColors[256]; - this->applyColorXform(dstColors, currColorTable->readColors(), currColorTable->count()); + this->applyColorXform(dstColors, currColorTable->readColors(), currColorTable->count(), + kXformAlphaType); fCurrColorTable.reset(new SkColorTable(dstColors, currColorTable->count())); } else { fCurrColorTable = std::move(currColorTable); @@ -188,18 +190,6 @@ void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColor* inputColorPtr, int* inputColorCount, const Options& opts) { - // Check for valid input parameters - if (!conversion_possible(dstInfo, this->getInfo()) || - !this->initializeColorXform(dstInfo, opts.fPremulBehavior)) - { - return gif_error("Cannot convert input type to output type.\n", kInvalidConversion); - } - - if (this->xformOnDecode()) { - fXformBuffer.reset(new uint32_t[dstInfo.width()]); - sk_bzero(fXformBuffer.get(), dstInfo.width() * sizeof(uint32_t)); - } - if (opts.fSubset) { return gif_error("Subsets not supported.\n", kUnimplemented); } @@ -244,13 +234,27 @@ SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColo return gif_error("frame index out of range!\n", kIncompleteInput); } - if (!fReader->frameContext(frameIndex)->reachedStartOfData()) { + const auto* frame = fReader->frameContext(frameIndex); + if (!frame->reachedStartOfData()) { // We have parsed enough to know that there is a color map, but cannot // parse the map itself yet. Exit now, so we do not build an incorrect // table. return gif_error("color map not available yet\n", kIncompleteInput); } + const auto at = frame->hasAlpha() ? kUnpremul_SkAlphaType : kOpaque_SkAlphaType; + const auto srcInfo = this->getInfo().makeAlphaType(at); + if (!conversion_possible(dstInfo, srcInfo) || + !this->initializeColorXform(dstInfo, opts.fPremulBehavior)) + { + return gif_error("Cannot convert input type to output type.\n", kInvalidConversion); + } + + if (this->xformOnDecode()) { + fXformBuffer.reset(new uint32_t[dstInfo.width()]); + sk_bzero(fXformBuffer.get(), dstInfo.width() * sizeof(uint32_t)); + } + fTmpBuffer.reset(new uint8_t[dstInfo.minRowBytes()]); this->initializeColorTable(dstInfo, frameIndex); @@ -510,7 +514,7 @@ void SkGifCodec::applyXformRow(const SkImageInfo& dstInfo, void* dst, const uint fSwizzler->swizzle(fXformBuffer.get(), src); const int xformWidth = get_scaled_dimension(dstInfo.width(), fSwizzler->sampleX()); - this->applyColorXform(dst, fXformBuffer.get(), xformWidth); + this->applyColorXform(dst, fXformBuffer.get(), xformWidth, kXformAlphaType); } else { fSwizzler->swizzle(dst, src); } |