Use some more animated GIF test data

This commit is contained in:
Nigel Tao committed 2018-05-10 10:14:07 +10:00
1 parent 282b9c4b20
commit 76c6af4ff4
2 files changed
+92 -55

No files matched your search

+22 -25
View File
@@ -55,33 +55,30 @@ const char* mimic_gif_decode(wuffs_base__io_buffer* dst,
goto cleanup1; goto cleanup1;
} }
// TODO: have Wuffs accept multi-frame (animated) GIFs. int i;
if (f->ImageCount != 1) { for (i = 0; i < f->ImageCount; i++) {
ret = "GIF image has more than one frame"; // Copy the pixel data from the GifFileType* f to the dst buffer, since the
goto cleanup1; // former is free'd at the end of this function.
//
// In theory, this mimic_gif_decode function might be faster overall if the
// DGifSlurp call above decoded the pixel data directly into dst instead of
// into an intermediate buffer that needed to be malloc'ed and then free'd.
// In practice, doing so did not seem to show a huge difference. (See
// commit ab7e0ae "Add a custom gif_mimic_DGifSlurp function.") It also
// further complicates supporting both versions 4 and 5 of giflib. That
// commit was therefore rolled back.
struct SavedImage* si = &f->SavedImages[i];
size_t num_src =
(size_t)(si->ImageDesc.Width) * (size_t)(si->ImageDesc.Height);
size_t num_dst = dst->len - dst->wi;
if (num_dst < num_src) {
ret = "GIF image's pixel data won't fit in the dst buffer";
goto cleanup1;
}
memmove(dst->ptr + dst->wi, si->RasterBits, num_src);
dst->wi += num_src;
} }
// Copy the pixel data from the GifFileType* f to the dst buffer, since the
// former is free'd at the end of this function.
//
// In theory, this mimic_gif_decode function might be faster overall if the
// DGifSlurp call above decoded the pixel data directly into dst instead of
// into an intermediate buffer that needed to be malloc'ed and then free'd.
// In practice, doing so did not seem to show a huge difference. (See commit
// ab7e0ae "Add a custom gif_mimic_DGifSlurp function.") It also further
// complicates supporting both versions 4 and 5 of giflib. That commit was
// therefore rolled back.
struct SavedImage* si = &f->SavedImages[0];
size_t num_src =
(size_t)(si->ImageDesc.Width) * (size_t)(si->ImageDesc.Height);
size_t num_dst = dst->len - dst->wi;
if (num_dst < num_src) {
ret = "GIF image's pixel data won't fit in the dst buffer";
goto cleanup1;
}
memmove(dst->ptr + dst->wi, si->RasterBits, num_src);
dst->wi += num_src;
cleanup1:; cleanup1:;
#if defined(GIFLIB_MAJOR) && (GIFLIB_MAJOR >= 5) #if defined(GIFLIB_MAJOR) && (GIFLIB_MAJOR >= 5)
int close_status = DGifCloseFile(f, NULL); int close_status = DGifCloseFile(f, NULL);
+70 -30
View File
@@ -367,9 +367,14 @@ const char* wuffs_gif_decode(wuffs_base__io_buffer* dst,
if (s) { if (s) {
return wuffs_gif__status__string(s); return wuffs_gif__status__string(s);
} }
s = wuffs_gif__decoder__decode_frame(&dec, dst_writer, src_reader); while (true) {
if (s) { s = wuffs_gif__decoder__decode_frame(&dec, dst_writer, src_reader);
return wuffs_gif__status__string(s); if (s == WUFFS_GIF__SUSPENSION_END_OF_DATA) {
break;
}
if (s) {
return wuffs_gif__status__string(s);
}
} }
return NULL; return NULL;
} }
@@ -555,14 +560,14 @@ void test_wuffs_gif_call_sequence() {
} }
} }
void test_wuffs_gif_decode_animated() { bool do_test_wuffs_gif_decode_animated(const char* filename,
CHECK_FOCUS(__func__); uint32_t want_num_loops,
uint32_t want_num_frames) {
wuffs_base__io_buffer got = {.ptr = global_got_buffer, .len = BUFFER_SIZE}; wuffs_base__io_buffer got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
wuffs_base__io_buffer src = {.ptr = global_src_buffer, .len = BUFFER_SIZE}; wuffs_base__io_buffer src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
if (!read_file(&src, "../../data/animated-red-blue.gif")) { if (!read_file(&src, filename)) {
return; return false;
} }
wuffs_gif__decoder dec; wuffs_gif__decoder dec;
@@ -577,33 +582,30 @@ void test_wuffs_gif_decode_animated() {
if (status != WUFFS_GIF__STATUS_OK) { if (status != WUFFS_GIF__STATUS_OK) {
FAIL("decode_config: got %" PRIi32 " (%s)", status, FAIL("decode_config: got %" PRIi32 " (%s)", status,
wuffs_gif__status__string(status)); wuffs_gif__status__string(status));
return; return false;
} }
// animated-red-blue.gif's num_loops should be 3. The value explicitly in the if (wuffs_base__image_config__num_loops(&ic) != want_num_loops) {
// wire format is 0x0002, but that value means "repeat 2 times after the FAIL("num_loops: got %" PRIu32 ", want %" PRIu32,
// first play", so the total number of loops is 3. wuffs_base__image_config__num_loops(&ic), want_num_loops);
if (wuffs_base__image_config__num_loops(&ic) != 3) { return false;
FAIL("num_loops: got %" PRIu32 ", want 3",
wuffs_base__image_config__num_loops(&ic));
return;
} }
// animated-red-blue.gif should have 4 frames. uint32_t i;
int i; for (i = 0; i < want_num_frames; i++) {
for (i = 0; i < 4; i++) {
got.wi = 0; got.wi = 0;
status = wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader); status = wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader);
if (status != WUFFS_GIF__STATUS_OK) { if (status != WUFFS_GIF__STATUS_OK) {
FAIL("decode_frame #%d: got %" PRIi32 " (%s)", i, status, FAIL("decode_frame #%" PRIu32 ": got %" PRIi32 " (%s)", i, status,
wuffs_gif__status__string(status)); wuffs_gif__status__string(status));
return; return false;
} }
// TODO: check that the frame top/left/width/height is: // TODO: check that the frame top/left/width/height is:
// - 0, 0,64,48 for frame #0 // - 0, 0,64,48 for frame #0
// - 15,31,37, 9 for frame #1 // - 15,31,37, 9 for frame #1
// - 15, 0,49,40 for frame #2 // - 15, 0,49,40 for frame #2
// - 15, 0,49,40 for frame #3 // - 15, 0,49,40 for frame #3
// for "animated-red-blue.gif".
} }
// There should be no more frames. // There should be no more frames.
@@ -613,10 +615,33 @@ void test_wuffs_gif_decode_animated() {
FAIL("decode_frame: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, FAIL("decode_frame: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
wuffs_gif__status__string(status), WUFFS_GIF__SUSPENSION_END_OF_DATA, wuffs_gif__status__string(status), WUFFS_GIF__SUSPENSION_END_OF_DATA,
wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_END_OF_DATA)); wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_END_OF_DATA));
return; return false;
} }
// TODO: test calling wuffs_base__image_buffer__loop. // TODO: test calling wuffs_base__image_buffer__loop.
return true;
}
void test_wuffs_gif_decode_animated_big() {
CHECK_FOCUS(__func__);
// TODO: uncomment.
// do_test_wuffs_gif_decode_animated("../../data/gifplayer-muybridge.gif", 0, 0);
}
void test_wuffs_gif_decode_animated_medium() {
CHECK_FOCUS(__func__);
do_test_wuffs_gif_decode_animated("../../data/muybridge.gif", 0, 15);
}
void test_wuffs_gif_decode_animated_small() {
CHECK_FOCUS(__func__);
do_test_wuffs_gif_decode_animated("../../data/animated-red-blue.gif",
// animated-red-blue.gif's num_loops should
// be 3. The value explicitly in the wire
// format is 0x0002, but that value means
// "repeat 2 times after the first play", so
// the total number of loops is 3.
3, 4);
} }
void test_wuffs_gif_decode_input_is_a_gif() { void test_wuffs_gif_decode_input_is_a_gif() {
@@ -725,6 +750,12 @@ void test_mimic_gif_decode_bricks_nodither() {
do_test_mimic_gif_decode("../../data/bricks-nodither.gif"); do_test_mimic_gif_decode("../../data/bricks-nodither.gif");
} }
void test_mimic_gif_decode_gifplayer_muybridge() {
CHECK_FOCUS(__func__);
// TODO: uncomment.
// do_test_mimic_gif_decode("../../data/gifplayer-muybridge.gif");
}
void test_mimic_gif_decode_harvesters() { void test_mimic_gif_decode_harvesters() {
CHECK_FOCUS(__func__); CHECK_FOCUS(__func__);
do_test_mimic_gif_decode("../../data/harvesters.gif"); do_test_mimic_gif_decode("../../data/harvesters.gif");
@@ -740,6 +771,11 @@ void test_mimic_gif_decode_hibiscus() {
do_test_mimic_gif_decode("../../data/hibiscus.gif"); do_test_mimic_gif_decode("../../data/hibiscus.gif");
} }
void test_mimic_gif_decode_muybridge() {
CHECK_FOCUS(__func__);
do_test_mimic_gif_decode("../../data/muybridge.gif");
}
void test_mimic_gif_decode_pjw_thumbnail() { void test_mimic_gif_decode_pjw_thumbnail() {
CHECK_FOCUS(__func__); CHECK_FOCUS(__func__);
do_test_mimic_gif_decode("../../data/pjw-thumbnail.gif"); do_test_mimic_gif_decode("../../data/pjw-thumbnail.gif");
@@ -847,7 +883,9 @@ proc tests[] = {
test_wuffs_lzw_decode_pi, // test_wuffs_lzw_decode_pi, //
test_wuffs_gif_call_sequence, // test_wuffs_gif_call_sequence, //
test_wuffs_gif_decode_animated, // test_wuffs_gif_decode_animated_big, //
test_wuffs_gif_decode_animated_medium, //
test_wuffs_gif_decode_animated_small, //
test_wuffs_gif_decode_input_is_a_gif, // test_wuffs_gif_decode_input_is_a_gif, //
test_wuffs_gif_decode_input_is_a_gif_many_big_reads, // test_wuffs_gif_decode_input_is_a_gif_many_big_reads, //
test_wuffs_gif_decode_input_is_a_gif_many_medium_reads, // test_wuffs_gif_decode_input_is_a_gif_many_medium_reads, //
@@ -856,13 +894,15 @@ proc tests[] = {
#ifdef WUFFS_MIMIC #ifdef WUFFS_MIMIC
test_mimic_gif_decode_bricks_dither, // test_mimic_gif_decode_bricks_dither, //
test_mimic_gif_decode_bricks_gray, // test_mimic_gif_decode_bricks_gray, //
test_mimic_gif_decode_bricks_nodither, // test_mimic_gif_decode_bricks_nodither, //
test_mimic_gif_decode_harvesters, // test_mimic_gif_decode_gifplayer_muybridge, //
test_mimic_gif_decode_hat, // test_mimic_gif_decode_harvesters, //
test_mimic_gif_decode_hibiscus, // test_mimic_gif_decode_hat, //
test_mimic_gif_decode_pjw_thumbnail, // test_mimic_gif_decode_hibiscus, //
test_mimic_gif_decode_muybridge, //
test_mimic_gif_decode_pjw_thumbnail, //
#endif // WUFFS_MIMIC #endif // WUFFS_MIMIC