blob: e354ea6cbf50f28a26218f61e430c3dcf95b3c56 [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) {
36 sk_sp<SkData> data(GetResourceAsData("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) {
47 sk_sp<SkData> data(GetResourceAsData("blendBG.webp"));
48 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 IIIae79f322017-08-18 10:53:24 -040070 #define kOpaque SkEncodedInfo::kOpaque_Alpha
71 #define kUnpremul SkEncodedInfo::kUnpremul_Alpha
72 #define kBinary SkEncodedInfo::kBinary_Alpha
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040073 #define kKeep SkCodecAnimation::DisposalMethod::kKeep
74 #define kRestoreBG SkCodecAnimation::DisposalMethod::kRestoreBGColor
75 #define kRestorePrev SkCodecAnimation::DisposalMethod::kRestorePrevious
scroggo19b91532016-10-24 09:03:26 -070076 static const struct {
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040077 const char* fName;
78 int fFrameCount;
scroggo19b91532016-10-24 09:03:26 -070079 // One less than fFramecount, since the first frame is always
80 // independent.
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040081 std::vector<int> fRequiredFrames;
Leon Scroggins IIIae79f322017-08-18 10:53:24 -040082 // Same, since the first frame should match getEncodedInfo
83 std::vector<SkEncodedInfo::Alpha> fAlphas;
scroggo19b91532016-10-24 09:03:26 -070084 // The size of this one should match fFrameCount for animated, empty
85 // otherwise.
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040086 std::vector<int> fDurations;
87 int fRepetitionCount;
88 std::vector<SkCodecAnimation::DisposalMethod> fDisposalMethods;
scroggo19b91532016-10-24 09:03:26 -070089 } gRecs[] = {
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040090 { "required.gif", 7,
Chris Blume0b5e7d12017-09-27 13:23:41 -070091 { 0, 1, 2, 3, 4, 5 },
92 { kOpaque, kBinary, kBinary, kBinary, kBinary, kBinary },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -040093 { 100, 100, 100, 100, 100, 100, 100 },
94 0,
95 { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep } },
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -040096 { "alphabetAnim.gif", 13,
97 { SkCodec::kNone, 0, 0, 0, 0, 5, 6, SkCodec::kNone,
Chris Blume0b5e7d12017-09-27 13:23:41 -070098 SkCodec::kNone, 9, 10, 11 },
Leon Scroggins IIIae79f322017-08-18 10:53:24 -040099 { kBinary, kBinary, kBinary, kBinary, kBinary, kBinary,
Chris Blume0b5e7d12017-09-27 13:23:41 -0700100 kBinary, kBinary, kBinary, kBinary, kBinary, kBinary },
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400101 { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400102 0,
103 { kKeep, kRestorePrev, kRestorePrev, kRestorePrev, kRestorePrev,
104 kRestoreBG, kKeep, kRestoreBG, kRestoreBG, kKeep, kKeep,
105 kRestoreBG, kKeep } },
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400106 { "randPixelsAnim2.gif", 4,
107 // required frames
108 { 0, 0, 1 },
109 // alphas
110 { kOpaque, kOpaque, kOpaque },
111 // durations
112 { 0, 1000, 170, 40 },
113 // repetition count
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400114 0,
115 { kKeep, kKeep, kRestorePrev, kKeep } },
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -0500116 { "randPixelsAnim.gif", 13,
117 // required frames
Chris Blume0b5e7d12017-09-27 13:23:41 -0700118 { 0, 1, 2, 3, 4, 3, 6, 7, 7, 7, 9, 9 },
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400119 { kBinary, kBinary, kBinary, kBinary, kBinary, kBinary,
120 kBinary, kBinary, kBinary, kBinary, kBinary, kBinary },
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -0500121 // durations
122 { 0, 1000, 170, 40, 220, 7770, 90, 90, 90, 90, 90, 90, 90 },
123 // repetition count
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400124 0,
125 { kKeep, kKeep, kKeep, kKeep, kRestoreBG, kRestoreBG, kRestoreBG,
126 kRestoreBG, kRestorePrev, kRestoreBG, kRestorePrev, kRestorePrev,
127 kRestorePrev, } },
128 { "box.gif", 1, {}, {}, {}, 0, { kKeep } },
129 { "color_wheel.gif", 1, {}, {}, {}, 0, { kKeep } },
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400130 { "test640x479.gif", 4, { 0, 1, 2 },
131 { kOpaque, kOpaque, kOpaque },
132 { 200, 200, 200, 200 },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400133 SkCodec::kRepetitionCountInfinite,
134 { kKeep, kKeep, kKeep, kKeep } },
135 { "colorTables.gif", 2, { 0 }, { kOpaque }, { 1000, 1000 }, 5,
136 { kKeep, kKeep } },
scroggo19b91532016-10-24 09:03:26 -0700137
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400138 { "arrow.png", 1, {}, {}, {}, 0, {} },
139 { "google_chrome.ico", 1, {}, {}, {}, 0, {} },
140 { "brickwork-texture.jpg", 1, {}, {}, {}, 0, {} },
scroggo19b91532016-10-24 09:03:26 -0700141#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400142 { "dng_with_preview.dng", 1, {}, {}, {}, 0, {} },
scroggo19b91532016-10-24 09:03:26 -0700143#endif
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400144 { "mandrill.wbmp", 1, {}, {}, {}, 0, {} },
145 { "randPixels.bmp", 1, {}, {}, {}, 0, {} },
146 { "yellow_rose.webp", 1, {}, {}, {}, 0, {} },
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400147 { "webp-animated.webp", 3, { 0, 1 }, { kOpaque, kOpaque },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400148 { 1000, 500, 1000 }, SkCodec::kRepetitionCountInfinite,
149 { kKeep, kKeep, kKeep } },
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400150 { "blendBG.webp", 7, { 0, SkCodec::kNone, SkCodec::kNone, SkCodec::kNone,
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400151 4, 4 },
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400152 { kOpaque, kOpaque, kUnpremul, kOpaque, kUnpremul, kUnpremul },
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400153 { 525, 500, 525, 437, 609, 729, 444 }, 7,
154 { kKeep, kKeep, kKeep, kKeep, kKeep, kKeep, kKeep } },
155 { "required.webp", 7,
156 { 0, 1, 1, SkCodec::kNone, 4, 4 },
157 { kOpaque, kUnpremul, kUnpremul, kOpaque, kOpaque, kOpaque },
158 { 100, 100, 100, 100, 100, 100, 100 },
159 1,
160 { kKeep, kRestoreBG, kKeep, kKeep, kKeep, kRestoreBG, kKeep } },
scroggo19b91532016-10-24 09:03:26 -0700161 };
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400162 #undef kOpaque
163 #undef kUnpremul
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400164 #undef kBinary
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400165 #undef kKeep
166 #undef kRestorePrev
167 #undef kRestoreBG
scroggo19b91532016-10-24 09:03:26 -0700168
Leon Scroggins IIIa4db9be2017-04-11 10:32:02 -0400169 for (const auto& rec : gRecs) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400170 sk_sp<SkData> data(GetResourceAsData(rec.fName));
171 if (!data) {
scroggo19b91532016-10-24 09:03:26 -0700172 // Useful error statement, but sometimes people run tests without
173 // resources, and they do not want to see these messages.
174 //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName);
175 continue;
176 }
177
Mike Reedede7bac2017-07-23 15:30:02 -0400178 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
scroggo19b91532016-10-24 09:03:26 -0700179 if (!codec) {
180 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName);
181 continue;
182 }
183
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400184 {
185 SkCodec::FrameInfo frameInfo;
186 REPORTER_ASSERT(r, !codec->getFrameInfo(0, &frameInfo));
187 }
188
scroggoe71b1a12016-11-01 08:28:28 -0700189 const int repetitionCount = codec->getRepetitionCount();
190 if (repetitionCount != rec.fRepetitionCount) {
191 ERRORF(r, "%s repetition count does not match! expected: %i\tactual: %i",
192 rec.fName, rec.fRepetitionCount, repetitionCount);
193 }
194
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400195 const int expected = rec.fFrameCount;
196 if (rec.fRequiredFrames.size() + 1 != static_cast<size_t>(expected)) {
scroggo19b91532016-10-24 09:03:26 -0700197 ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expected: %i\tactual: %i",
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400198 rec.fName, expected - 1, rec.fRequiredFrames.size());
scroggo19b91532016-10-24 09:03:26 -0700199 continue;
200 }
201
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400202 if (expected > 1) {
203 if (rec.fDurations.size() != static_cast<size_t>(expected)) {
204 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i\tactual: %i",
205 rec.fName, expected, rec.fDurations.size());
206 continue;
207 }
208
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400209 if (rec.fAlphas.size() + 1 != static_cast<size_t>(expected)) {
210 ERRORF(r, "'%s' has wrong number entries in fAlphas; expected: %i\tactual: %i",
211 rec.fName, expected - 1, rec.fAlphas.size());
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400212 continue;
213 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400214
215 if (rec.fDisposalMethods.size() != static_cast<size_t>(expected)) {
216 ERRORF(r, "'%s' has wrong number entries in fDisposalMethods; "
217 "expected %i\tactual: %i",
218 rec.fName, expected, rec.fDisposalMethods.size());
219 continue;
220 }
scroggo19b91532016-10-24 09:03:26 -0700221 }
222
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400223 enum class TestMode {
224 kVector,
225 kIndividual,
226 };
227
228 for (auto mode : { TestMode::kVector, TestMode::kIndividual }) {
229 // Re-create the codec to reset state and test parsing.
Mike Reedede7bac2017-07-23 15:30:02 -0400230 codec = SkCodec::MakeFromData(data);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400231
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400232 int frameCount;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400233 std::vector<SkCodec::FrameInfo> frameInfos;
234 switch (mode) {
235 case TestMode::kVector:
236 frameInfos = codec->getFrameInfo();
237 // getFrameInfo returns empty set for non-animated.
238 frameCount = frameInfos.empty() ? 1 : frameInfos.size();
239 break;
240 case TestMode::kIndividual:
241 frameCount = codec->getFrameCount();
242 break;
243 }
244
245 if (frameCount != expected) {
246 ERRORF(r, "'%s' expected frame count: %i\tactual: %i",
247 rec.fName, expected, frameCount);
248 continue;
249 }
250
251 // From here on, we are only concerned with animated images.
252 if (1 == frameCount) {
253 continue;
254 }
255
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400256 for (int i = 0; i < frameCount; i++) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400257 SkCodec::FrameInfo frameInfo;
258 switch (mode) {
259 case TestMode::kVector:
260 frameInfo = frameInfos[i];
261 break;
262 case TestMode::kIndividual:
263 REPORTER_ASSERT(r, codec->getFrameInfo(i, nullptr));
264 REPORTER_ASSERT(r, codec->getFrameInfo(i, &frameInfo));
265 break;
266 }
267
268 if (rec.fDurations[i] != frameInfo.fDuration) {
269 ERRORF(r, "%s frame %i's durations do not match! expected: %i\tactual: %i",
270 rec.fName, i, rec.fDurations[i], frameInfo.fDuration);
271 }
272
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400273 auto to_string = [](SkEncodedInfo::Alpha alpha) {
274 switch (alpha) {
275 case SkEncodedInfo::kUnpremul_Alpha:
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400276 return "unpremul";
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400277 case SkEncodedInfo::kOpaque_Alpha:
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400278 return "opaque";
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400279 case SkEncodedInfo::kBinary_Alpha:
280 return "binary";
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400281 default:
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400282 SkASSERT(false);
283 return "unknown";
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400284 }
285 };
286
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400287 auto expectedAlpha = 0 == i ? codec->getEncodedInfo().alpha() : rec.fAlphas[i-1];
288 auto alpha = frameInfo.fAlpha;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400289 if (expectedAlpha != alpha) {
290 ERRORF(r, "%s's frame %i has wrong alpha type! expected: %s\tactual: %s",
291 rec.fName, i, to_string(expectedAlpha), to_string(alpha));
292 }
Leon Scroggins III557fbbe2017-05-23 09:37:21 -0400293
294 if (0 == i) {
295 REPORTER_ASSERT(r, frameInfo.fRequiredFrame == SkCodec::kNone);
296 } else if (rec.fRequiredFrames[i-1] != frameInfo.fRequiredFrame) {
297 ERRORF(r, "%s's frame %i has wrong dependency! expected: %i\tactual: %i",
298 rec.fName, i, rec.fRequiredFrames[i-1], frameInfo.fRequiredFrame);
299 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400300
301 REPORTER_ASSERT(r, frameInfo.fDisposalMethod == rec.fDisposalMethods[i]);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400302 }
303
304 if (TestMode::kIndividual == mode) {
305 // No need to test decoding twice.
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400306 continue;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400307 }
308
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400309 // Compare decoding in multiple ways:
310 // - Start from scratch for each frame. |codec| will have to decode the required frame
311 // (and any it depends on) to decode. This is stored in |cachedFrames|.
312 // - Provide the frame that a frame depends on, so |codec| just has to blend.
313 // - Provide a frame after the required frame, which will be covered up by the newest
314 // frame.
315 // All should look the same.
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400316 std::vector<SkBitmap> cachedFrames(frameCount);
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400317 const auto info = codec->getInfo().makeColorType(kN32_SkColorType);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400318
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400319 auto decode = [&](SkBitmap* bm, int index, int cachedIndex) {
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400320 auto decodeInfo = info;
321 if (index > 0) {
Leon Scroggins IIIae79f322017-08-18 10:53:24 -0400322 auto alphaType = frameInfos[index].fAlpha == SkEncodedInfo::kOpaque_Alpha
323 ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
324 decodeInfo = info.makeAlphaType(alphaType);
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400325 }
326 bm->allocPixels(decodeInfo);
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400327 if (cachedIndex != SkCodec::kNone) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400328 // First copy the pixels from the cached frame
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400329 const bool success = sk_tool_utils::copy_to(bm, kN32_SkColorType,
330 cachedFrames[cachedIndex]);
331 REPORTER_ASSERT(r, success);
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400332 }
333 SkCodec::Options opts;
334 opts.fFrameIndex = index;
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400335 opts.fPriorFrame = cachedIndex;
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400336 const auto result = codec->getPixels(decodeInfo, bm->getPixels(), bm->rowBytes(),
Leon Scroggins571b30f2017-07-11 17:35:31 +0000337 &opts);
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400338 if (cachedIndex != SkCodec::kNone && restore_previous(frameInfos[cachedIndex])) {
339 if (result == SkCodec::kInvalidParameters) {
340 return true;
341 }
342 ERRORF(r, "Using a kRestorePrevious frame as fPriorFrame should fail");
343 return false;
344 }
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400345 if (result != SkCodec::kSuccess) {
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400346 ERRORF(r, "Failed to decode frame %i from %s when providing prior frame %i, "
347 "error %i", index, rec.fName, cachedIndex, result);
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400348 }
349 return result == SkCodec::kSuccess;
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400350 };
351
Leon Scroggins III249b8e32017-04-17 12:46:33 -0400352 for (int i = 0; i < frameCount; i++) {
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400353 SkBitmap& cachedFrame = cachedFrames[i];
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400354 if (!decode(&cachedFrame, i, SkCodec::kNone)) {
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400355 continue;
356 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400357 const auto reqFrame = frameInfos[i].fRequiredFrame;
358 if (reqFrame == SkCodec::kNone) {
359 // Nothing to compare against.
Leon Scroggins III91f0f732017-06-07 09:31:23 -0400360 continue;
361 }
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400362 for (int j = reqFrame; j < i; j++) {
363 SkBitmap frame;
364 if (restore_previous(frameInfos[j])) {
365 (void) decode(&frame, i, j);
366 continue;
367 }
368 if (!decode(&frame, i, j)) {
369 continue;
370 }
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400371
Leon Scroggins III33deb7e2017-06-07 12:31:51 -0400372 // Now verify they're equal.
373 const size_t rowLen = info.bytesPerPixel() * info.width();
374 for (int y = 0; y < info.height(); y++) {
375 const void* cachedAddr = cachedFrame.getAddr(0, y);
376 SkASSERT(cachedAddr != nullptr);
377 const void* addr = frame.getAddr(0, y);
378 SkASSERT(addr != nullptr);
379 const bool lineMatches = memcmp(cachedAddr, addr, rowLen) == 0;
380 if (!lineMatches) {
381 SkString name = SkStringPrintf("cached_%i", i);
382 write_bm(name.c_str(), cachedFrame);
383 name = SkStringPrintf("frame_%i", i);
384 write_bm(name.c_str(), frame);
385 ERRORF(r, "%s's frame %i is different (starting from line %i) when "
386 "providing prior frame %i!", rec.fName, i, y, j);
387 break;
388 }
Leon Scroggins IIIe132e7b2017-04-12 10:49:52 -0400389 }
390 }
Leon Scroggins IIIb0b625b2016-12-22 16:40:24 -0500391 }
scroggo19b91532016-10-24 09:03:26 -0700392 }
393 }
394}