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 | |
scroggo | 38a2cf5 | 2016-10-24 09:56:40 -0700 | [diff] [blame] | 8 | #include "SkBitmap.h" |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 9 | #include "SkCodec.h" |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 10 | #include "SkCommonFlags.h" |
| 11 | #include "SkImageEncoder.h" |
| 12 | #include "SkOSPath.h" |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 13 | #include "SkStream.h" |
| 14 | |
| 15 | #include "Resources.h" |
| 16 | #include "Test.h" |
Matt Sarett | 68b8e3d | 2017-04-28 11:15:22 -0400 | [diff] [blame] | 17 | #include "sk_tool_utils.h" |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 18 | |
| 19 | #include <initializer_list> |
| 20 | #include <vector> |
| 21 | |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 22 | static 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 III | 7d22a33 | 2017-04-12 17:01:26 -0400 | [diff] [blame] | 35 | DEF_TEST(Codec_trunc, r) { |
| 36 | sk_sp<SkData> data(GetResourceAsData("box.gif")); |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 37 | if (!data) { |
| 38 | return; |
| 39 | } |
Leon Scroggins III | 7d22a33 | 2017-04-12 17:01:26 -0400 | [diff] [blame] | 40 | data = SkData::MakeSubset(data.get(), 0, 23); |
| 41 | std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data)); |
| 42 | codec->getFrameInfo(); |
| 43 | } |
| 44 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 45 | // 565 does not support alpha, but there is no reason for it not to support an |
| 46 | // animated image with a frame that has alpha but then blends onto an opaque |
| 47 | // frame making the result opaque. Test that we can decode such a frame. |
| 48 | DEF_TEST(Codec_565, r) { |
| 49 | sk_sp<SkData> data(GetResourceAsData("blendBG.webp")); |
| 50 | if (!data) { |
| 51 | return; |
| 52 | } |
| 53 | std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(std::move(data))); |
| 54 | auto info = codec->getInfo().makeColorType(kRGB_565_SkColorType); |
| 55 | SkBitmap bm; |
| 56 | bm.allocPixels(info); |
| 57 | |
| 58 | SkCodec::Options options; |
| 59 | options.fFrameIndex = 1; |
| 60 | options.fHasPriorFrame = false; |
| 61 | |
| 62 | const auto result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), |
| 63 | &options, nullptr, nullptr); |
| 64 | REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 65 | } |
| 66 | |
| 67 | |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 68 | DEF_TEST(Codec_frames, r) { |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 69 | #define kOpaque kOpaque_SkAlphaType |
| 70 | #define kUnpremul kUnpremul_SkAlphaType |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 71 | static const struct { |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 72 | const char* fName; |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 73 | int fFrameCount; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 74 | // One less than fFramecount, since the first frame is always |
| 75 | // independent. |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 76 | std::vector<int> fRequiredFrames; |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 77 | // Same, since the first frame should match getInfo. |
| 78 | std::vector<SkAlphaType> fAlphaTypes; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 79 | // The size of this one should match fFrameCount for animated, empty |
| 80 | // otherwise. |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 81 | std::vector<int> fDurations; |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 82 | int fRepetitionCount; |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 83 | } gRecs[] = { |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 84 | { "alphabetAnim.gif", 13, |
| 85 | { SkCodec::kNone, 0, 0, 0, 0, 5, 6, SkCodec::kNone, |
| 86 | SkCodec::kNone, SkCodec::kNone, 10, 11 }, |
| 87 | { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, |
| 88 | kUnpremul, kUnpremul, kUnpremul, kOpaque, kOpaque, kUnpremul }, |
| 89 | { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }, |
| 90 | 0 }, |
| 91 | { "randPixelsAnim2.gif", 4, |
| 92 | // required frames |
| 93 | { 0, 0, 1 }, |
| 94 | // alphas |
| 95 | { kOpaque, kOpaque, kOpaque }, |
| 96 | // durations |
| 97 | { 0, 1000, 170, 40 }, |
| 98 | // repetition count |
| 99 | 0 }, |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 100 | { "randPixelsAnim.gif", 13, |
| 101 | // required frames |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 102 | { SkCodec::kNone, 1, 2, 3, 4, 3, 6, 7, 7, 7, 9, 9 }, |
| 103 | { kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, |
| 104 | kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul, kUnpremul }, |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 105 | // durations |
| 106 | { 0, 1000, 170, 40, 220, 7770, 90, 90, 90, 90, 90, 90, 90 }, |
| 107 | // repetition count |
| 108 | 0 }, |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 109 | { "box.gif", 1, {}, {}, {}, 0 }, |
| 110 | { "color_wheel.gif", 1, {}, {}, {}, 0 }, |
| 111 | { "test640x479.gif", 4, { 0, 1, 2 }, |
| 112 | { kOpaque, kOpaque, kOpaque }, |
| 113 | { 200, 200, 200, 200 }, |
scroggo | e71b1a1 | 2016-11-01 08:28:28 -0700 | [diff] [blame] | 114 | SkCodec::kRepetitionCountInfinite }, |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 115 | { "colorTables.gif", 2, { 0 }, { kOpaque }, { 1000, 1000 }, 5 }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 116 | |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 117 | { "arrow.png", 1, {}, {}, {}, 0 }, |
| 118 | { "google_chrome.ico", 1, {}, {}, {}, 0 }, |
| 119 | { "brickwork-texture.jpg", 1, {}, {}, {}, 0 }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 120 | #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 121 | { "dng_with_preview.dng", 1, {}, {}, {}, 0 }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 122 | #endif |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 123 | { "mandrill.wbmp", 1, {}, {}, {}, 0 }, |
| 124 | { "randPixels.bmp", 1, {}, {}, {}, 0 }, |
| 125 | { "yellow_rose.webp", 1, {}, {}, {}, 0 }, |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 126 | { "webp-animated.webp", 3, { 0, 1 }, { kOpaque, kOpaque }, |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 127 | { 1000, 500, 1000 }, SkCodec::kRepetitionCountInfinite }, |
| 128 | { "blendBG.webp", 7, { 0, SkCodec::kNone, SkCodec::kNone, SkCodec::kNone, |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 129 | 4, 4 }, |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 130 | { kOpaque, kOpaque, kUnpremul, kOpaque, kUnpremul, kUnpremul }, |
| 131 | { 525, 500, 525, 437, 609, 729, 444 }, 7 }, |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 132 | }; |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 133 | #undef kOpaque |
| 134 | #undef kUnpremul |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 135 | |
Leon Scroggins III | a4db9be | 2017-04-11 10:32:02 -0400 | [diff] [blame] | 136 | for (const auto& rec : gRecs) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 137 | sk_sp<SkData> data(GetResourceAsData(rec.fName)); |
| 138 | if (!data) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 139 | // Useful error statement, but sometimes people run tests without |
| 140 | // resources, and they do not want to see these messages. |
| 141 | //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName); |
| 142 | continue; |
| 143 | } |
| 144 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 145 | std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data)); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 146 | if (!codec) { |
| 147 | ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); |
| 148 | continue; |
| 149 | } |
| 150 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 151 | { |
| 152 | SkCodec::FrameInfo frameInfo; |
| 153 | REPORTER_ASSERT(r, !codec->getFrameInfo(0, &frameInfo)); |
| 154 | } |
| 155 | |
scroggo | e71b1a1 | 2016-11-01 08:28:28 -0700 | [diff] [blame] | 156 | const int repetitionCount = codec->getRepetitionCount(); |
| 157 | if (repetitionCount != rec.fRepetitionCount) { |
| 158 | ERRORF(r, "%s repetition count does not match! expected: %i\tactual: %i", |
| 159 | rec.fName, rec.fRepetitionCount, repetitionCount); |
| 160 | } |
| 161 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 162 | const int expected = rec.fFrameCount; |
| 163 | if (rec.fRequiredFrames.size() + 1 != static_cast<size_t>(expected)) { |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 164 | ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expected: %i\tactual: %i", |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 165 | rec.fName, expected - 1, rec.fRequiredFrames.size()); |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 166 | continue; |
| 167 | } |
| 168 | |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 169 | if (expected > 1) { |
| 170 | if (rec.fDurations.size() != static_cast<size_t>(expected)) { |
| 171 | ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i\tactual: %i", |
| 172 | rec.fName, expected, rec.fDurations.size()); |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | if (rec.fAlphaTypes.size() + 1 != static_cast<size_t>(expected)) { |
| 177 | ERRORF(r, "'%s' has wrong number entries in fAlphaTypes; expected: %i\tactual: %i", |
| 178 | rec.fName, expected - 1, rec.fAlphaTypes.size()); |
| 179 | continue; |
| 180 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 183 | enum class TestMode { |
| 184 | kVector, |
| 185 | kIndividual, |
| 186 | }; |
| 187 | |
| 188 | for (auto mode : { TestMode::kVector, TestMode::kIndividual }) { |
| 189 | // Re-create the codec to reset state and test parsing. |
| 190 | codec.reset(SkCodec::NewFromData(data)); |
| 191 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 192 | int frameCount; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 193 | std::vector<SkCodec::FrameInfo> frameInfos; |
| 194 | switch (mode) { |
| 195 | case TestMode::kVector: |
| 196 | frameInfos = codec->getFrameInfo(); |
| 197 | // getFrameInfo returns empty set for non-animated. |
| 198 | frameCount = frameInfos.empty() ? 1 : frameInfos.size(); |
| 199 | break; |
| 200 | case TestMode::kIndividual: |
| 201 | frameCount = codec->getFrameCount(); |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | if (frameCount != expected) { |
| 206 | ERRORF(r, "'%s' expected frame count: %i\tactual: %i", |
| 207 | rec.fName, expected, frameCount); |
| 208 | continue; |
| 209 | } |
| 210 | |
| 211 | // From here on, we are only concerned with animated images. |
| 212 | if (1 == frameCount) { |
| 213 | continue; |
| 214 | } |
| 215 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 216 | for (int i = 0; i < frameCount; i++) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 217 | SkCodec::FrameInfo frameInfo; |
| 218 | switch (mode) { |
| 219 | case TestMode::kVector: |
| 220 | frameInfo = frameInfos[i]; |
| 221 | break; |
| 222 | case TestMode::kIndividual: |
| 223 | REPORTER_ASSERT(r, codec->getFrameInfo(i, nullptr)); |
| 224 | REPORTER_ASSERT(r, codec->getFrameInfo(i, &frameInfo)); |
| 225 | break; |
| 226 | } |
| 227 | |
| 228 | if (rec.fDurations[i] != frameInfo.fDuration) { |
| 229 | ERRORF(r, "%s frame %i's durations do not match! expected: %i\tactual: %i", |
| 230 | rec.fName, i, rec.fDurations[i], frameInfo.fDuration); |
| 231 | } |
| 232 | |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 233 | auto to_string = [](SkAlphaType type) { |
| 234 | switch (type) { |
| 235 | case kUnpremul_SkAlphaType: |
| 236 | return "unpremul"; |
| 237 | case kOpaque_SkAlphaType: |
| 238 | return "opaque"; |
| 239 | default: |
| 240 | return "other"; |
| 241 | } |
| 242 | }; |
| 243 | |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 244 | auto expectedAlpha = 0 == i ? codec->getInfo().alphaType() : rec.fAlphaTypes[i-1]; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 245 | auto alpha = frameInfo.fAlphaType; |
| 246 | if (expectedAlpha != alpha) { |
| 247 | ERRORF(r, "%s's frame %i has wrong alpha type! expected: %s\tactual: %s", |
| 248 | rec.fName, i, to_string(expectedAlpha), to_string(alpha)); |
| 249 | } |
Leon Scroggins III | 557fbbe | 2017-05-23 09:37:21 -0400 | [diff] [blame] | 250 | |
| 251 | if (0 == i) { |
| 252 | REPORTER_ASSERT(r, frameInfo.fRequiredFrame == SkCodec::kNone); |
| 253 | } else if (rec.fRequiredFrames[i-1] != frameInfo.fRequiredFrame) { |
| 254 | ERRORF(r, "%s's frame %i has wrong dependency! expected: %i\tactual: %i", |
| 255 | rec.fName, i, rec.fRequiredFrames[i-1], frameInfo.fRequiredFrame); |
| 256 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | if (TestMode::kIndividual == mode) { |
| 260 | // No need to test decoding twice. |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 261 | continue; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | // Compare decoding in two ways: |
| 265 | // 1. Provide the frame that a frame depends on, so the codec just has to blend. |
| 266 | // (in the array cachedFrames) |
| 267 | // 2. Do not provide the frame that a frame depends on, so the codec has to decode |
| 268 | // all the way back to a key-frame. (in a local variable uncachedFrame) |
| 269 | // The two should look the same. |
| 270 | std::vector<SkBitmap> cachedFrames(frameCount); |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 271 | const auto info = codec->getInfo().makeColorType(kN32_SkColorType); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 272 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 273 | auto decode = [&](SkBitmap* bm, bool cached, int index) { |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 274 | auto decodeInfo = info; |
| 275 | if (index > 0) { |
| 276 | decodeInfo = info.makeAlphaType(frameInfos[index].fAlphaType); |
| 277 | } |
| 278 | bm->allocPixels(decodeInfo); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 279 | if (cached) { |
| 280 | // First copy the pixels from the cached frame |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 281 | const int requiredFrame = frameInfos[index].fRequiredFrame; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 282 | if (requiredFrame != SkCodec::kNone) { |
Matt Sarett | 68b8e3d | 2017-04-28 11:15:22 -0400 | [diff] [blame] | 283 | const bool success = sk_tool_utils::copy_to(bm, kN32_SkColorType, |
| 284 | cachedFrames[requiredFrame]); |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 285 | REPORTER_ASSERT(r, success); |
| 286 | } |
| 287 | } |
| 288 | SkCodec::Options opts; |
| 289 | opts.fFrameIndex = index; |
| 290 | opts.fHasPriorFrame = cached; |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 291 | const auto result = codec->getPixels(decodeInfo, bm->getPixels(), bm->rowBytes(), |
| 292 | &opts, nullptr, nullptr); |
| 293 | if (result != SkCodec::kSuccess) { |
| 294 | ERRORF(r, "Failed to decode frame %i from %s when %scached, error %i", |
| 295 | index, rec.fName, (cached ? "" : "not "), result); |
| 296 | } |
| 297 | return result == SkCodec::kSuccess; |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 298 | }; |
| 299 | |
Leon Scroggins III | 249b8e3 | 2017-04-17 12:46:33 -0400 | [diff] [blame] | 300 | for (int i = 0; i < frameCount; i++) { |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 301 | SkBitmap& cachedFrame = cachedFrames[i]; |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 302 | if (!decode(&cachedFrame, true, i)) { |
| 303 | continue; |
| 304 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 305 | SkBitmap uncachedFrame; |
Leon Scroggins III | 91f0f73 | 2017-06-07 09:31:23 -0400 | [diff] [blame^] | 306 | if (!decode(&uncachedFrame, false, i)) { |
| 307 | continue; |
| 308 | } |
Leon Scroggins III | e132e7b | 2017-04-12 10:49:52 -0400 | [diff] [blame] | 309 | |
| 310 | // Now verify they're equal. |
| 311 | const size_t rowLen = info.bytesPerPixel() * info.width(); |
| 312 | for (int y = 0; y < info.height(); y++) { |
| 313 | const void* cachedAddr = cachedFrame.getAddr(0, y); |
| 314 | SkASSERT(cachedAddr != nullptr); |
| 315 | const void* uncachedAddr = uncachedFrame.getAddr(0, y); |
| 316 | SkASSERT(uncachedAddr != nullptr); |
| 317 | const bool lineMatches = memcmp(cachedAddr, uncachedAddr, rowLen) == 0; |
| 318 | if (!lineMatches) { |
| 319 | SkString name = SkStringPrintf("cached_%i", i); |
| 320 | write_bm(name.c_str(), cachedFrame); |
| 321 | name = SkStringPrintf("uncached_%i", i); |
| 322 | write_bm(name.c_str(), uncachedFrame); |
| 323 | ERRORF(r, "%s's frame %i is different depending on caching!", rec.fName, i); |
| 324 | break; |
| 325 | } |
| 326 | } |
Leon Scroggins III | b0b625b | 2016-12-22 16:40:24 -0500 | [diff] [blame] | 327 | } |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | } |