30#include <initializer_list>
40 const char*
file =
"images/stoplight_h.webp";
62 for (
int i = 1;
i <=8;
i++) {
76 ERRORF(r,
"Failed to create animated image from %s",
file);
80 auto bounds = animatedImage->getBounds();
81 if (
bounds != expectedBounds) {
94 const char*
file =
"images/alphabetAnim.gif";
107 {
true, {100, 100}, { 0, 0, 100, 100} },
108 {
true, {100, 100}, { 0, 0, 50, 50} },
109 {
true, {100, 100}, { 10, 10, 100, 100} },
110 {
true, {100, 100}, { 0, 0, 100, 100} },
113 {
false, {100, 100}, { 0, 100, 100, 0} },
114 {
false, {100, 100}, { 100, 0, 0, 100} },
117 {
false, {100, 100}, { 0, 1, 100, 101} },
118 {
false, {100, 100}, { 0, -1, 100, 99} },
119 {
false, {100, 100}, { -1, 0, 99, 100} },
120 {
false, {100, 100}, { 100, 100, 200, 200} },
123 {
true, { 50, 50}, { 0, 0, 50, 50} },
124 {
true, { 50, 50}, { 0, 0, 25, 25} },
125 {
true, {200, 200}, { 0, 1, 100, 101} },
128 {
false, { 50, 50}, { 0, 0, 75, 25} },
129 {
false, { 50, 50}, { 0, 0, 25, 75} },
132 for (
const auto& rec : gRecs) {
135 ERRORF(r,
"Could not create codec for %s",
file);
139 auto info = codec->getInfo();
143 rec.cropRect,
nullptr);
154 const char*
file =
"images/alphabetAnim.gif";
163 ERRORF(r,
"Could not create codec for %s",
file);
168 auto info = codec->getInfo();
173 ERRORF(r,
"Failed to create animated image for %s",
file);
183 image->draw(&canvas);
184 for (
int i = 0;
i <
info.width(); ++
i)
185 for (
int j = 0; j <
info.height(); ++j) {
187 ERRORF(r,
"Erased color underneath!");
200 for (
int i = 0;
i < actualBm.
width(); ++
i)
201 for (
int j = 0; j < actualBm.
height(); ++j) {
204 if (expected != actual) {
205 ERRORF(r,
"frame %i of %s does not match at pixel %i, %i!"
206 " expected %x\tactual: %x",
207 expectedFrame,
file,
i, j, expected, actual);
222 for (
const char*
file : {
"images/alphabetAnim.gif",
223 "images/colorTables.gif",
224 "images/stoplight.webp",
225 "images/required.webp",
235 ERRORF(r,
"Could not create codec for %s",
file);
240 const int frameCount = codec->getFrameCount();
243 ERRORF(r,
"Could not create androidCodec for %s",
file);
248 if (!animatedImage) {
249 ERRORF(r,
"Could not create animated image for %s",
file);
252 animatedImage->setRepetitionCount(0);
254 std::vector<SkBitmap> expected(frameCount);
255 std::vector<sk_sp<SkPicture>> pictures(frameCount);
256 for (
int i = 0;
i < frameCount;
i++) {
262 pictures[
i] = animatedImage->makePictureSnapshot();
265 const auto duration = animatedImage->decodeNextFrame();
269 if (
i >= frameCount - 2) {
276 for (
int i = 0;
i < frameCount;
i++) {
278 test.allocPixels(imageInfo);
293 for (
const char*
file : {
"images/alphabetAnim.gif",
294 "images/colorTables.gif",
295 "images/stoplight.webp",
296 "images/required.webp",
306 ERRORF(r,
"Could not create codec for %s",
file);
310 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
311 std::vector<SkBitmap> frames(frameInfos.size());
326 const int defaultRepetitionCount = codec->getRepetitionCount();
328 for (
size_t i = 0;
i < frameInfos.size(); ++
i) {
330 auto& bm = frames[
i];
334 options.fPriorFrame = frameInfos[
i].fRequiredFrame;
336 bm.allocPixels(
info);
355 ERRORF(r,
"Could not create androidCodec for %s",
file);
360 if (!animatedImage) {
361 ERRORF(r,
"Could not create animated image for %s",
file);
365 REPORTER_ASSERT(r, defaultRepetitionCount == animatedImage->getRepetitionCount());
370 test.allocPixels(imageInfo);
373 animatedImage->draw(&c);
379 REPORTER_ASSERT(r, animatedImage->currentFrameDuration() == frameInfos[0].fDuration);
381 if (!testDraw(animatedImage, 0)) {
382 ERRORF(r,
"Did not start with frame 0");
388 for (
size_t i = 1;
i < frameInfos.size(); ++
i) {
389 const int frameTime = animatedImage->decodeNextFrame();
390 REPORTER_ASSERT(r, frameTime == animatedImage->currentFrameDuration());
392 if (
i == frameInfos.size() - 1 && defaultRepetitionCount == 0) {
400 if (!testDraw(animatedImage,
i)) {
401 ERRORF(r,
"Did not update to %zu properly",
i);
411 animatedImage->reset();
413 if (!testDraw(animatedImage, 0)) {
414 ERRORF(r,
"reset failed");
420 for (
int j = 0; j < (
int) frameInfos.size(); ++j) {
426 for (
int i = 0;
i <= j; ++
i) {
428 animatedImage->reset();
429 if (!testDraw(animatedImage, 0)) {
430 ERRORF(r,
"reset failed for image %s from frame %i",
436 animatedImage->decodeNextFrame();
437 if (!testDraw(animatedImage,
i)) {
438 ERRORF(r,
"failed to match frame %i in %s on iteration %i",
451 for (
int loopCount : { 0, 1, 2, 5 }) {
454 animatedImage->setRepetitionCount(loopCount);
457 for (
int loops = 0; loops <= loopCount; loops++) {
462 for (
size_t i = 1;
i <= frameInfos.size(); ++
i) {
463 const int frameTime = animatedImage->decodeNextFrame();
465 if (loops != loopCount) {
466 ERRORF(r,
"%s animation stopped early: loops: %i\tloopCount: %i",
467 file, loops, loopCount);
470 if (
i != frameInfos.size() - 1) {
471 ERRORF(r,
"%s animation stopped early: i: %zu\tsize: %zu",
472 file,
i, frameInfos.size());
480 if (!animatedImage->isFinished()) {
481 ERRORF(r,
"%s animation should have finished with specified loop count (%i)",
DEF_TEST(AnimatedImage_simple, r)
static bool compare_bitmaps(skiatest::Reporter *r, const char *file, int expectedFrame, const SkBitmap &expectedBm, const SkBitmap &actualBm)
void write_bm(const char *name, const SkBitmap &bm)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
sk_sp< SkData > GetResourceAsData(const char *resource)
SkString GetResourcePath(const char *resource)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
constexpr SkColor SK_ColorTRANSPARENT
constexpr SkColor SK_ColorBLUE
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
#define REPORTER_ASSERT(r, cond,...)
static std::unique_ptr< SkAndroidCodec > MakeFromData(sk_sp< SkData >, SkPngChunkReader *=nullptr)
static std::unique_ptr< SkAndroidCodec > MakeFromCodec(std::unique_ptr< SkCodec >)
static sk_sp< SkAnimatedImage > Make(std::unique_ptr< SkAndroidCodec >, const SkImageInfo &info, SkIRect cropRect, sk_sp< SkPicture > postProcess)
static constexpr int kFinished
void allocPixels(const SkImageInfo &info, size_t rowBytes)
SkISize dimensions() const
SkColorType colorType() const
uint32_t * getAddr32(int x, int y) const
void eraseColor(SkColor4f) const
void drawPicture(const SkPicture *picture)
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
static const char * ResultToString(Result)
static constexpr int kNoFrame
const char * c_str() const
static SkColor PMColorToColor(SkPMColor c)
Optional< SkRect > bounds
sk_sp< const SkImage > image
sk_sp< SkBlender > blender SkRect rect
DEF_SWITCHES_START aot vmservice shared library name
static constexpr SkISize Make(int32_t w, int32_t h)
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect MakeIWH(int w, int h)
std::shared_ptr< const fml::Mapping > data