Prepare to re-org GIF Image Descriptor parsing

This commit is contained in:
Nigel Tao committed 2018-08-26 16:48:09 +10:00
1 parent 7798beaa8c
commit 87ee928448
2 files changed
+22 -15

No files matched your search

+12 -8
View File
@@ -2423,7 +2423,7 @@ typedef struct {
bool f_end_of_data; bool f_end_of_data;
bool f_previous_lzw_decode_ended_abruptly; bool f_previous_lzw_decode_ended_abruptly;
bool f_previous_use_global_palette; bool f_previous_use_global_palette;
bool f_use_local_palette; uint8_t f_local_palette_log2_size;
uint8_t f_which_palette; uint8_t f_which_palette;
uint8_t f_interlace; uint8_t f_interlace;
bool f_seen_num_loops; bool f_seen_num_loops;
@@ -6553,7 +6553,7 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
} }
} }
if (self->private_impl.f_use_local_palette || if ((self->private_impl.f_local_palette_log2_size != 0) ||
self->private_impl.f_gc_has_transparent_index) { self->private_impl.f_gc_has_transparent_index) {
self->private_impl.f_which_palette = 1; self->private_impl.f_which_palette = 1;
} else if (!self->private_impl.f_previous_use_global_palette) { } else if (!self->private_impl.f_previous_use_global_palette) {
@@ -6562,8 +6562,8 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
self->private_impl.f_which_palette = 2; self->private_impl.f_which_palette = 2;
} }
self->private_impl.f_previous_use_global_palette = self->private_impl.f_previous_use_global_palette =
!(self->private_impl.f_use_local_palette || ((self->private_impl.f_local_palette_log2_size == 0) &&
self->private_impl.f_gc_has_transparent_index); !self->private_impl.f_gc_has_transparent_index);
v_blend = 0; v_blend = 0;
if (!self->private_impl.f_gc_has_transparent_index) { if (!self->private_impl.f_gc_has_transparent_index) {
v_blend = 2; v_blend = 2;
@@ -7855,9 +7855,13 @@ wuffs_gif__decoder__decode_id_part0(wuffs_gif__decoder* self,
} else { } else {
self->private_impl.f_interlace = 0; self->private_impl.f_interlace = 0;
} }
self->private_impl.f_use_local_palette = ((v_flags & 128) != 0); self->private_impl.f_local_palette_log2_size = 0;
if (self->private_impl.f_use_local_palette) { if ((v_flags & 128) != 0) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7))); self->private_impl.f_local_palette_log2_size = (1 + (v_flags & 7));
}
if (self->private_impl.f_local_palette_log2_size != 0) {
v_num_palette_entries =
(((uint32_t)(1)) << self->private_impl.f_local_palette_log2_size);
v_i = 0; v_i = 0;
while (v_i < v_num_palette_entries) { while (v_i < v_num_palette_entries) {
{ {
@@ -7982,7 +7986,7 @@ wuffs_gif__decoder__decode_id_part1(wuffs_gif__decoder* self,
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_gc_has_transparent_index) { if (self->private_impl.f_gc_has_transparent_index) {
if (!self->private_impl.f_use_local_palette) { if (self->private_impl.f_local_palette_log2_size == 0) {
wuffs_base__slice_u8__copy_from_slice( wuffs_base__slice_u8__copy_from_slice(
((wuffs_base__slice_u8){.ptr = self->private_impl.f_palettes[1], ((wuffs_base__slice_u8){.ptr = self->private_impl.f_palettes[1],
.len = 1024}), .len = 1024}),
+10 -7
View File
@@ -76,7 +76,7 @@ pub struct decoder?(
previous_lzw_decode_ended_abruptly base.bool, previous_lzw_decode_ended_abruptly base.bool,
previous_use_global_palette base.bool, previous_use_global_palette base.bool,
use_local_palette base.bool, local_palette_log2_size base.u8[..8], // 0 means no local palette.
which_palette base.u8[..2], which_palette base.u8[..2],
@@ -188,7 +188,7 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
} }
} }
if this.use_local_palette or this.gc_has_transparent_index { if (this.local_palette_log2_size != 0) or this.gc_has_transparent_index {
this.which_palette = 1 this.which_palette = 1
} else if not this.previous_use_global_palette { } else if not this.previous_use_global_palette {
// This frame uses the global palette but the previous one didn't. // This frame uses the global palette but the previous one didn't.
@@ -199,7 +199,7 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
this.which_palette = 2 this.which_palette = 2
} }
this.previous_use_global_palette = this.previous_use_global_palette =
not (this.use_local_palette or this.gc_has_transparent_index) (this.local_palette_log2_size == 0) and not this.gc_has_transparent_index
var blend base.u8 = 0 var blend base.u8 = 0
if not this.gc_has_transparent_index { if not this.gc_has_transparent_index {
@@ -513,9 +513,12 @@ pri func decoder.decode_id_part0!??(src base.io_reader) {
} }
// Read the optional Local Color Table. // Read the optional Local Color Table.
this.use_local_palette = (flags & 0x80) != 0 this.local_palette_log2_size = 0
if this.use_local_palette { if (flags & 0x80) != 0 {
var num_palette_entries base.u32[..256] = (1 as base.u32) << (1 + (flags & 0x07)) this.local_palette_log2_size = 1 + (flags & 0x07)
}
if this.local_palette_log2_size != 0 {
var num_palette_entries base.u32[..256] = (1 as base.u32) << this.local_palette_log2_size
var i base.u32 var i base.u32
while i < num_palette_entries { while i < num_palette_entries {
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries) assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
@@ -541,7 +544,7 @@ pri func decoder.decode_id_part0!??(src base.io_reader) {
pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reader) { pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reader) {
if this.gc_has_transparent_index { if this.gc_has_transparent_index {
if not this.use_local_palette { if this.local_palette_log2_size == 0 {
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:]) this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
} }