| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkStream.h" | 9 #include "SkStream.h" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 continue; | 45 continue; |
| 46 } | 46 } |
| 47 | 47 |
| 48 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()))
; | 48 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()))
; |
| 49 if (!codec) { | 49 if (!codec) { |
| 50 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); | 50 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); |
| 51 continue; | 51 continue; |
| 52 } | 52 } |
| 53 | 53 |
| 54 const size_t expected = rec.fFrameCount; | 54 const size_t expected = rec.fFrameCount; |
| 55 const size_t frameCount = codec->getFrameCount(); | 55 const auto frameInfos = codec->getFrameInfo(); |
| 56 // getFrameInfo returns empty set for non-animated. |
| 57 const size_t frameCount = frameInfos.size() == 0 ? 1 : frameInfos.size()
; |
| 56 if (frameCount != expected) { | 58 if (frameCount != expected) { |
| 57 ERRORF(r, "'%s' expected frame count: %i\tactual: %i", rec.fName, ex
pected, frameCount); | 59 ERRORF(r, "'%s' expected frame count: %i\tactual: %i", rec.fName, ex
pected, frameCount); |
| 58 continue; | 60 continue; |
| 59 } | 61 } |
| 60 | 62 |
| 61 REPORTER_ASSERT(r, codec->getRequiredFrame(0) == SkCodec::kIndependentFr
ame); | |
| 62 | |
| 63 if (rec.fRequiredFrames.size() + 1 != expected) { | 63 if (rec.fRequiredFrames.size() + 1 != expected) { |
| 64 ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expecte
d: %i\tactual: %i", | 64 ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expecte
d: %i\tactual: %i", |
| 65 rec.fName, expected, rec.fRequiredFrames.size()); | 65 rec.fName, expected, rec.fRequiredFrames.size()); |
| 66 continue; | 66 continue; |
| 67 } | 67 } |
| 68 | 68 |
| 69 if (1 == frameCount) { | 69 if (1 == frameCount) { |
| 70 continue; | 70 continue; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // From here on, we are only concerned with animated images. | 73 // From here on, we are only concerned with animated images. |
| 74 REPORTER_ASSERT(r, frameInfos[0].fRequiredFrame == SkCodec::kIndependent
Frame); |
| 74 for (size_t i = 1; i < frameCount; i++) { | 75 for (size_t i = 1; i < frameCount; i++) { |
| 75 REPORTER_ASSERT(r, rec.fRequiredFrames[i-1] == codec->getRequiredFra
me(i)); | 76 REPORTER_ASSERT(r, rec.fRequiredFrames[i-1] == frameInfos[i].fRequir
edFrame); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Compare decoding in two ways: | 79 // Compare decoding in two ways: |
| 79 // 1. Provide the frame that a frame depends on, so the codec just has t
o blend. | 80 // 1. Provide the frame that a frame depends on, so the codec just has t
o blend. |
| 80 // (in the array cachedFrames) | 81 // (in the array cachedFrames) |
| 81 // 2. Do not provide the frame that a frame depends on, so the codec has
to decode all the | 82 // 2. Do not provide the frame that a frame depends on, so the codec has
to decode all the |
| 82 // way back to a key-frame. (in a local variable uncachedFrame) | 83 // way back to a key-frame. (in a local variable uncachedFrame) |
| 83 // The two should look the same. | 84 // The two should look the same. |
| 84 std::vector<SkBitmap> cachedFrames(frameCount); | 85 std::vector<SkBitmap> cachedFrames(frameCount); |
| 85 const auto& info = codec->getInfo().makeColorType(kN32_SkColorType); | 86 const auto& info = codec->getInfo().makeColorType(kN32_SkColorType); |
| 86 | 87 |
| 87 auto decode = [&](SkBitmap* bm, bool cached, size_t index) { | 88 auto decode = [&](SkBitmap* bm, bool cached, size_t index) { |
| 88 bm->allocPixels(info); | 89 bm->allocPixels(info); |
| 89 if (cached) { | 90 if (cached) { |
| 90 // First copy the pixels from the cached frame | 91 // First copy the pixels from the cached frame |
| 91 const size_t requiredFrame = codec->getRequiredFrame(index); | 92 const size_t requiredFrame = frameInfos[index].fRequiredFrame; |
| 92 if (requiredFrame != SkCodec::kIndependentFrame) { | 93 if (requiredFrame != SkCodec::kIndependentFrame) { |
| 93 const bool success = cachedFrames[requiredFrame].copyTo(bm); | 94 const bool success = cachedFrames[requiredFrame].copyTo(bm); |
| 94 REPORTER_ASSERT(r, success); | 95 REPORTER_ASSERT(r, success); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 SkCodec::Options opts; | 98 SkCodec::Options opts; |
| 98 SkCodec::MultiFrameOptions multiOpts; | 99 SkCodec::MultiFrameOptions multiOpts; |
| 99 multiOpts.fIndex = index; | 100 multiOpts.fIndex = index; |
| 100 multiOpts.fHasPriorFrame = cached; | 101 multiOpts.fHasPriorFrame = cached; |
| 101 opts.fFrameOptions = &multiOpts; | 102 opts.fFrameOptions = &multiOpts; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 if (rec.fDurations.size() != expected) { | 129 if (rec.fDurations.size() != expected) { |
| 129 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i
\tactual: %i", | 130 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i
\tactual: %i", |
| 130 rec.fName, expected, rec.fDurations.size()); | 131 rec.fName, expected, rec.fDurations.size()); |
| 131 continue; | 132 continue; |
| 132 } | 133 } |
| 133 | 134 |
| 134 for (size_t i = 0; i < frameCount; i++) { | 135 for (size_t i = 0; i < frameCount; i++) { |
| 135 REPORTER_ASSERT(r, rec.fDurations[i] == codec->getFrameDuration(i)); | 136 REPORTER_ASSERT(r, rec.fDurations[i] == frameInfos[i].fDuration); |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 } | 139 } |
| OLD | NEW |