mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Decode a GIF's transparent index
This commit is contained in:
1 parent
49cb260774
commit
2e14f0fc6d
2 files changed
+38
-4
No files matched your search
+24
-2
@@ -3569,6 +3569,27 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
|||||||
v_i += 1;
|
v_i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (self->private_impl.f_gc_has_transparent_index) {
|
||||||
|
if (!v_use_local_palette) {
|
||||||
|
wuffs_base__slice_u8__copy_from_slice(
|
||||||
|
((wuffs_base__slice_u8){.ptr = self->private_impl.f_palettes[1],
|
||||||
|
.len = 1024}),
|
||||||
|
((wuffs_base__slice_u8){.ptr = self->private_impl.f_palettes[0],
|
||||||
|
.len = 1024}));
|
||||||
|
}
|
||||||
|
self->private_impl.f_palettes[1][(
|
||||||
|
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 0)] =
|
||||||
|
0;
|
||||||
|
self->private_impl.f_palettes[1][(
|
||||||
|
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 1)] =
|
||||||
|
0;
|
||||||
|
self->private_impl.f_palettes[1][(
|
||||||
|
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 2)] =
|
||||||
|
0;
|
||||||
|
self->private_impl.f_palettes[1][(
|
||||||
|
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 3)] =
|
||||||
|
0;
|
||||||
|
}
|
||||||
if (self->private_impl.f_previous_lzw_decode_ended_abruptly) {
|
if (self->private_impl.f_previous_lzw_decode_ended_abruptly) {
|
||||||
(memset(&self->private_impl.f_lzw, 0, sizeof((wuffs_lzw__decoder){})),
|
(memset(&self->private_impl.f_lzw, 0, sizeof((wuffs_lzw__decoder){})),
|
||||||
wuffs_lzw__decoder__check_wuffs_version(&self->private_impl.f_lzw,
|
wuffs_lzw__decoder__check_wuffs_version(&self->private_impl.f_lzw,
|
||||||
@@ -3681,7 +3702,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
v_palette = ((wuffs_base__slice_u8){});
|
v_palette = ((wuffs_base__slice_u8){});
|
||||||
if (v_use_local_palette) {
|
if (v_use_local_palette || self->private_impl.f_gc_has_transparent_index) {
|
||||||
v_palette = ((wuffs_base__slice_u8){
|
v_palette = ((wuffs_base__slice_u8){
|
||||||
.ptr = self->private_impl.f_palettes[1], .len = 1024});
|
.ptr = self->private_impl.f_palettes[1], .len = 1024});
|
||||||
} else if (!self->private_impl.f_previous_use_global_palette) {
|
} else if (!self->private_impl.f_previous_use_global_palette) {
|
||||||
@@ -3692,7 +3713,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1(
|
|||||||
self->private_impl.f_gc_duration, true,
|
self->private_impl.f_gc_duration, true,
|
||||||
self->private_impl.f_gc_disposal,
|
self->private_impl.f_gc_disposal,
|
||||||
v_palette);
|
v_palette);
|
||||||
self->private_impl.f_previous_use_global_palette = !v_use_local_palette;
|
self->private_impl.f_previous_use_global_palette =
|
||||||
|
!(v_use_local_palette || self->private_impl.f_gc_has_transparent_index);
|
||||||
self->private_impl.f_seen_graphic_control = false;
|
self->private_impl.f_seen_graphic_control = false;
|
||||||
self->private_impl.f_gc_has_transparent_index = false;
|
self->private_impl.f_gc_has_transparent_index = false;
|
||||||
self->private_impl.f_gc_transparent_index = 0;
|
self->private_impl.f_gc_transparent_index = 0;
|
||||||
|
|||||||
@@ -424,6 +424,18 @@ 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 {
|
||||||
|
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the gc_transparent_index palette entry to transparent black.
|
||||||
|
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 0] = 0x00
|
||||||
|
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 1] = 0x00
|
||||||
|
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 2] = 0x00
|
||||||
|
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 3] = 0x00
|
||||||
|
}
|
||||||
|
|
||||||
// Other GIF implementations accept GIF files that aren't completely spec
|
// Other GIF implementations accept GIF files that aren't completely spec
|
||||||
// compliant. For example, the test/data/gifplayer-muybridge.gif file
|
// compliant. For example, the test/data/gifplayer-muybridge.gif file
|
||||||
// (created by the gifsicle program) is accepted by other GIF decoders.
|
// (created by the gifsicle program) is accepted by other GIF decoders.
|
||||||
@@ -498,7 +510,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
|
|||||||
// TODO: check for "not enough pixel data".
|
// TODO: check for "not enough pixel data".
|
||||||
|
|
||||||
var palette slice base.u8
|
var palette slice base.u8
|
||||||
if use_local_palette {
|
if use_local_palette or this.gc_has_transparent_index {
|
||||||
palette = this.palettes[1][:]
|
palette = this.palettes[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.
|
||||||
@@ -510,7 +522,7 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader)
|
|||||||
in.dst.update!(dirty_rect:this.frame_rect, duration:this.gc_duration,
|
in.dst.update!(dirty_rect:this.frame_rect, duration:this.gc_duration,
|
||||||
blend:true, disposal:this.gc_disposal, palette:palette)
|
blend:true, disposal:this.gc_disposal, palette:palette)
|
||||||
|
|
||||||
this.previous_use_global_palette = not use_local_palette
|
this.previous_use_global_palette = not (use_local_palette or this.gc_has_transparent_index)
|
||||||
|
|
||||||
// The Image Descriptor is mandatory, but the Graphic Control extension is
|
// The Image Descriptor is mandatory, but the Graphic Control extension is
|
||||||
// optional. Reset the GC related fields for the next decode_frame call.
|
// optional. Reset the GC related fields for the next decode_frame call.
|
||||||
|
|||||||
Reference in new issue
Block a user