Add wuffs_gif__quirk_first_frame_local_palette_etc

This commit is contained in:
Nigel Tao committed 2019-06-01 08:38:30 +10:00
1 parent e5e1f43f72
commit fd72372312
2 files changed
+140 -10

No files matched your search

+88 -2
View File
@@ -3324,6 +3324,13 @@ static const uint32_t //
wuffs_gif__quirk_delay_num_decoded_frames //
WUFFS_BASE__POTENTIALLY_UNUSED = 1041635328;
#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND \
1041635334
static const uint32_t //
wuffs_gif__quirk_first_frame_local_palette_means_black_background //
WUFFS_BASE__POTENTIALLY_UNUSED = 1041635334;
#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 1041635329
static const uint32_t //
@@ -3467,6 +3474,7 @@ struct wuffs_gif__decoder__struct {
uint64_t f_metadata_chunk_length_value;
uint64_t f_metadata_io_position;
bool f_quirk_enabled_delay_num_decoded_frames;
bool f_quirk_enabled_first_frame_local_palette_means_black_background;
bool f_quirk_enabled_honor_background_color;
bool f_quirk_enabled_ignore_too_much_pixel_data;
bool f_quirk_enabled_image_bounds_are_strict;
@@ -3481,6 +3489,7 @@ struct wuffs_gif__decoder__struct {
bool f_seen_num_loops;
uint32_t f_num_loops;
uint32_t f_background_color_u32_argb_premul;
uint32_t f_black_color_u32_argb_premul;
bool f_gc_has_transparent_index;
uint8_t f_gc_transparent_index;
uint8_t f_gc_disposal;
@@ -3522,6 +3531,10 @@ struct wuffs_gif__decoder__struct {
uint8_t f_dst_palette[1024];
wuffs_lzw__decoder f_lzw;
struct {
uint8_t v_blend;
uint32_t v_background_color;
} s_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
@@ -8769,6 +8782,10 @@ wuffs_gif__decoder__set_quirk_enabled(wuffs_gif__decoder* self,
if (self->private_impl.f_call_sequence == 0) {
if (a_quirk == 1041635328) {
self->private_impl.f_quirk_enabled_delay_num_decoded_frames = a_enabled;
} else if (a_quirk == 1041635334) {
self->private_impl
.f_quirk_enabled_first_frame_local_palette_means_black_background =
a_enabled;
} else if (a_quirk == 1041635329) {
self->private_impl.f_quirk_enabled_honor_background_color = a_enabled;
} else if (a_quirk == 1041635330) {
@@ -8841,6 +8858,12 @@ wuffs_gif__decoder__decode_image_config(wuffs_gif__decoder* self,
(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));
} else if (v_ffio) {
self->private_impl.f_black_color_u32_argb_premul = 4278190080;
}
if (self->private_impl.f_background_color_u32_argb_premul == 77) {
self->private_impl.f_background_color_u32_argb_premul =
self->private_impl.f_black_color_u32_argb_premul;
}
if (a_dst != NULL) {
wuffs_base__image_config__set(
@@ -9181,9 +9204,28 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
uint8_t v_blend = 0;
uint32_t v_background_color = 0;
uint8_t v_flags = 0;
uint8_t* iop_a_src = NULL;
uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
if (!a_src.private_impl.mark) {
a_src.private_impl.mark = iop_a_src;
a_src.private_impl.limit =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.wi;
}
io0_a_src = a_src.private_impl.mark;
io1_a_src = a_src.private_impl.limit;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
if (coro_susp_point) {
v_blend = self->private_data.s_decode_frame_config[0].v_blend;
v_background_color =
self->private_data.s_decode_frame_config[0].v_background_color;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -9193,21 +9235,45 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
wuffs_base__make_empty_struct());
if (!self->private_impl.f_end_of_data) {
if (self->private_impl.f_call_sequence == 0) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
if (a_src.private_impl.buf) {
iop_a_src = a_src.private_impl.buf->data.ptr +
a_src.private_impl.buf->meta.ri;
}
if (status) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence != 3) {
if (self->private_impl.f_call_sequence == 4) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_gif__decoder__skip_frame(self, a_src);
if (a_src.private_impl.buf) {
iop_a_src = a_src.private_impl.buf->data.ptr +
a_src.private_impl.buf->meta.ri;
}
if (status) {
goto suspend;
}
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src);
if (a_src.private_impl.buf) {
iop_a_src = a_src.private_impl.buf->data.ptr +
a_src.private_impl.buf->meta.ri;
}
if (status) {
goto suspend;
}
@@ -9218,11 +9284,23 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
goto ok;
}
v_blend = 0;
v_background_color = 0;
v_background_color = self->private_impl.f_black_color_u32_argb_premul;
if (!self->private_impl.f_gc_has_transparent_index) {
v_blend = 2;
v_background_color =
self->private_impl.f_background_color_u32_argb_premul;
if (self->private_impl
.f_quirk_enabled_first_frame_local_palette_means_black_background &&
(self->private_impl.f_num_decoded_frame_configs_value == 0)) {
while (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
status = wuffs_base__suspension__short_read;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
}
v_flags = wuffs_base__load_u8be(iop_a_src);
if ((v_flags & 128) != 0) {
v_background_color = self->private_impl.f_black_color_u32_argb_premul;
}
}
}
if (a_dst != NULL) {
wuffs_base__frame_config__update(
@@ -9257,9 +9335,17 @@ suspend:
wuffs_base__status__is_suspension(status) ? coro_susp_point : 0;
self->private_impl.active_coroutine =
wuffs_base__status__is_suspension(status) ? 3 : 0;
self->private_data.s_decode_frame_config[0].v_blend = v_blend;
self->private_data.s_decode_frame_config[0].v_background_color =
v_background_color;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
@@ -9860,7 +9946,7 @@ wuffs_gif__decoder__decode_lsd(wuffs_gif__decoder* self,
(((uint32_t)(self->private_data.f_palettes[0][(v_j + 3)]))
<< 24));
} else {
self->private_impl.f_background_color_u32_argb_premul = 4278190080;
self->private_impl.f_background_color_u32_argb_premul = 77;
}
}
}