Fix std/gif setting the dirty_palette bit

This commit is contained in:
Nigel Tao committed 2018-05-24 12:10:17 +10:00
1 parent 30e48093fc
commit 414d6e1f48
3 files changed
+38 -22

No files matched your search

+23 -9
View File
@@ -1258,9 +1258,8 @@ typedef struct {
uint8_t f_call_sequence;
bool f_end_of_data;
bool f_previous_lzw_decode_ended_abruptly;
bool f_previous_use_global_palette;
uint8_t f_background_color_index;
bool f_have_gct;
bool f_have_lct;
bool f_interlace;
bool f_seen_num_loops;
uint32_t f_num_loops;
@@ -1290,6 +1289,7 @@ typedef struct {
uint32_t coro_susp_point;
uint8_t v_c[7];
uint32_t v_i;
uint8_t v_flags;
uint32_t v_num_palette_entries;
} c_decode_lsd[1];
struct {
@@ -1318,6 +1318,7 @@ typedef struct {
struct {
uint32_t coro_susp_point;
uint8_t v_flags;
bool v_use_local_palette;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint8_t v_lw;
@@ -2376,6 +2377,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_lsd(
uint8_t v_c[7];
uint32_t v_i;
uint8_t v_flags;
uint32_t v_num_palette_entries;
uint8_t* ioptr_src = NULL;
@@ -2398,6 +2400,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_lsd(
if (coro_susp_point) {
memcpy(v_c, self->private_impl.c_decode_lsd[0].v_c, sizeof(v_c));
v_i = self->private_impl.c_decode_lsd[0].v_i;
v_flags = self->private_impl.c_decode_lsd[0].v_flags;
v_num_palette_entries =
self->private_impl.c_decode_lsd[0].v_num_palette_entries;
} else {
@@ -2422,10 +2425,10 @@ static wuffs_gif__status wuffs_gif__decoder__decode_lsd(
(((uint32_t)(v_c[0])) | (((uint32_t)(v_c[1])) << 8));
self->private_impl.f_height =
(((uint32_t)(v_c[2])) | (((uint32_t)(v_c[3])) << 8));
v_flags = v_c[4];
self->private_impl.f_background_color_index = v_c[5];
self->private_impl.f_have_gct = ((v_c[4] & 128) != 0);
if (self->private_impl.f_have_gct) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_c[4] & 7)));
if ((v_flags & 128) != 0) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7)));
v_i = 0;
while (v_i < v_num_palette_entries) {
{
@@ -2468,6 +2471,7 @@ suspend:
self->private_impl.c_decode_lsd[0].coro_susp_point = coro_susp_point;
memcpy(self->private_impl.c_decode_lsd[0].v_c, v_c, sizeof(v_c));
self->private_impl.c_decode_lsd[0].v_i = v_i;
self->private_impl.c_decode_lsd[0].v_flags = v_flags;
self->private_impl.c_decode_lsd[0].v_num_palette_entries =
v_num_palette_entries;
@@ -3094,6 +3098,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
uint8_t v_flags;
bool v_use_local_palette;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint8_t v_lw;
@@ -3151,6 +3156,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
self->private_impl.c_decode_id_part1[0].coro_susp_point;
if (coro_susp_point) {
v_flags = self->private_impl.c_decode_id_part1[0].v_flags;
v_use_local_palette =
self->private_impl.c_decode_id_part1[0].v_use_local_palette;
v_num_palette_entries =
self->private_impl.c_decode_id_part1[0].v_num_palette_entries;
v_i = self->private_impl.c_decode_id_part1[0].v_i;
@@ -3166,6 +3173,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
v_pixel_data = ((wuffs_base__slice_u8){});
v_p = self->private_impl.c_decode_id_part1[0].v_p;
} else {
v_use_local_palette = false;
v_w = ((wuffs_base__io_writer){});
v_write_to_ib_instead_of_w = false;
v_pass_through = ((wuffs_base__slice_u8){});
@@ -3184,8 +3192,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
v_flags = t_0;
}
self->private_impl.f_interlace = ((v_flags & 64) != 0);
self->private_impl.f_have_lct = ((v_flags & 128) != 0);
if (self->private_impl.f_have_lct) {
v_use_local_palette = ((v_flags & 128) != 0);
if (v_use_local_palette) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7)));
v_i = 0;
while (v_i < v_num_palette_entries) {
@@ -3345,13 +3353,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
}
label_0_break:;
v_p = 0;
if (self->private_impl.f_have_lct) {
if (v_use_local_palette) {
v_p = 1;
}
wuffs_base__image_buffer__update(
a_ib, true, self->private_impl.f_frame_rect, 0,
a_ib,
(v_use_local_palette ||
!self->private_impl.f_previous_use_global_palette),
self->private_impl.f_frame_rect, 0,
((wuffs_base__slice_u8){.ptr = self->private_impl.f_palettes[v_p],
.len = 1024}));
self->private_impl.f_previous_use_global_palette = !v_use_local_palette;
goto ok;
ok:
@@ -3363,6 +3375,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
suspend:
self->private_impl.c_decode_id_part1[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode_id_part1[0].v_flags = v_flags;
self->private_impl.c_decode_id_part1[0].v_use_local_palette =
v_use_local_palette;
self->private_impl.c_decode_id_part1[0].v_num_palette_entries =
v_num_palette_entries;
self->private_impl.c_decode_id_part1[0].v_i = v_i;
+3 -2
View File
@@ -1258,9 +1258,8 @@ typedef struct {
uint8_t f_call_sequence;
bool f_end_of_data;
bool f_previous_lzw_decode_ended_abruptly;
bool f_previous_use_global_palette;
uint8_t f_background_color_index;
bool f_have_gct;
bool f_have_lct;
bool f_interlace;
bool f_seen_num_loops;
uint32_t f_num_loops;
@@ -1290,6 +1289,7 @@ typedef struct {
uint32_t coro_susp_point;
uint8_t v_c[7];
uint32_t v_i;
uint8_t v_flags;
uint32_t v_num_palette_entries;
} c_decode_lsd[1];
struct {
@@ -1318,6 +1318,7 @@ typedef struct {
struct {
uint32_t coro_susp_point;
uint8_t v_flags;
bool v_use_local_palette;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint8_t v_lw;
+12 -11
View File
@@ -37,12 +37,10 @@ pub struct decoder?(
end_of_data base.bool,
previous_lzw_decode_ended_abruptly base.bool,
previous_use_global_palette base.bool,
background_color_index base.u8,
have_gct base.bool,
have_lct base.bool,
interlace base.bool,
// Absent an ANIMEXTS1.0 or NETSCAPE2.0 extension, the implicit number of
@@ -154,12 +152,12 @@ pri func decoder.decode_lsd?(src base.io_reader)() {
// TODO: use read_u16le.
this.width = (c[0] as base.u32) | ((c[1] as base.u32) << 8)
this.height = (c[2] as base.u32) | ((c[3] as base.u32) << 8)
var flags base.u8 = c[4]
this.background_color_index = c[5]
// Read the optional Global Color Table.
this.have_gct = (c[4] & 0x80) != 0
if this.have_gct {
var num_palette_entries base.u32[..256] = (1 as base.u32) << (1 + (c[4] & 0x07))
if (flags & 0x80) != 0 {
var num_palette_entries base.u32[..256] = (1 as base.u32) << (1 + (flags & 0x07))
i = 0
while i < num_palette_entries {
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
@@ -316,8 +314,8 @@ pri func decoder.decode_id_part1?(ib ptr base.image_buffer, dst base.io_writer,
this.interlace = (flags & 0x40) != 0
// Read the optional Local Color Table.
this.have_lct = (flags & 0x80) != 0
if this.have_lct {
var use_local_palette base.bool = (flags & 0x80) != 0
if use_local_palette {
var num_palette_entries base.u32[..256] = (1 as base.u32) << (1 + (flags & 0x07))
var i base.u32
while i < num_palette_entries {
@@ -433,9 +431,12 @@ pri func decoder.decode_id_part1?(ib ptr base.image_buffer, dst base.io_writer,
// TODO: have a builtin btoi or "b as base.u32"?
var p base.u32[..1] = 0
if this.have_lct {
if use_local_palette {
p = 1
}
// TODO: dirty_palette isn't always true; duration isn't always 0.
in.ib.update!(dirty_palette:true, dirty_rect:this.frame_rect, duration:0, palette:this.palettes[p][:])
// TODO: duration isn't always 0.
in.ib.update!(dirty_palette:use_local_palette or not this.previous_use_global_palette,
dirty_rect:this.frame_rect, duration:0, palette:this.palettes[p][:])
this.previous_use_global_palette = not use_local_palette
}