scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/codec/SkAndroidCodec.h" |
| 9 | #include "include/codec/SkCodec.h" |
| 10 | #include "include/codec/SkCodecAnimation.h" |
| 11 | #include "include/core/SkBitmap.h" |
| 12 | #include "include/core/SkData.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 13 | #include "include/core/SkImage.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkImageInfo.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 15 | #include "include/core/SkRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/core/SkRefCnt.h" |
| 17 | #include "include/core/SkSize.h" |
| 18 | #include "include/core/SkString.h" |
| 19 | #include "include/core/SkTypes.h" |
| 20 | #include "include/utils/SkAnimCodecPlayer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "tests/CodecPriv.h" |
| 22 | #include "tests/Test.h" |
| 23 | #include "tools/Resources.h" |
| 24 | #include "tools/ToolUtils.h" |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 25 | |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 26 | #include <stdio.h> |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 27 | #include <cstring> |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 28 | #include <initializer_list> |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 29 | #include <memory> |
| 30 | #include <utility> |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 31 | #include <vector> |
| 32 | |
Leon Scroggins III | 7d22a33 | 2017-04-12 17:01:26 -0400 | [diff] [blame] | 33 | DEF_TEST(Codec_trunc, r) { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 34 | sk_sp<SkData> data(GetResourceAsData("images/box.gif")); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 35 | if (!data) { |
| 36 | return; |
| 37 | } |
Leon Scroggins III | e93ec68 | 2018-10-26 09:25:51 -0400 | [diff] [blame] | 38 | // See also Codec_GifTruncated2 in GifTest.cpp for this magic 23. |
| 39 | // |
| 40 | // TODO: just move this getFrameInfo call to Codec_GifTruncated2? |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 41 | SkCodec::MakeFromData(SkData::MakeSubset(data.get(), 0, 23))->getFrameInfo(); |
Leon Scroggins III | 7d22a33 | 2017-04-12 17:01:26 -0400 | [diff] [blame] | 42 | } |
| 43 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 44 | // 565 does not support alpha, but there is no reason for it not to support an |
| 45 | // animated image with a frame that has alpha but then blends onto an opaque |
| 46 | // frame making the result opaque. Test that we can decode such a frame. |
| 47 | DEF_TEST(Codec_565, r) { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 48 | sk_sp<SkData> data(GetResourceAsData("images/blendBG.webp")); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 49 | if (!data) { |
| 50 | return; |
| 51 | } |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 52 | std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(std::move(data))); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 53 | auto info = codec->getInfo().makeColorType(kRGB_565_SkColorType); |
| 54 | SkBitmap bm; |
| 55 | bm.allocPixels(info); |
| 56 | |
| 57 | SkCodec::Options options; |
| 58 | options.fFrameIndex = 1; |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 59 | options.fPriorFrame = SkCodec::kNoFrame; |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 60 | |
| 61 | const auto result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 62 | &options); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 63 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 64 | } |
| 65 | |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 66 | static bool restore_previous(const SkCodec::FrameInfo& info) { |
| 67 | return info.fDisposalMethod == SkCodecAnimation::DisposalMethod::kRestorePrevious; |
| 68 | } |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 69 | |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 70 | namespace { |
| 71 | SkString to_string(bool boolean) { return boolean ? SkString("true") : SkString("false"); } |
| 72 | SkString to_string(SkCodecAnimation::Blend blend) { |
| 73 | switch (blend) { |
| 74 | case SkCodecAnimation::Blend::kSrcOver: |
| 75 | return SkString("kSrcOver"); |
| 76 | case SkCodecAnimation::Blend::kSrc: |
| 77 | return SkString("kSrc"); |
| 78 | default: |
| 79 | return SkString(); |
| 80 | } |
| 81 | } |
| 82 | SkString to_string(SkIRect rect) { |
| 83 | return SkStringPrintf("{ %i, %i, %i, %i }", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 84 | } |
| 85 | |
| 86 | template <typename T> |
| 87 | void reporter_assert_equals(skiatest::Reporter* r, const char* name, int i, const char* prop, |
| 88 | T expected, T actual) { |
| 89 | REPORTER_ASSERT(r, expected == actual, "%s's frame %i has wrong %s! expected:" |
| 90 | " %s\tactual: %s", name, i, prop, to_string(expected).c_str(), |
| 91 | to_string(actual).c_str()); |
| 92 | } |
| 93 | } // namespace |
| 94 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 95 | DEF_TEST(Codec_frames, r) { |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 96 | constexpr int kNoFrame = SkCodec::kNoFrame; |
| 97 | constexpr SkAlphaType kOpaque = kOpaque_SkAlphaType; |
| 98 | constexpr SkAlphaType kUnpremul = kUnpremul_SkAlphaType; |
| 99 | constexpr SkCodecAnimation::DisposalMethod kKeep = |
| 100 | SkCodecAnimation::DisposalMethod::kKeep; |
| 101 | constexpr SkCodecAnimation::DisposalMethod kRestoreBG = |
| 102 | SkCodecAnimation::DisposalMethod::kRestoreBGColor; |
| 103 | constexpr SkCodecAnimation::DisposalMethod kRestorePrev = |
| 104 | SkCodecAnimation::DisposalMethod::kRestorePrevious; |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 105 | constexpr auto kSrcOver = SkCodecAnimation::Blend::kSrcOver; |
| 106 | constexpr auto kSrc = SkCodecAnimation::Blend::kSrc; |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 107 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 108 | static const struct { |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 109 | const char* fName; |
| 110 | int fFrameCount; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 111 | // One less than fFramecount, since the first frame is always |
| 112 | // independent. |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 113 | std::vector<int> fRequiredFrames; |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 114 | // Same, since the first frame should match getInfo |
| 115 | std::vector<SkAlphaType> fAlphas; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 116 | // The size of this one should match fFrameCount for animated, empty |
| 117 | // otherwise. |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 118 | std::vector<int> fDurations; |
| 119 | int fRepetitionCount; |
| 120 | std::vector<SkCodecAnimation::DisposalMethod> fDisposalMethods; |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 121 | std::vector<bool> fAlphaWithinBounds; |
| 122 | std::vector<SkCodecAnimation::Blend> fBlends; |
| 123 | std::vector<SkIRect> fFrameRects; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 124 | } gRecs[] = { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 125 | { "images/required.gif", 7, |
Chris Blume | 0b5e7d1 | 2017-09-27 13:23:41 -0700 | [diff] [blame] | 126 | { 0, 1, 2, 3, 4, 5 }, |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 127 | { kOpaque, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul }, |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 128 | { 100, 100, 100, 100, 100, 100, 100 }, |
| 129 | 0, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 130 | { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep }, |
| 131 | { false, true, true, true, true, true, true }, |
| 132 | { kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, |
| 133 | kSrcOver }, |
| 134 | { {0, 0, 100, 100}, {0, 0, 75, 75}, {0, 0, 50, 50}, {0, 0, 60, 60}, |
| 135 | {0, 0, 100, 100}, {0, 0, 50, 50}, {0, 0, 75, 75}}, |
| 136 | }, |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 137 | { "images/alphabetAnim.gif", 13, |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 138 | { kNoFrame, 0, 0, 0, 0, 5, 6, kNoFrame, kNoFrame, 9, 10, 11 }, |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 139 | { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, |
| 140 | kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul }, |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 141 | { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }, |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 142 | 0, |
| 143 | { kKeep, kRestorePrev, kRestorePrev, kRestorePrev, kRestorePrev, |
| 144 | kRestoreBG, kKeep, kRestoreBG, kRestoreBG, kKeep, kKeep, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 145 | kRestoreBG, kKeep }, |
| 146 | { true, false, true, false, true, true, true, true, true, true, true, true, true }, |
| 147 | { kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, |
| 148 | kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, |
| 149 | kSrcOver }, |
| 150 | { {25, 25, 75, 75}, {25, 25, 75, 75}, {25, 25, 75, 75}, {37, 37, 62, 62}, |
| 151 | {37, 37, 62, 62}, {25, 25, 75, 75}, {0, 0, 50, 50}, {0, 0, 100, 100}, |
| 152 | {25, 25, 75, 75}, {25, 25, 75, 75}, {0, 0, 100, 100}, {25, 25, 75, 75}, |
| 153 | {37, 37, 62, 62}}, |
| 154 | }, |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 155 | { "images/randPixelsAnim2.gif", 4, |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 156 | // required frames |
| 157 | { 0, 0, 1 }, |
| 158 | // alphas |
| 159 | { kOpaque, kOpaque, kOpaque }, |
| 160 | // durations |
| 161 | { 0, 1000, 170, 40 }, |
| 162 | // repetition count |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 163 | 0, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 164 | { kKeep, kKeep, kRestorePrev, kKeep }, |
| 165 | { false, true, false, false }, |
| 166 | { kSrcOver, kSrcOver, kSrcOver, kSrcOver }, |
| 167 | { {0, 0, 8, 8}, {6, 6, 8, 8}, {4, 4, 8, 8}, {7, 0, 8, 8} }, |
| 168 | }, |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 169 | { "images/randPixelsAnim.gif", 13, |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 170 | // required frames |
Chris Blume | 0b5e7d1 | 2017-09-27 13:23:41 -0700 | [diff] [blame] | 171 | { 0, 1, 2, 3, 4, 3, 6, 7, 7, 7, 9, 9 }, |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 172 | { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, |
| 173 | kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul }, |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 174 | // durations |
| 175 | { 0, 1000, 170, 40, 220, 7770, 90, 90, 90, 90, 90, 90, 90 }, |
| 176 | // repetition count |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 177 | 0, |
| 178 | { kKeep, kKeep, kKeep, kKeep, kRestoreBG, kRestoreBG, kRestoreBG, |
| 179 | kRestoreBG, kRestorePrev, kRestoreBG, kRestorePrev, kRestorePrev, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 180 | kRestorePrev, }, |
| 181 | { false, true, true, false, true, true, false, false, true, true, false, false, |
| 182 | true }, |
| 183 | { kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, |
| 184 | kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, kSrcOver, |
| 185 | kSrcOver }, |
| 186 | { {4, 4, 12, 12}, {4, 4, 12, 12}, {4, 4, 12, 12}, {0, 0, 8, 8}, {8, 8, 16, 16}, |
| 187 | {8, 8, 16, 16}, {8, 8, 16, 16}, {2, 2, 10, 10}, {7, 7, 15, 15}, {7, 7, 15, 15}, |
| 188 | {7, 7, 15, 15}, {0, 0, 8, 8}, {14, 14, 16, 16} }, |
| 189 | }, |
| 190 | { "images/box.gif", 1, {}, {}, {}, 0, { kKeep }, {}, {}, {} }, |
| 191 | { "images/color_wheel.gif", 1, {}, {}, {}, 0, { kKeep }, {}, {}, {} }, |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 192 | { "images/test640x479.gif", 4, { 0, 1, 2 }, |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 193 | { kOpaque, kOpaque, kOpaque }, |
| 194 | { 200, 200, 200, 200 }, |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 195 | SkCodec::kRepetitionCountInfinite, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 196 | { kKeep, kKeep, kKeep, kKeep }, |
| 197 | { false, true, true, true }, |
| 198 | { kSrcOver, kSrcOver, kSrcOver, kSrcOver }, |
| 199 | { {0, 0, 640, 479}, {0, 0, 640, 479}, {0, 0, 640, 479}, {0, 0, 640, 479} }, |
| 200 | }, |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 201 | { "images/colorTables.gif", 2, { 0 }, { kOpaque }, { 1000, 1000 }, 5, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 202 | { kKeep, kKeep }, {false, true}, { kSrcOver, kSrcOver }, |
| 203 | { {0, 0, 640, 400}, {0, 0, 640, 200}}, |
| 204 | }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 205 | |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 206 | { "images/arrow.png", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
| 207 | { "images/google_chrome.ico", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
| 208 | { "images/brickwork-texture.jpg", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 209 | #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 210 | { "images/dng_with_preview.dng", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 211 | #endif |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 212 | { "images/mandrill.wbmp", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
| 213 | { "images/randPixels.bmp", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
| 214 | { "images/yellow_rose.webp", 1, {}, {}, {}, 0, {}, {}, {}, {} }, |
Leon Scroggins | bc098ef | 2020-10-27 15:24:18 -0400 | [diff] [blame] | 215 | { "images/stoplight.webp", 3, { 0, 1 }, { kOpaque, kOpaque }, |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 216 | { 1000, 500, 1000 }, SkCodec::kRepetitionCountInfinite, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 217 | { kKeep, kKeep, kKeep }, {false, false, false}, |
| 218 | {kSrcOver, kSrcOver, kSrcOver}, |
| 219 | { {0, 0, 11, 29}, {2, 10, 9, 27}, {2, 2, 9, 18}}, |
| 220 | }, |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 221 | { "images/blendBG.webp", 7, |
| 222 | { 0, kNoFrame, kNoFrame, kNoFrame, 4, 4 }, |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 223 | { kOpaque, kOpaque, kUnpremul, kOpaque, kUnpremul, kUnpremul }, |
Leon Scroggins III | ae834f57 | 2019-12-10 14:24:18 -0500 | [diff] [blame] | 224 | { 525, 500, 525, 437, 609, 729, 444 }, |
Leon Scroggins III | ae834f57 | 2019-12-10 14:24:18 -0500 | [diff] [blame] | 225 | 6, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 226 | { kKeep, kKeep, kKeep, kKeep, kKeep, kKeep, kKeep }, |
| 227 | { false, true, false, true, false, true, true }, |
| 228 | { kSrc, kSrcOver, kSrc, kSrc, kSrc, kSrc, kSrc }, |
| 229 | { {0, 0, 200, 200}, {0, 0, 200, 200}, {0, 0, 200, 200}, {0, 0, 200, 200}, |
| 230 | {0, 0, 200, 200}, {100, 100, 200, 200}, {100, 100, 200, 200} }, |
| 231 | }, |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 232 | { "images/required.webp", 7, |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 233 | { 0, 1, 1, kNoFrame, 4, 4 }, |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 234 | { kOpaque, kUnpremul, kUnpremul, kOpaque, kOpaque, kOpaque }, |
| 235 | { 100, 100, 100, 100, 100, 100, 100 }, |
Leon Scroggins III | ae834f57 | 2019-12-10 14:24:18 -0500 | [diff] [blame] | 236 | 0, |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 237 | { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep }, |
| 238 | { false, false, false, false, false, false, false }, |
| 239 | { kSrc, kSrcOver, kSrcOver, kSrcOver, kSrc, kSrcOver, |
| 240 | kSrcOver }, |
| 241 | { {0, 0, 100, 100}, {0, 0, 75, 75}, {0, 0, 50, 50}, {0, 0, 60, 60}, |
| 242 | {0, 0, 100, 100}, {0, 0, 50, 50}, {0, 0, 75, 75}}, |
| 243 | }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 246 | for (const auto& rec : gRecs) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 247 | sk_sp<SkData> data(GetResourceAsData(rec.fName)); |
| 248 | if (!data) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 249 | // Useful error statement, but sometimes people run tests without |
| 250 | // resources, and they do not want to see these messages. |
| 251 | //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName); |
| 252 | continue; |
| 253 | } |
| 254 | |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 255 | std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data)); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 256 | if (!codec) { |
| 257 | ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); |
| 258 | continue; |
| 259 | } |
| 260 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 261 | { |
| 262 | SkCodec::FrameInfo frameInfo; |
| 263 | REPORTER_ASSERT(r, !codec->getFrameInfo(0, &frameInfo)); |
| 264 | } |
| 265 | |
scroggo | e71b1a1 | 2016-11-01 08:28:28 -0700 | [diff] [blame] | 266 | const int repetitionCount = codec->getRepetitionCount(); |
| 267 | if (repetitionCount != rec.fRepetitionCount) { |
| 268 | ERRORF(r, "%s repetition count does not match! expected: %i\tactual: %i", |
| 269 | rec.fName, rec.fRepetitionCount, repetitionCount); |
| 270 | } |
| 271 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 272 | const int expected = rec.fFrameCount; |
| 273 | if (rec.fRequiredFrames.size() + 1 != static_cast<size_t>(expected)) { |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 274 | ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expected: %i\tactual: %zu", |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 275 | rec.fName, expected - 1, rec.fRequiredFrames.size()); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 276 | continue; |
| 277 | } |
| 278 | |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 279 | if (expected > 1) { |
| 280 | if (rec.fDurations.size() != static_cast<size_t>(expected)) { |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 281 | ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i\tactual: %zu", |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 282 | rec.fName, expected, rec.fDurations.size()); |
| 283 | continue; |
| 284 | } |
| 285 | |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 286 | if (rec.fAlphas.size() + 1 != static_cast<size_t>(expected)) { |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 287 | ERRORF(r, "'%s' has wrong number entries in fAlphas; expected: %i\tactual: %zu", |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 288 | rec.fName, expected - 1, rec.fAlphas.size()); |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 289 | continue; |
| 290 | } |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 291 | |
| 292 | if (rec.fDisposalMethods.size() != static_cast<size_t>(expected)) { |
| 293 | ERRORF(r, "'%s' has wrong number entries in fDisposalMethods; " |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 294 | "expected %i\tactual: %zu", |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 295 | rec.fName, expected, rec.fDisposalMethods.size()); |
| 296 | continue; |
| 297 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 300 | enum class TestMode { |
| 301 | kVector, |
| 302 | kIndividual, |
| 303 | }; |
| 304 | |
| 305 | for (auto mode : { TestMode::kVector, TestMode::kIndividual }) { |
| 306 | // Re-create the codec to reset state and test parsing. |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 307 | codec = SkCodec::MakeFromData(data); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 308 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 309 | int frameCount; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 310 | std::vector<SkCodec::FrameInfo> frameInfos; |
| 311 | switch (mode) { |
| 312 | case TestMode::kVector: |
| 313 | frameInfos = codec->getFrameInfo(); |
| 314 | // getFrameInfo returns empty set for non-animated. |
| 315 | frameCount = frameInfos.empty() ? 1 : frameInfos.size(); |
| 316 | break; |
| 317 | case TestMode::kIndividual: |
| 318 | frameCount = codec->getFrameCount(); |
| 319 | break; |
| 320 | } |
| 321 | |
| 322 | if (frameCount != expected) { |
| 323 | ERRORF(r, "'%s' expected frame count: %i\tactual: %i", |
| 324 | rec.fName, expected, frameCount); |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | // From here on, we are only concerned with animated images. |
| 329 | if (1 == frameCount) { |
| 330 | continue; |
| 331 | } |
| 332 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 333 | for (int i = 0; i < frameCount; i++) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 334 | SkCodec::FrameInfo frameInfo; |
| 335 | switch (mode) { |
| 336 | case TestMode::kVector: |
| 337 | frameInfo = frameInfos[i]; |
| 338 | break; |
| 339 | case TestMode::kIndividual: |
| 340 | REPORTER_ASSERT(r, codec->getFrameInfo(i, nullptr)); |
| 341 | REPORTER_ASSERT(r, codec->getFrameInfo(i, &frameInfo)); |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | if (rec.fDurations[i] != frameInfo.fDuration) { |
| 346 | ERRORF(r, "%s frame %i's durations do not match! expected: %i\tactual: %i", |
| 347 | rec.fName, i, rec.fDurations[i], frameInfo.fDuration); |
| 348 | } |
| 349 | |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 350 | auto to_string = [](SkAlphaType alpha) { |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 351 | switch (alpha) { |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 352 | case kUnpremul_SkAlphaType: |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 353 | return "unpremul"; |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 354 | case kOpaque_SkAlphaType: |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 355 | return "opaque"; |
| 356 | default: |
Leon Scroggins III | ae79f32 | 2017-08-18 10:53:24 -0400 | [diff] [blame] | 357 | SkASSERT(false); |
| 358 | return "unknown"; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 359 | } |
| 360 | }; |
| 361 | |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 362 | auto expectedAlpha = 0 == i ? codec->getInfo().alphaType() : rec.fAlphas[i-1]; |
| 363 | auto alpha = frameInfo.fAlphaType; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 364 | if (expectedAlpha != alpha) { |
| 365 | ERRORF(r, "%s's frame %i has wrong alpha type! expected: %s\tactual: %s", |
| 366 | rec.fName, i, to_string(expectedAlpha), to_string(alpha)); |
| 367 | } |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 368 | |
| 369 | if (0 == i) { |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 370 | REPORTER_ASSERT(r, frameInfo.fRequiredFrame == SkCodec::kNoFrame); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 371 | } else if (rec.fRequiredFrames[i-1] != frameInfo.fRequiredFrame) { |
| 372 | ERRORF(r, "%s's frame %i has wrong dependency! expected: %i\tactual: %i", |
| 373 | rec.fName, i, rec.fRequiredFrames[i-1], frameInfo.fRequiredFrame); |
| 374 | } |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 375 | |
| 376 | REPORTER_ASSERT(r, frameInfo.fDisposalMethod == rec.fDisposalMethods[i]); |
Leon Scroggins III | 469d67e | 2020-11-11 12:45:40 -0500 | [diff] [blame] | 377 | |
| 378 | reporter_assert_equals<bool>(r, rec.fName, i, "alpha within bounds", |
| 379 | rec.fAlphaWithinBounds[i], |
| 380 | frameInfo.fHasAlphaWithinBounds); |
| 381 | |
| 382 | reporter_assert_equals(r, rec.fName, i, "blend mode", rec.fBlends[i], |
| 383 | frameInfo.fBlend); |
| 384 | |
| 385 | reporter_assert_equals(r, rec.fName, i, "frame rect", rec.fFrameRects[i], |
| 386 | frameInfo.fFrameRect); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if (TestMode::kIndividual == mode) { |
| 390 | // No need to test decoding twice. |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 391 | continue; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 394 | // Compare decoding in multiple ways: |
| 395 | // - Start from scratch for each frame. |codec| will have to decode the required frame |
| 396 | // (and any it depends on) to decode. This is stored in |cachedFrames|. |
| 397 | // - Provide the frame that a frame depends on, so |codec| just has to blend. |
| 398 | // - Provide a frame after the required frame, which will be covered up by the newest |
| 399 | // frame. |
| 400 | // All should look the same. |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 401 | std::vector<SkBitmap> cachedFrames(frameCount); |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 402 | const auto info = codec->getInfo().makeColorType(kN32_SkColorType); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 403 | |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 404 | auto decode = [&](SkBitmap* bm, int index, int cachedIndex) { |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 405 | auto decodeInfo = info; |
| 406 | if (index > 0) { |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 407 | decodeInfo = info.makeAlphaType(frameInfos[index].fAlphaType); |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 408 | } |
| 409 | bm->allocPixels(decodeInfo); |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 410 | if (cachedIndex != SkCodec::kNoFrame) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 411 | // First copy the pixels from the cached frame |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 412 | const bool success = |
| 413 | ToolUtils::copy_to(bm, kN32_SkColorType, cachedFrames[cachedIndex]); |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 414 | REPORTER_ASSERT(r, success); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 415 | } |
| 416 | SkCodec::Options opts; |
| 417 | opts.fFrameIndex = index; |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 418 | opts.fPriorFrame = cachedIndex; |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 419 | const auto result = codec->getPixels(decodeInfo, bm->getPixels(), bm->rowBytes(), |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 420 | &opts); |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 421 | if (cachedIndex != SkCodec::kNoFrame && |
| 422 | restore_previous(frameInfos[cachedIndex])) { |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 423 | if (result == SkCodec::kInvalidParameters) { |
| 424 | return true; |
| 425 | } |
| 426 | ERRORF(r, "Using a kRestorePrevious frame as fPriorFrame should fail"); |
| 427 | return false; |
| 428 | } |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 429 | if (result != SkCodec::kSuccess) { |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 430 | ERRORF(r, "Failed to decode frame %i from %s when providing prior frame %i, " |
| 431 | "error %i", index, rec.fName, cachedIndex, result); |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 432 | } |
| 433 | return result == SkCodec::kSuccess; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 434 | }; |
| 435 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 436 | for (int i = 0; i < frameCount; i++) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 437 | SkBitmap& cachedFrame = cachedFrames[i]; |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 438 | if (!decode(&cachedFrame, i, SkCodec::kNoFrame)) { |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 439 | continue; |
| 440 | } |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 441 | const auto reqFrame = frameInfos[i].fRequiredFrame; |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 442 | if (reqFrame == SkCodec::kNoFrame) { |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 443 | // Nothing to compare against. |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame] | 444 | continue; |
| 445 | } |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 446 | for (int j = reqFrame; j < i; j++) { |
| 447 | SkBitmap frame; |
| 448 | if (restore_previous(frameInfos[j])) { |
| 449 | (void) decode(&frame, i, j); |
| 450 | continue; |
| 451 | } |
| 452 | if (!decode(&frame, i, j)) { |
| 453 | continue; |
| 454 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 455 | |
Leon Scroggins III | 33deb7e | 2017-06-07 12:31:51 -0400 | [diff] [blame] | 456 | // Now verify they're equal. |
| 457 | const size_t rowLen = info.bytesPerPixel() * info.width(); |
| 458 | for (int y = 0; y < info.height(); y++) { |
| 459 | const void* cachedAddr = cachedFrame.getAddr(0, y); |
| 460 | SkASSERT(cachedAddr != nullptr); |
| 461 | const void* addr = frame.getAddr(0, y); |
| 462 | SkASSERT(addr != nullptr); |
| 463 | const bool lineMatches = memcmp(cachedAddr, addr, rowLen) == 0; |
| 464 | if (!lineMatches) { |
| 465 | SkString name = SkStringPrintf("cached_%i", i); |
| 466 | write_bm(name.c_str(), cachedFrame); |
| 467 | name = SkStringPrintf("frame_%i", i); |
| 468 | write_bm(name.c_str(), frame); |
| 469 | ERRORF(r, "%s's frame %i is different (starting from line %i) when " |
| 470 | "providing prior frame %i!", rec.fName, i, y, j); |
| 471 | break; |
| 472 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 473 | } |
| 474 | } |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 475 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 479 | |
Leon Scroggins | 1340dbd | 2020-11-09 14:18:12 -0500 | [diff] [blame] | 480 | // Verify that an image can be animated scaled down. These images have a |
| 481 | // kRestoreBG frame, so they are interesting to test. After decoding that |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 482 | // frame, we have to erase its rectangle. The rectangle has to be adjusted |
| 483 | // based on the scaled size. |
Leon Scroggins | 1340dbd | 2020-11-09 14:18:12 -0500 | [diff] [blame] | 484 | static void test_animated_AndroidCodec(skiatest::Reporter* r, const char* file) { |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 485 | if (GetResourcePath().isEmpty()) { |
| 486 | return; |
| 487 | } |
| 488 | |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 489 | sk_sp<SkData> data(GetResourceAsData(file)); |
| 490 | if (!data) { |
| 491 | ERRORF(r, "Missing %s", file); |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | auto codec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(std::move(data))); |
| 496 | if (!codec) { |
| 497 | ERRORF(r, "Failed to decode %s", file); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | auto info = codec->getInfo().makeAlphaType(kPremul_SkAlphaType); |
| 502 | |
| 503 | for (int sampleSize : { 8, 32, 100 }) { |
| 504 | auto dimensions = codec->codec()->getScaledDimensions(1.0f / sampleSize); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 505 | info = info.makeDimensions(dimensions); |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 506 | SkBitmap bm; |
| 507 | bm.allocPixels(info); |
| 508 | |
| 509 | SkCodec::Options options; |
| 510 | for (int i = 0; i < codec->codec()->getFrameCount(); ++i) { |
| 511 | SkCodec::FrameInfo frameInfo; |
| 512 | REPORTER_ASSERT(r, codec->codec()->getFrameInfo(i, &frameInfo)); |
| 513 | if (5 == i) { |
| 514 | REPORTER_ASSERT(r, frameInfo.fDisposalMethod |
| 515 | == SkCodecAnimation::DisposalMethod::kRestoreBGColor); |
| 516 | } |
| 517 | options.fFrameIndex = i; |
| 518 | options.fPriorFrame = i - 1; |
| 519 | info = info.makeAlphaType(frameInfo.fAlphaType); |
| 520 | |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 521 | auto result = codec->codec()->getPixels(info, bm.getPixels(), bm.rowBytes(), |
| 522 | &options); |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 523 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 524 | |
| 525 | // Now compare to not using prior frame. |
| 526 | SkBitmap bm2; |
| 527 | bm2.allocPixels(info); |
| 528 | |
Nigel Tao | 66bc524 | 2018-08-22 10:56:03 +1000 | [diff] [blame] | 529 | options.fPriorFrame = SkCodec::kNoFrame; |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 530 | result = codec->codec()->getPixels(info, bm2.getPixels(), bm2.rowBytes(), |
| 531 | &options); |
| 532 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 533 | |
| 534 | for (int y = 0; y < info.height(); ++y) { |
John Stiles | c1c3c6d | 2020-08-15 23:22:53 -0400 | [diff] [blame] | 535 | if (0 != memcmp(bm.getAddr32(0, y), bm2.getAddr32(0, y), info.minRowBytes())) { |
Leon Scroggins III | 7916c0e | 2018-05-24 13:04:06 -0400 | [diff] [blame] | 536 | ERRORF(r, "pixel mismatch for sample size %i, frame %i resulting in " |
| 537 | "dimensions %i x %i line %i\n", |
| 538 | sampleSize, i, info.width(), info.height(), y); |
| 539 | break; |
| 540 | } |
| 541 | } |
Leon Scroggins III | 42ee284 | 2018-01-14 14:46:51 -0500 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | } |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 545 | |
Leon Scroggins | 1340dbd | 2020-11-09 14:18:12 -0500 | [diff] [blame] | 546 | DEF_TEST(AndroidCodec_animated, r) { |
| 547 | test_animated_AndroidCodec(r, "images/required.webp"); |
| 548 | } |
| 549 | |
| 550 | DEF_TEST(AndroidCodec_animated_gif, r) { |
| 551 | test_animated_AndroidCodec(r, "images/required.gif"); |
| 552 | } |
| 553 | |
Leon Scroggins | bc098ef | 2020-10-27 15:24:18 -0400 | [diff] [blame] | 554 | DEF_TEST(EncodedOriginToMatrixTest, r) { |
| 555 | // SkAnimCodecPlayer relies on the fact that these matrices are invertible. |
| 556 | for (auto origin : { kTopLeft_SkEncodedOrigin , |
| 557 | kTopRight_SkEncodedOrigin , |
| 558 | kBottomRight_SkEncodedOrigin , |
| 559 | kBottomLeft_SkEncodedOrigin , |
| 560 | kLeftTop_SkEncodedOrigin , |
| 561 | kRightTop_SkEncodedOrigin , |
| 562 | kRightBottom_SkEncodedOrigin , |
| 563 | kLeftBottom_SkEncodedOrigin }) { |
| 564 | // Arbitrary output dimensions. |
| 565 | auto matrix = SkEncodedOriginToMatrix(origin, 100, 80); |
| 566 | REPORTER_ASSERT(r, matrix.invert(nullptr)); |
| 567 | } |
| 568 | } |
| 569 | |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 570 | DEF_TEST(AnimCodecPlayer, r) { |
| 571 | static constexpr struct { |
| 572 | const char* fFile; |
| 573 | uint32_t fDuration; |
| 574 | SkISize fSize; |
| 575 | } gTests[] = { |
Leon Scroggins | bc098ef | 2020-10-27 15:24:18 -0400 | [diff] [blame] | 576 | { "images/alphabetAnim.gif" , 1300, {100, 100} }, |
| 577 | { "images/randPixels.gif" , 0, { 8, 8} }, |
| 578 | { "images/randPixels.jpg" , 0, { 8, 8} }, |
| 579 | { "images/randPixels.png" , 0, { 8, 8} }, |
| 580 | { "images/stoplight.webp" , 2500, { 11, 29} }, |
| 581 | { "images/stoplight_h.webp" , 2500, { 29, 11} }, |
| 582 | { "images/orientation/1.webp", 0, {100, 80} }, |
| 583 | { "images/orientation/2.webp", 0, {100, 80} }, |
| 584 | { "images/orientation/3.webp", 0, {100, 80} }, |
| 585 | { "images/orientation/4.webp", 0, {100, 80} }, |
| 586 | { "images/orientation/5.webp", 0, {100, 80} }, |
| 587 | { "images/orientation/6.webp", 0, {100, 80} }, |
| 588 | { "images/orientation/7.webp", 0, {100, 80} }, |
| 589 | { "images/orientation/8.webp", 0, {100, 80} }, |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 590 | }; |
| 591 | |
| 592 | for (const auto& test : gTests) { |
| 593 | auto codec = SkCodec::MakeFromData(GetResourceAsData(test.fFile)); |
| 594 | REPORTER_ASSERT(r, codec); |
| 595 | |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 596 | auto player = std::make_unique<SkAnimCodecPlayer>(std::move(codec)); |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 597 | REPORTER_ASSERT(r, player->duration() == test.fDuration); |
Leon Scroggins | bc098ef | 2020-10-27 15:24:18 -0400 | [diff] [blame] | 598 | REPORTER_ASSERT(r, player->dimensions() == test.fSize); |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 599 | |
| 600 | auto f0 = player->getFrame(); |
| 601 | REPORTER_ASSERT(r, f0); |
Leon Scroggins | bc098ef | 2020-10-27 15:24:18 -0400 | [diff] [blame] | 602 | REPORTER_ASSERT(r, f0->bounds().size() == test.fSize, |
| 603 | "Mismatched size for initial frame of %s", test.fFile); |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 604 | |
| 605 | player->seek(500); |
| 606 | auto f1 = player->getFrame(); |
| 607 | REPORTER_ASSERT(r, f1); |
Leon Scroggins | bc098ef | 2020-10-27 15:24:18 -0400 | [diff] [blame] | 608 | REPORTER_ASSERT(r, f1->bounds().size() == test.fSize, |
| 609 | "Mismatched size for frame at 500 ms of %s", test.fFile); |
Florin Malita | f8776c2 | 2018-11-06 19:16:28 -0500 | [diff] [blame] | 610 | } |
| 611 | } |