diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 7abf7846..4fbe38fb 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -8768,12 +8768,14 @@ wuffs_gif__decoder__decode_image_config(wuffs_gif__decoder* self, if (status) { goto suspend; } - v_ffio = - (!self->private_impl.f_gc_has_transparent_index && - (self->private_impl.f_frame_rect_x0 == 0) && - (self->private_impl.f_frame_rect_y0 == 0) && - (self->private_impl.f_frame_rect_x1 == self->private_impl.f_width) && - (self->private_impl.f_frame_rect_y1 == self->private_impl.f_height)); + v_ffio = !self->private_impl.f_gc_has_transparent_index; + if (!self->private_impl.f_quirk_enabled_initial_background_is_opaque) { + v_ffio = + (v_ffio && (self->private_impl.f_frame_rect_x0 == 0) && + (self->private_impl.f_frame_rect_y0 == 0) && + (self->private_impl.f_frame_rect_x1 == self->private_impl.f_width) && + (self->private_impl.f_frame_rect_y1 == self->private_impl.f_height)); + } if (a_dst != NULL) { wuffs_base__image_config__set( a_dst, 1191444488, 0, self->private_impl.f_width, diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 98dc747e..b24b0357 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -209,11 +209,14 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re // TODO: if this.end_of_data, return an error and/or set dst to zero? - ffio = (not this.gc_has_transparent_index) and - (this.frame_rect_x0 == 0) and - (this.frame_rect_y0 == 0) and - (this.frame_rect_x1 == this.width) and - (this.frame_rect_y1 == this.height) + ffio = not this.gc_has_transparent_index + if not this.quirk_enabled_initial_background_is_opaque { + ffio = ffio and + (this.frame_rect_x0 == 0) and + (this.frame_rect_y0 == 0) and + (this.frame_rect_x1 == this.width) and + (this.frame_rect_y1 == this.height) + } if args.dst <> nullptr { // TODO: a Wuffs (not just C) name for the diff --git a/test/c/std/gif.c b/test/c/std/gif.c index 2c8fa49b..f608bddc 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -720,6 +720,48 @@ const char* test_wuffs_gif_decode_animated_small() { want_frame_config_bounds); } +const char* test_wuffs_gif_decode_first_frame_is_opaque() { + CHECK_FOCUS(__func__); + wuffs_base__io_buffer src = ((wuffs_base__io_buffer){ + .data = global_src_slice, + }); + const char* status = + read_file(&src, "test/data/artificial/gif-frame-out-of-bounds.gif"); + if (status) { + return status; + } + int q; + for (q = 0; q < 2; q++) { + src.meta.ri = 0; + + wuffs_gif__decoder dec; + status = wuffs_gif__decoder__initialize( + &dec, sizeof dec, WUFFS_VERSION, + WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED); + if (status) { + RETURN_FAIL("q=%d: initialize: \"%s\"", q, status); + } + wuffs_gif__decoder__set_quirk_enabled( + &dec, wuffs_gif__quirk_initial_background_is_opaque, q); + + wuffs_base__image_config ic = ((wuffs_base__image_config){}); + wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src); + status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src_reader); + if (status) { + RETURN_FAIL("q=%d: decode_image_config: \"%s\"", q, status); + } + + bool got = wuffs_base__image_config__first_frame_is_opaque(&ic); + bool want = q; + + if (got != want) { + RETURN_FAIL("q=%d: got %s, want %s", q, got ? "true" : "false", + want ? "true" : "false"); + } + } + return NULL; +} + const char* test_wuffs_gif_decode_frame_out_of_bounds() { CHECK_FOCUS(__func__); wuffs_base__io_buffer src = ((wuffs_base__io_buffer){ @@ -1879,6 +1921,7 @@ proc tests[] = { test_wuffs_gif_decode_animated_medium, // test_wuffs_gif_decode_animated_small, // test_wuffs_gif_decode_bgra_nonpremul, // + test_wuffs_gif_decode_first_frame_is_opaque, // test_wuffs_gif_decode_frame_out_of_bounds, // test_wuffs_gif_decode_input_is_a_gif_just_one_read, // test_wuffs_gif_decode_input_is_a_gif_many_big_reads, //