diff options
author | Leon Scroggins III <scroggo@google.com> | 2018-03-05 14:19:40 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-06 13:39:35 +0000 |
commit | 2f8622029d265e79eb11df8eb06a29ff3faa7ac0 (patch) | |
tree | e787570075c128f21736d4ba5efd1428ca00e68d /tests/AnimatedImageTest.cpp | |
parent | bd6525304d448f9c1ce04bf6b10bc9306802823e (diff) |
Fix drawing SkAnimatedImages with transparency
Bug: b/74195953
Do not use SkBlendMode::kSrc, which overwrites the pixels that were
already present. Instead, blend normally.
Change-Id: Ie6843c6278212fddddd0ba0ae292fdb5eaf2342e
Reviewed-on: https://skia-review.googlesource.com/112200
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'tests/AnimatedImageTest.cpp')
-rw-r--r-- | tests/AnimatedImageTest.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/AnimatedImageTest.cpp b/tests/AnimatedImageTest.cpp index e0a640b7d8..6c7b0e5a55 100644 --- a/tests/AnimatedImageTest.cpp +++ b/tests/AnimatedImageTest.cpp @@ -15,6 +15,7 @@ #include "SkColor.h" #include "SkData.h" #include "SkImageInfo.h" +#include "SkPicture.h" #include "SkRefCnt.h" #include "SkSize.h" #include "SkString.h" @@ -27,6 +28,50 @@ #include <memory> #include <vector> +DEF_TEST(AnimatedImage_scaled, r) { + if (GetResourcePath().isEmpty()) { + return; + } + + const char* file = "images/alphabetAnim.gif"; + auto data = GetResourceAsData(file); + if (!data) { + ERRORF(r, "Could not get %s", file); + return; + } + + auto codec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(data)); + if (!codec) { + ERRORF(r, "Could not create codec for %s", file); + return; + } + + // Force the drawable follow its special case that requires scaling. + auto size = codec->getInfo().dimensions(); + size.set(size.width() - 5, size.height() - 5); + auto rect = SkIRect::MakeSize(size); + auto image = SkAnimatedImage::Make(std::move(codec), size, rect, nullptr); + if (!image) { + ERRORF(r, "Failed to create animated image for %s", file); + return; + } + + // Clear a bitmap to non-transparent and draw to it. pixels that are transparent + // in the image should not replace the original non-transparent color. + SkBitmap bm; + bm.allocPixels(SkImageInfo::MakeN32Premul(size.width(), size.height())); + bm.eraseColor(SK_ColorBLUE); + SkCanvas canvas(bm); + image->draw(&canvas); + for (int i = 0; i < size.width(); ++i) + for (int j = 0; j < size.height(); ++j) { + if (*bm.getAddr32(i, j) == SK_ColorTRANSPARENT) { + ERRORF(r, "Erased color underneath!"); + return; + } + } +} + DEF_TEST(AnimatedImage, r) { if (GetResourcePath().isEmpty()) { return; |