Add a image_config.first_frame_is_opaque method

This commit is contained in:
Nigel Tao committed 2018-06-11 11:07:14 +10:00
1 parent 26ce04ab64
commit 1ee2152785
20 files changed
+306 -141

No files matched your search

+23 -8
View File
@@ -64,6 +64,10 @@ pub struct decoder?(
background_color_index base.u8,
has_full_global_palette base.bool,
has_full_palette base.bool,
use_local_palette base.bool,
// interlace indexes the interlace_start and interlace_delta arrays.
interlace base.u8[..4],
@@ -117,12 +121,19 @@ pub func decoder.decode_config?(dst ptr base.image_config, src base.io_reader)()
num_loops = this.num_loops
}
var ffio base.bool = (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) and
(this.has_full_palette)
// TODO: rename initialize to set?
//
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED magic pixfmt constant.
in.dst.initialize!(pixfmt:0x22088888, pixsub:0,
width:this.width, height:this.height, num_loops:num_loops)
width:this.width, height:this.height, num_loops:num_loops, first_frame_is_opaque:ffio)
this.call_sequence = 1
}
@@ -225,6 +236,7 @@ pri func decoder.decode_lsd?(src base.io_reader)() {
this.palettes[0][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
i += 1
}
this.has_full_global_palette = i == 256
// Set the remaining palette entries to transparent black.
while i < 256 {
this.palettes[0][(4 * i) + 0] = 0x00
@@ -409,9 +421,7 @@ pri func decoder.decode_id_part0?(src base.io_reader)() {
this.width = this.width.max(x:this.frame_rect_x1)
this.height = this.height.max(x:this.frame_rect_y1)
}
}
pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)() {
var flags base.u8 = in.src.read_u8?()
if (flags & 0x40) != 0 {
this.interlace = 4
@@ -419,9 +429,11 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
this.interlace = 0
}
this.has_full_palette = this.has_full_global_palette
// Read the optional Local Color Table.
var use_local_palette base.bool = (flags & 0x80) != 0
if use_local_palette {
this.use_local_palette = (flags & 0x80) != 0
if this.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 {
@@ -435,6 +447,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
this.palettes[1][(4 * i) + 3] = ((argb >> 24) & 0xFF) as base.u8
i += 1
}
this.has_full_palette = i == 256
// Set the remaining palette entries to transparent black.
while i < 256 {
this.palettes[1][(4 * i) + 0] = 0x00
@@ -444,9 +457,11 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
i += 1
}
}
}
pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)() {
if this.gc_has_transparent_index {
if not use_local_palette {
if not this.use_local_palette {
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
}
@@ -531,7 +546,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
// TODO: check for "not enough pixel data".
var palette slice base.u8
if use_local_palette or this.gc_has_transparent_index {
if this.use_local_palette or this.gc_has_transparent_index {
palette = this.palettes[1][:]
} else if not this.previous_use_global_palette {
// This frame uses the global palette but the previous one didn't.
@@ -547,7 +562,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
max_excl_y:this.frame_rect_y1),
duration:this.gc_duration, blend:true, disposal:this.gc_disposal, palette:palette)
this.previous_use_global_palette = not (use_local_palette or this.gc_has_transparent_index)
this.previous_use_global_palette = not (this.use_local_palette or this.gc_has_transparent_index)
// The Image Descriptor is mandatory, but the Graphic Control extension is
// optional. Reset the GC related fields for the next decode_frame call.