blob: b09c9251d15e18d2a21eff10cef6cd7ea724f104 [file] [log] [blame]
scroggo19b91532016-10-24 09:03:26 -07001/*
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
scroggo38a2cf52016-10-24 09:56:40 -07008#include "SkBitmap.h"
scroggo19b91532016-10-24 09:03:26 -07009#include "SkCodec.h"
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -050010#include "SkCommonFlags.h"
11#include "SkImageEncoder.h"
12#include "SkOSPath.h"
scroggo19b91532016-10-24 09:03:26 -070013#include "SkStream.h"
14
15#include "Resources.h"
16#include "Test.h"
Matt Sarett68b8e3d2017-04-28 11:15:22 -040017#include "sk_tool_utils.h"
scroggo19b91532016-10-24 09:03:26 -070018
19#include <initializer_list>
20#include <vector>
21
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -050022static void write_bm(const char* name, const SkBitmap& bm) {
23 if (FLAGS_writePath.isEmpty()) {
24 return;
25 }
26
27 SkString filename = SkOSPath::Join(FLAGS_writePath[0], name);
28 filename.appendf(".png");
29 SkFILEWStream file(filename.c_str());
30 if (!SkEncodeImage(&file, bm, SkEncodedImageFormat::kPNG, 100)) {
31 SkDebugf("failed to write '%s'\n", filename.c_str());
32 }
33}
34
Leon Scroggins III7d22a332017-04-12 17:01:26 -040035DEF_TEST(Codec_trunc, r) {
Hal Canaryc465d132017-12-08 10:21:31 -050036 sk_sp<SkData> data(GetResourceAsData("images/box.gif"));
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040037 if (!data) {
38 return;
39 }
Mike Reedede7bac2017-07-23 15:30:02 -040040 SkCodec::MakeFromData(SkData::MakeSubset(data.get(), 0, 23))->getFrameInfo();
Leon Scroggins III7d22a332017-04-12 17:01:26 -040041}
42
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040043// 565 does not support alpha, but there is no reason for it not to support an
44// animated image with a frame that has alpha but then blends onto an opaque
45// frame making the result opaque. Test that we can decode such a frame.
46DEF_TEST(Codec_565, r) {
Hal Canaryc465d132017-12-08 10:21:31 -050047 sk_sp<SkData> data(GetResourceAsData("images/blendBG.webp"));
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040048 if (!data) {
49 return;
50 }
Mike Reedede7bac2017-07-23 15:30:02 -040051 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(std::move(data)));
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040052 auto info = codec->getInfo().makeColorType(kRGB_565_SkColorType);
53 SkBitmap bm;
54 bm.allocPixels(info);
55
56 SkCodec::Options options;
57 options.fFrameIndex = 1;
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040058 options.fPriorFrame = SkCodec::kNone;
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040059
60 const auto result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(),
Leon Scroggins571b30f2017-07-11 17:35:31 +000061 &options);
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040062 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
63}
64
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040065static bool restore_previous(const SkCodec::FrameInfo& info) {
66 return info.fDisposalMethod == SkCodecAnimation::DisposalMethod::kRestorePrevious;
67}
Leon Scroggins III557fbbe2017-05-23 09:37:21 -040068
scroggo19b91532016-10-24 09:03:26 -070069DEF_TEST(Codec_frames, r) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050070 #define kOpaque kOpaque_SkAlphaType
71 #define kUnpremul kUnpremul_SkAlphaType
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040072 #define kKeep SkCodecAnimation::DisposalMethod::kKeep
73 #define kRestoreBG SkCodecAnimation::DisposalMethod::kRestoreBGColor
74 #define kRestorePrev SkCodecAnimation::DisposalMethod::kRestorePrevious
scroggo19b91532016-10-24 09:03:26 -070075 static const struct {
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040076 const char* fName;
77 int fFrameCount;
scroggo19b91532016-10-24 09:03:26 -070078 // One less than fFramecount, since the first frame is always
79 // independent.
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040080 std::vector<int> fRequiredFrames;
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050081 // Same, since the first frame should match getInfo
82 std::vector<SkAlphaType> fAlphas;
scroggo19b91532016-10-24 09:03:26 -070083 // The size of this one should match fFrameCount for animated, empty
84 // otherwise.
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040085 std::vector<int> fDurations;
86 int fRepetitionCount;
87 std::vector<SkCodecAnimation::DisposalMethod> fDisposalMethods;
scroggo19b91532016-10-24 09:03:26 -070088 } gRecs[] = {
Hal Canaryc465d132017-12-08 10:21:31 -050089 { "images/required.gif", 7,
Chris Blume0b5e7d12017-09-27 13:23:41 -070090 { 0, 1, 2, 3, 4, 5 },
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050091 { kOpaque, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040092 { 100, 100, 100, 100, 100, 100, 100 },
93 0,
94 { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep } },
Hal Canaryc465d132017-12-08 10:21:31 -050095 { "images/alphabetAnim.gif", 13,
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -040096 { SkCodec::kNone, 0, 0, 0, 0, 5, 6, SkCodec::kNone,
Chris Blume0b5e7d12017-09-27 13:23:41 -070097 SkCodec::kNone, 9, 10, 11 },
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050098 { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul,
99 kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul },
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400100 { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400101 0,
102 { kKeep, kRestorePrev, kRestorePrev, kRestorePrev, kRestorePrev,
103 kRestoreBG, kKeep, kRestoreBG, kRestoreBG, kKeep, kKeep,
104 kRestoreBG, kKeep } },
Hal Canaryc465d132017-12-08 10:21:31 -0500105 { "images/randPixelsAnim2.gif", 4,
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400106 // required frames
107 { 0, 0, 1 },
108 // alphas
109 { kOpaque, kOpaque, kOpaque },
110 // durations
111 { 0, 1000, 170, 40 },
112 // repetition count
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400113 0,
114 { kKeep, kKeep, kRestorePrev, kKeep } },
Hal Canaryc465d132017-12-08 10:21:31 -0500115 { "images/randPixelsAnim.gif", 13,
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -0500116 // required frames
Chris Blume0b5e7d12017-09-27 13:23:41 -0700117 { 0, 1, 2, 3, 4, 3, 6, 7, 7, 7, 9, 9 },
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500118 { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul,
119 kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul },
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -0500120 // durations
121 { 0, 1000, 170, 40, 220, 7770, 90, 90, 90, 90, 90, 90, 90 },
122 // repetition count
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400123 0,
124 { kKeep, kKeep, kKeep, kKeep, kRestoreBG, kRestoreBG, kRestoreBG,
125 kRestoreBG, kRestorePrev, kRestoreBG, kRestorePrev, kRestorePrev,
126 kRestorePrev, } },
Hal Canaryc465d132017-12-08 10:21:31 -0500127 { "images/box.gif", 1, {}, {}, {}, 0, { kKeep } },
128 { "images/color_wheel.gif", 1, {}, {}, {}, 0, { kKeep } },
129 { "images/test640x479.gif", 4, { 0, 1, 2 },
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400130 { kOpaque, kOpaque, kOpaque },
131 { 200, 200, 200, 200 },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400132 SkCodec::kRepetitionCountInfinite,
133 { kKeep, kKeep, kKeep, kKeep } },
Hal Canaryc465d132017-12-08 10:21:31 -0500134 { "images/colorTables.gif", 2, { 0 }, { kOpaque }, { 1000, 1000 }, 5,
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400135 { kKeep, kKeep } },
scroggo19b91532016-10-24 09:03:26 -0700136
Hal Canaryc465d132017-12-08 10:21:31 -0500137 { "images/arrow.png", 1, {}, {}, {}, 0, {} },
138 { "images/google_chrome.ico", 1, {}, {}, {}, 0, {} },
139 { "images/brickwork-texture.jpg", 1, {}, {}, {}, 0, {} },
scroggo19b91532016-10-24 09:03:26 -0700140#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
Hal Canaryc465d132017-12-08 10:21:31 -0500141 { "images/dng_with_preview.dng", 1, {}, {}, {}, 0, {} },
scroggo19b91532016-10-24 09:03:26 -0700142#endif
Hal Canaryc465d132017-12-08 10:21:31 -0500143 { "images/mandrill.wbmp", 1, {}, {}, {}, 0, {} },
144 { "images/randPixels.bmp", 1, {}, {}, {}, 0, {} },
145 { "images/yellow_rose.webp", 1, {}, {}, {}, 0, {} },
146 { "images/webp-animated.webp", 3, { 0, 1 }, { kOpaque, kOpaque },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400147 { 1000, 500, 1000 }, SkCodec::kRepetitionCountInfinite,
148 { kKeep, kKeep, kKeep } },
Hal Canaryc465d132017-12-08 10:21:31 -0500149 { "images/blendBG.webp", 7, { 0, SkCodec::kNone, SkCodec::kNone, SkCodec::kNone,
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400150 4, 4 },
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400151 { kOpaque, kOpaque, kUnpremul, kOpaque, kUnpremul, kUnpremul },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400152 { 525, 500, 525, 437, 609, 729, 444 }, 7,
153 { kKeep, kKeep, kKeep, kKeep, kKeep, kKeep, kKeep } },
Hal Canaryc465d132017-12-08 10:21:31 -0500154 { "images/required.webp", 7,
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400155 { 0, 1, 1, SkCodec::kNone, 4, 4 },
156 { kOpaque, kUnpremul, kUnpremul, kOpaque, kOpaque, kOpaque },
157 { 100, 100, 100, 100, 100, 100, 100 },
158 1,
159 { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep } },
scroggo19b91532016-10-24 09:03:26 -0700160 };
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400161 #undef kOpaque
162 #undef kUnpremul
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400163 #undef kKeep
164 #undef kRestorePrev
165 #undef kRestoreBG
scroggo19b91532016-10-24 09:03:26 -0700166
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400167 for (const auto& rec : gRecs) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400168 sk_sp<SkData> data(GetResourceAsData(rec.fName));
169 if (!data) {
scroggo19b91532016-10-24 09:03:26 -0700170 // Useful error statement, but sometimes people run tests without
171 // resources, and they do not want to see these messages.
172 //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName);
173 continue;
174 }
175
Mike Reedede7bac2017-07-23 15:30:02 -0400176 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
scroggo19b91532016-10-24 09:03:26 -0700177 if (!codec) {
178 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName);
179 continue;
180 }
181
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400182 {
183 SkCodec::FrameInfo frameInfo;
184 REPORTER_ASSERT(r, !codec->getFrameInfo(0, &frameInfo));
185 }
186
scroggoe71b1a12016-11-01 08:28:28 -0700187 const int repetitionCount = codec->getRepetitionCount();
188 if (repetitionCount != rec.fRepetitionCount) {
189 ERRORF(r, "%s repetition count does not match! expected: %i\tactual: %i",
190 rec.fName, rec.fRepetitionCount, repetitionCount);
191 }
192
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400193 const int expected = rec.fFrameCount;
194 if (rec.fRequiredFrames.size() + 1 != static_cast<size_t>(expected)) {
scroggo19b91532016-10-24 09:03:26 -0700195 ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expected: %i\tactual: %i",
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400196 rec.fName, expected - 1, rec.fRequiredFrames.size());
scroggo19b91532016-10-24 09:03:26 -0700197 continue;
198 }
199
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400200 if (expected > 1) {
201 if (rec.fDurations.size() != static_cast<size_t>(expected)) {
202 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i\tactual: %i",
203 rec.fName, expected, rec.fDurations.size());
204 continue;
205 }
206
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400207 if (rec.fAlphas.size() + 1 != static_cast<size_t>(expected)) {
208 ERRORF(r, "'%s' has wrong number entries in fAlphas; expected: %i\tactual: %i",
209 rec.fName, expected - 1, rec.fAlphas.size());
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400210 continue;
211 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400212
213 if (rec.fDisposalMethods.size() != static_cast<size_t>(expected)) {
214 ERRORF(r, "'%s' has wrong number entries in fDisposalMethods; "
215 "expected %i\tactual: %i",
216 rec.fName, expected, rec.fDisposalMethods.size());
217 continue;
218 }
scroggo19b91532016-10-24 09:03:26 -0700219 }
220
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400221 enum class TestMode {
222 kVector,
223 kIndividual,
224 };
225
226 for (auto mode : { TestMode::kVector, TestMode::kIndividual }) {
227 // Re-create the codec to reset state and test parsing.
Mike Reedede7bac2017-07-23 15:30:02 -0400228 codec = SkCodec::MakeFromData(data);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400229
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400230 int frameCount;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400231 std::vector<SkCodec::FrameInfo> frameInfos;
232 switch (mode) {
233 case TestMode::kVector:
234 frameInfos = codec->getFrameInfo();
235 // getFrameInfo returns empty set for non-animated.
236 frameCount = frameInfos.empty() ? 1 : frameInfos.size();
237 break;
238 case TestMode::kIndividual:
239 frameCount = codec->getFrameCount();
240 break;
241 }
242
243 if (frameCount != expected) {
244 ERRORF(r, "'%s' expected frame count: %i\tactual: %i",
245 rec.fName, expected, frameCount);
246 continue;
247 }
248
249 // From here on, we are only concerned with animated images.
250 if (1 == frameCount) {
251 continue;
252 }
253
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400254 for (int i = 0; i < frameCount; i++) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400255 SkCodec::FrameInfo frameInfo;
256 switch (mode) {
257 case TestMode::kVector:
258 frameInfo = frameInfos[i];
259 break;
260 case TestMode::kIndividual:
261 REPORTER_ASSERT(r, codec->getFrameInfo(i, nullptr));
262 REPORTER_ASSERT(r, codec->getFrameInfo(i, &frameInfo));
263 break;
264 }
265
266 if (rec.fDurations[i] != frameInfo.fDuration) {
267 ERRORF(r, "%s frame %i's durations do not match! expected: %i\tactual: %i",
268 rec.fName, i, rec.fDurations[i], frameInfo.fDuration);
269 }
270
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500271 auto to_string = [](SkAlphaType alpha) {
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400272 switch (alpha) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500273 case kUnpremul_SkAlphaType:
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400274 return "unpremul";
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500275 case kOpaque_SkAlphaType:
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400276 return "opaque";
277 default:
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400278 SkASSERT(false);
279 return "unknown";
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400280 }
281 };
282
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500283 auto expectedAlpha = 0 == i ? codec->getInfo().alphaType() : rec.fAlphas[i-1];
284 auto alpha = frameInfo.fAlphaType;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400285 if (expectedAlpha != alpha) {
286 ERRORF(r, "%s's frame %i has wrong alpha type! expected: %s\tactual: %s",
287 rec.fName, i, to_string(expectedAlpha), to_string(alpha));
288 }
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400289
290 if (0 == i) {
291 REPORTER_ASSERT(r, frameInfo.fRequiredFrame == SkCodec::kNone);
292 } else if (rec.fRequiredFrames[i-1] != frameInfo.fRequiredFrame) {
293 ERRORF(r, "%s's frame %i has wrong dependency! expected: %i\tactual: %i",
294 rec.fName, i, rec.fRequiredFrames[i-1], frameInfo.fRequiredFrame);
295 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400296
297 REPORTER_ASSERT(r, frameInfo.fDisposalMethod == rec.fDisposalMethods[i]);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400298 }
299
300 if (TestMode::kIndividual == mode) {
301 // No need to test decoding twice.
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400302 continue;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400303 }
304
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400305 // Compare decoding in multiple ways:
306 // - Start from scratch for each frame. |codec| will have to decode the required frame
307 // (and any it depends on) to decode. This is stored in |cachedFrames|.
308 // - Provide the frame that a frame depends on, so |codec| just has to blend.
309 // - Provide a frame after the required frame, which will be covered up by the newest
310 // frame.
311 // All should look the same.
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400312 std::vector<SkBitmap> cachedFrames(frameCount);
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400313 const auto info = codec->getInfo().makeColorType(kN32_SkColorType);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400314
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400315 auto decode = [&](SkBitmap* bm, int index, int cachedIndex) {
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400316 auto decodeInfo = info;
317 if (index > 0) {
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -0500318 decodeInfo = info.makeAlphaType(frameInfos[index].fAlphaType);
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400319 }
320 bm->allocPixels(decodeInfo);
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400321 if (cachedIndex != SkCodec::kNone) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400322 // First copy the pixels from the cached frame
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400323 const bool success = sk_tool_utils::copy_to(bm, kN32_SkColorType,
324 cachedFrames[cachedIndex]);
325 REPORTER_ASSERT(r, success);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400326 }
327 SkCodec::Options opts;
328 opts.fFrameIndex = index;
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400329 opts.fPriorFrame = cachedIndex;
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400330 const auto result = codec->getPixels(decodeInfo, bm->getPixels(), bm->rowBytes(),
Leon Scroggins571b30f2017-07-11 17:35:31 +0000331 &opts);
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400332 if (cachedIndex != SkCodec::kNone && restore_previous(frameInfos[cachedIndex])) {
333 if (result == SkCodec::kInvalidParameters) {
334 return true;
335 }
336 ERRORF(r, "Using a kRestorePrevious frame as fPriorFrame should fail");
337 return false;
338 }
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400339 if (result != SkCodec::kSuccess) {
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400340 ERRORF(r, "Failed to decode frame %i from %s when providing prior frame %i, "
341 "error %i", index, rec.fName, cachedIndex, result);
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400342 }
343 return result == SkCodec::kSuccess;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400344 };
345
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400346 for (int i = 0; i < frameCount; i++) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400347 SkBitmap& cachedFrame = cachedFrames[i];
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400348 if (!decode(&cachedFrame, i, SkCodec::kNone)) {
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400349 continue;
350 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400351 const auto reqFrame = frameInfos[i].fRequiredFrame;
352 if (reqFrame == SkCodec::kNone) {
353 // Nothing to compare against.
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400354 continue;
355 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400356 for (int j = reqFrame; j < i; j++) {
357 SkBitmap frame;
358 if (restore_previous(frameInfos[j])) {
359 (void) decode(&frame, i, j);
360 continue;
361 }
362 if (!decode(&frame, i, j)) {
363 continue;
364 }
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400365
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400366 // Now verify they're equal.
367 const size_t rowLen = info.bytesPerPixel() * info.width();
368 for (int y = 0; y < info.height(); y++) {
369 const void* cachedAddr = cachedFrame.getAddr(0, y);
370 SkASSERT(cachedAddr != nullptr);
371 const void* addr = frame.getAddr(0, y);
372 SkASSERT(addr != nullptr);
373 const bool lineMatches = memcmp(cachedAddr, addr, rowLen) == 0;
374 if (!lineMatches) {
375 SkString name = SkStringPrintf("cached_%i", i);
376 write_bm(name.c_str(), cachedFrame);
377 name = SkStringPrintf("frame_%i", i);
378 write_bm(name.c_str(), frame);
379 ERRORF(r, "%s's frame %i is different (starting from line %i) when "
380 "providing prior frame %i!", rec.fName, i, y, j);
381 break;
382 }
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400383 }
384 }
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -0500385 }
scroggo19b91532016-10-24 09:03:26 -0700386 }
387 }
388}