| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| 11 | 11 |
| 12 #include "Resources.h" | 12 #include "Resources.h" |
| 13 #include "Test.h" | 13 #include "Test.h" |
| 14 | 14 |
| 15 #include <initializer_list> | 15 #include <initializer_list> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 DEF_TEST(Codec_frames, r) { | 18 DEF_TEST(Codec_frames, r) { |
| 19 static const struct { | 19 static const struct { |
| 20 const char* fName; | 20 const char* fName; |
| 21 size_t fFrameCount; | 21 size_t fFrameCount; |
| 22 // One less than fFramecount, since the first frame is always | 22 // One less than fFramecount, since the first frame is always |
| 23 // independent. | 23 // independent. |
| 24 std::vector<size_t> fRequiredFrames; | 24 std::vector<size_t> fRequiredFrames; |
| 25 // The size of this one should match fFrameCount for animated, empty | 25 // The size of this one should match fFrameCount for animated, empty |
| 26 // otherwise. | 26 // otherwise. |
| 27 std::vector<size_t> fDurations; | 27 std::vector<size_t> fDurations; |
| 28 int fRepetitionCount; |
| 28 } gRecs[] = { | 29 } gRecs[] = { |
| 29 { "box.gif", 1, {}, {} }, | 30 { "box.gif", 1, {}, {}, 0 }, |
| 30 { "color_wheel.gif", 1, {}, {} }, | 31 { "color_wheel.gif", 1, {}, {}, 0 }, |
| 31 { "test640x479.gif", 4, { 0, 1, 2 }, { 200, 200, 200, 200 } }, | 32 { "test640x479.gif", 4, { 0, 1, 2 }, { 200, 200, 200, 200 }, |
| 32 { "colorTables.gif", 2, { 0 }, { 1000, 1000 } }, | 33 SkCodec::kRepetitionCountInfinite }, |
| 34 { "colorTables.gif", 2, { 0 }, { 1000, 1000 }, 5 }, |
| 33 | 35 |
| 34 { "arrow.png", 1, {}, {} }, | 36 { "arrow.png", 1, {}, {}, 0 }, |
| 35 { "google_chrome.ico", 1, {}, {} }, | 37 { "google_chrome.ico", 1, {}, {}, 0 }, |
| 36 { "brickwork-texture.jpg", 1, {}, {} }, | 38 { "brickwork-texture.jpg", 1, {}, {}, 0 }, |
| 37 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) | 39 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) |
| 38 { "dng_with_preview.dng", 1, {}, {} }, | 40 { "dng_with_preview.dng", 1, {}, {}, 0 }, |
| 39 #endif | 41 #endif |
| 40 { "mandrill.wbmp", 1, {}, {} }, | 42 { "mandrill.wbmp", 1, {}, {}, 0 }, |
| 41 { "randPixels.bmp", 1, {}, {} }, | 43 { "randPixels.bmp", 1, {}, {}, 0 }, |
| 42 { "yellow_rose.webp", 1, {}, {} }, | 44 { "yellow_rose.webp", 1, {}, {}, 0 }, |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 for (auto rec : gRecs) { | 47 for (auto rec : gRecs) { |
| 46 std::unique_ptr<SkStream> stream(GetResourceAsStream(rec.fName)); | 48 std::unique_ptr<SkStream> stream(GetResourceAsStream(rec.fName)); |
| 47 if (!stream) { | 49 if (!stream) { |
| 48 // Useful error statement, but sometimes people run tests without | 50 // Useful error statement, but sometimes people run tests without |
| 49 // resources, and they do not want to see these messages. | 51 // resources, and they do not want to see these messages. |
| 50 //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName); | 52 //ERRORF(r, "Missing resources? Could not find '%s'", rec.fName); |
| 51 continue; | 53 continue; |
| 52 } | 54 } |
| 53 | 55 |
| 54 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()))
; | 56 std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()))
; |
| 55 if (!codec) { | 57 if (!codec) { |
| 56 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); | 58 ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName); |
| 57 continue; | 59 continue; |
| 58 } | 60 } |
| 59 | 61 |
| 62 const int repetitionCount = codec->getRepetitionCount(); |
| 63 if (repetitionCount != rec.fRepetitionCount) { |
| 64 ERRORF(r, "%s repetition count does not match! expected: %i\tactual:
%i", |
| 65 rec.fName, rec.fRepetitionCount, repetitionCount); |
| 66 } |
| 67 |
| 60 const size_t expected = rec.fFrameCount; | 68 const size_t expected = rec.fFrameCount; |
| 61 const auto frameInfos = codec->getFrameInfo(); | 69 const auto frameInfos = codec->getFrameInfo(); |
| 62 // getFrameInfo returns empty set for non-animated. | 70 // getFrameInfo returns empty set for non-animated. |
| 63 const size_t frameCount = frameInfos.size() == 0 ? 1 : frameInfos.size()
; | 71 const size_t frameCount = frameInfos.size() == 0 ? 1 : frameInfos.size()
; |
| 64 if (frameCount != expected) { | 72 if (frameCount != expected) { |
| 65 ERRORF(r, "'%s' expected frame count: %i\tactual: %i", rec.fName, ex
pected, frameCount); | 73 ERRORF(r, "'%s' expected frame count: %i\tactual: %i", rec.fName, ex
pected, frameCount); |
| 66 continue; | 74 continue; |
| 67 } | 75 } |
| 68 | 76 |
| 69 if (rec.fRequiredFrames.size() + 1 != expected) { | 77 if (rec.fRequiredFrames.size() + 1 != expected) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i
\tactual: %i", | 142 ERRORF(r, "'%s' has wrong number entries in fDurations; expected: %i
\tactual: %i", |
| 135 rec.fName, expected, rec.fDurations.size()); | 143 rec.fName, expected, rec.fDurations.size()); |
| 136 continue; | 144 continue; |
| 137 } | 145 } |
| 138 | 146 |
| 139 for (size_t i = 0; i < frameCount; i++) { | 147 for (size_t i = 0; i < frameCount; i++) { |
| 140 REPORTER_ASSERT(r, rec.fDurations[i] == frameInfos[i].fDuration); | 148 REPORTER_ASSERT(r, rec.fDurations[i] == frameInfos[i].fDuration); |
| 141 } | 149 } |
| 142 } | 150 } |
| 143 } | 151 } |
| OLD | NEW |