aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/CodecAnimTest.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2018-01-14 14:46:51 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-16 20:36:09 +0000
commit42ee2845673c38f6d70f0d8ddf7e26dce8aa61d3 (patch)
tree623988f152fca794623e25458bf55212fe5b670d /tests/CodecAnimTest.cpp
parent23e0cf29639459fb8695bf8174d82ae47fd0d0bb (diff)
Use SkAndroidCodec in SkAnimatedImage
Bug: b/63909536 Bug: b/63908092 SkAnimatedImage is designed around a specific Android use case, so move it into the android folders. Make SkAnimatedImage hold an SkAndroidCodec (instead of an SkCodec). Expose fCodec so that SkAnimatedImage can animate by using the internal SkCodec. Update the sample to use SkAndroidCodec. Allow webp to decode a scaled down animation. For RestoreBG frames, adjust the frameRect (which is erased) to account for the scaling. Add a test to verify that we decode a webp with a RestoreBG frame successfully. Disable scaling for later frames in other formats (GIF, for now), since the code for erasing a RestoreBG frame is currently unaware of the sampling. Change-Id: I5dd2b86138f2c7f6adcd08dce1bd49040f7dc224 Reviewed-on: https://skia-review.googlesource.com/94621 Commit-Queue: Leon Scroggins <scroggo@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
Diffstat (limited to 'tests/CodecAnimTest.cpp')
-rw-r--r--tests/CodecAnimTest.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/CodecAnimTest.cpp b/tests/CodecAnimTest.cpp
index b09c9251d1..f707f1e04c 100644
--- a/tests/CodecAnimTest.cpp
+++ b/tests/CodecAnimTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkAndroidCodec.h"
#include "SkBitmap.h"
#include "SkCodec.h"
#include "SkCommonFlags.h"
@@ -386,3 +387,52 @@ DEF_TEST(Codec_frames, r) {
}
}
}
+
+// Verify that a webp image can be animated scaled down. This image has a
+// kRestoreBG frame, so it is an interesting image to test. After decoding that
+// frame, we have to erase its rectangle. The rectangle has to be adjusted
+// based on the scaled size.
+DEF_TEST(AndroidCodec_animated, r) {
+ if (GetResourcePath().isEmpty()) {
+ return;
+ }
+
+ const char* file = "images/required.webp";
+ sk_sp<SkData> data(GetResourceAsData(file));
+ if (!data) {
+ ERRORF(r, "Missing %s", file);
+ return;
+ }
+
+ auto codec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(std::move(data)));
+ if (!codec) {
+ ERRORF(r, "Failed to decode %s", file);
+ return;
+ }
+
+ auto info = codec->getInfo().makeAlphaType(kPremul_SkAlphaType);
+
+ for (int sampleSize : { 8, 32, 100 }) {
+ auto dimensions = codec->codec()->getScaledDimensions(1.0f / sampleSize);
+ info = info.makeWH(dimensions.width(), dimensions.height());
+ SkBitmap bm;
+ bm.allocPixels(info);
+
+ SkCodec::Options options;
+ for (int i = 0; i < codec->codec()->getFrameCount(); ++i) {
+ SkCodec::FrameInfo frameInfo;
+ REPORTER_ASSERT(r, codec->codec()->getFrameInfo(i, &frameInfo));
+ if (5 == i) {
+ REPORTER_ASSERT(r, frameInfo.fDisposalMethod
+ == SkCodecAnimation::DisposalMethod::kRestoreBGColor);
+ }
+ options.fFrameIndex = i;
+ options.fPriorFrame = i - 1;
+ info = info.makeAlphaType(frameInfo.fAlphaType);
+
+ const auto result = codec->codec()->getPixels(info, bm.getPixels(), bm.rowBytes(),
+ &options);
+ REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+ }
+ }
+}