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 |
11 #include "Resources.h" | 11 #include "Resources.h" |
12 #include "Test.h" | 12 #include "Test.h" |
13 | 13 |
14 #include <initializer_list> | 14 #include <initializer_list> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 DEF_TEST(Codec_frames, r) { | 17 DEF_TEST(Codec_frames, r) { |
18 static const struct { | 18 static const struct { |
19 const char* fName; | 19 const char* fName; |
20 size_t fFrameCount; | 20 size_t fFrameCount; |
21 // One less than fFramecount, since the first frame is always | 21 // One less than fFramecount, since the first frame is always |
22 // independent. | 22 // independent. |
23 std::vector<size_t> fRequiredFrames; | 23 std::vector<size_t> fRequiredFrames; |
24 // The size of this one should match fFrameCount for animated, empty | 24 // The size of this one should match fFrameCount for animated, empty |
25 // otherwise. | 25 // otherwise. |
26 std::vector<size_t> fDurations; | 26 std::vector<size_t> fDurations; |
| 27 int fRepetitionCount; |
27 } gRecs[] = { | 28 } gRecs[] = { |
28 { "box.gif", 1, {}, {} }, | 29 { "box.gif", 1, {}, {}, 0 }, |
29 { "color_wheel.gif", 1, {}, {} }, | 30 { "color_wheel.gif", 1, {}, {}, 0 }, |
30 { "test640x479.gif", 4, { 0, 1, 2 }, { 200, 200, 200, 200 } }, | 31 { "test640x479.gif", 4, { 0, 1, 2 }, { 200, 200, 200, 200 }, |
| 32 SkCodec::kRepetitionCountInfinite }, |
31 | 33 |
32 { "arrow.png", 1, {}, {} }, | 34 { "arrow.png", 1, {}, {}, 0 }, |
33 { "google_chrome.ico", 1, {}, {} }, | 35 { "google_chrome.ico", 1, {}, {}, 0 }, |
34 { "brickwork-texture.jpg", 1, {}, {} }, | 36 { "brickwork-texture.jpg", 1, {}, {}, 0 }, |
35 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) | 37 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) |
36 { "dng_with_preview.dng", 1, {}, {} }, | 38 { "dng_with_preview.dng", 1, {}, {}, 0 }, |
37 #endif | 39 #endif |
38 { "mandrill.wbmp", 1, {}, {} }, | 40 { "mandrill.wbmp", 1, {}, {}, 0 }, |
39 { "randPixels.bmp", 1, {}, {} }, | 41 { "randPixels.bmp", 1, {}, {}, 0 }, |
40 { "yellow_rose.webp", 1, {}, {} }, | 42 { "yellow_rose.webp", 1, {}, {}, 0 }, |
41 }; | 43 }; |
42 | 44 |
43 for (auto rec : gRecs) { | 45 for (auto rec : gRecs) { |
44 std::unique_ptr<SkStream> stream(GetResourceAsStream(rec.fName)); | 46 std::unique_ptr<SkStream> stream(GetResourceAsStream(rec.fName)); |
45 if (!stream) { | 47 if (!stream) { |
46 // Useful error statement, but sometimes people run tests without | 48 // Useful error statement, but sometimes people run tests without |
47 // resources, and they do not want to see these messages. | 49 // resources, and they do not want to see these messages. |
48 //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName); | 50 //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName); |
49 continue; | 51 continue; |
50 } | 52 } |
51 | 53 |
52 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()))
; | 54 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()))
; |
53 if (!codec) { | 55 if (!codec) { |
54 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); | 56 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); |
55 continue; | 57 continue; |
56 } | 58 } |
57 | 59 |
58 const size_t expected = rec.fFrameCount; | 60 const size_t expected = rec.fFrameCount; |
59 const auto frameInfos = codec->getFrameInfo(); | 61 int repetitionCount; |
| 62 const auto frameInfos = codec->getFrameInfo(&repetitionCount); |
60 // getFrameInfo returns empty set for non-animated. | 63 // getFrameInfo returns empty set for non-animated. |
61 const size_t frameCount = frameInfos.size() == 0 ? 1 : frameInfos.size()
; | 64 const size_t frameCount = frameInfos.size() == 0 ? 1 : frameInfos.size()
; |
62 if (frameCount != expected) { | 65 if (frameCount != expected) { |
63 ERRORF(r, "'%s' expected frame count: %i\tactual: %i", rec.fName, ex
pected, frameCount); | 66 ERRORF(r, "'%s' expected frame count: %i\tactual: %i", rec.fName, ex
pected, frameCount); |
64 continue; | 67 continue; |
65 } | 68 } |
66 | 69 |
67 if (rec.fRequiredFrames.size() + 1 != expected) { | 70 if (rec.fRequiredFrames.size() + 1 != expected) { |
68 ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expecte
d: %i\tactual: %i", | 71 ERRORF(r, "'%s' has wrong number entries in fRequiredFrames; expecte
d: %i\tactual: %i", |
69 rec.fName, expected, rec.fRequiredFrames.size()); | 72 rec.fName, expected, rec.fRequiredFrames.size()); |
70 continue; | 73 continue; |
71 } | 74 } |
72 | 75 |
73 if (1 == frameCount) { | 76 if (1 == frameCount) { |
74 continue; | 77 continue; |
75 } | 78 } |
76 | 79 |
77 // From here on, we are only concerned with animated images. | 80 // From here on, we are only concerned with animated images. |
| 81 REPORTER_ASSERT(r, repetitionCount == rec.fRepetitionCount); |
78 REPORTER_ASSERT(r, frameInfos[0].fRequiredFrame == SkCodec::kNone); | 82 REPORTER_ASSERT(r, frameInfos[0].fRequiredFrame == SkCodec::kNone); |
79 for (size_t i = 1; i < frameCount; i++) { | 83 for (size_t i = 1; i < frameCount; i++) { |
80 REPORTER_ASSERT(r, rec.fRequiredFrames[i-1] == frameInfos[i].fRequir
edFrame); | 84 REPORTER_ASSERT(r, rec.fRequiredFrames[i-1] == frameInfos[i].fRequir
edFrame); |
81 } | 85 } |
82 | 86 |
83 // Compare decoding in two ways: | 87 // Compare decoding in two ways: |
84 // 1. Provide the frame that a frame depends on, so the codec just has t
o blend. | 88 // 1. Provide the frame that a frame depends on, so the codec just has t
o blend. |
85 // (in the array cachedFrames) | 89 // (in the array cachedFrames) |
86 // 2. Do not provide the frame that a frame depends on, so the codec has
to decode all the | 90 // 2. Do not provide the frame that a frame depends on, so the codec has
to decode all the |
87 // way back to a key-frame. (in a local variable uncachedFrame) | 91 // way back to a key-frame. (in a local variable uncachedFrame) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i
\tactual: %i", | 136 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i
\tactual: %i", |
133 rec.fName, expected, rec.fDurations.size()); | 137 rec.fName, expected, rec.fDurations.size()); |
134 continue; | 138 continue; |
135 } | 139 } |
136 | 140 |
137 for (size_t i = 0; i < frameCount; i++) { | 141 for (size_t i = 0; i < frameCount; i++) { |
138 REPORTER_ASSERT(r, rec.fDurations[i] == frameInfos[i].fDuration); | 142 REPORTER_ASSERT(r, rec.fDurations[i] == frameInfos[i].fDuration); |
139 } | 143 } |
140 } | 144 } |
141 } | 145 } |
OLD | NEW |