mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Put the GIF frame_config I/O position back 1 byte
We'll need that flags byte (for the interlace bit and palette size) when decoding frames in a random-access manner.
This commit is contained in:
1 parent
0066d6ac9b
commit
695d731fb9
3 files changed
+88
-96
No files matched your search
+13
-23
@@ -75,8 +75,6 @@ pub struct decoder?(
|
||||
end_of_data base.bool,
|
||||
previous_lzw_decode_ended_abruptly base.bool,
|
||||
|
||||
local_palette_log2_size base.u8[..8], // 0 means no local palette.
|
||||
|
||||
which_palette base.u8[..1],
|
||||
|
||||
// interlace indexes the interlace_start and interlace_delta arrays.
|
||||
@@ -211,8 +209,9 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
|
||||
|
||||
pri func decoder.skip_frame!??(src base.io_reader) {
|
||||
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
|
||||
if this.local_palette_log2_size != 0 {
|
||||
args.src.skip!??(n:(3 as base.u32) << this.local_palette_log2_size)
|
||||
var flags base.u8 = args.src.read_u8!??()
|
||||
if (flags & 0x80) != 0 {
|
||||
args.src.skip!??(n:(3 as base.u32) << (1 + (flags & 0x07)))
|
||||
}
|
||||
|
||||
var lw base.u8 = args.src.read_u8!??()
|
||||
@@ -494,7 +493,9 @@ 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.pixel_buffer, src base.io_reader) {
|
||||
var flags base.u8 = args.src.read_u8!??()
|
||||
if (flags & 0x40) != 0 {
|
||||
this.interlace = 4
|
||||
@@ -502,16 +503,10 @@ pri func decoder.decode_id_part0!??(src base.io_reader) {
|
||||
this.interlace = 0
|
||||
}
|
||||
|
||||
this.local_palette_log2_size = 0
|
||||
if (flags & 0x80) != 0 {
|
||||
this.local_palette_log2_size = 1 + (flags & 0x07)
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reader) {
|
||||
// Read the optional Local Color Table.
|
||||
if this.local_palette_log2_size != 0 {
|
||||
var num_palette_entries base.u32[..256] = (1 as base.u32) << this.local_palette_log2_size
|
||||
this.which_palette = 1
|
||||
if (flags & 0x80) != 0 {
|
||||
var num_palette_entries base.u32[..256] = (1 as base.u32) << (1 + (flags & 0x07))
|
||||
var i base.u32
|
||||
while i < num_palette_entries {
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
|
||||
@@ -532,25 +527,20 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
||||
this.palettes[1][(4 * i) + 3] = 0xFF
|
||||
i += 1
|
||||
}
|
||||
} else if this.gc_has_transparent_index {
|
||||
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
|
||||
} else {
|
||||
this.which_palette = 0
|
||||
}
|
||||
|
||||
// Set the gc_transparent_index palette entry to transparent black.
|
||||
if this.gc_has_transparent_index {
|
||||
if this.local_palette_log2_size == 0 {
|
||||
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
|
||||
}
|
||||
|
||||
if (this.local_palette_log2_size != 0) or this.gc_has_transparent_index {
|
||||
this.which_palette = 1
|
||||
} else {
|
||||
this.which_palette = 0
|
||||
}
|
||||
args.dst.set_palette!(palette:this.palettes[this.which_palette][:])
|
||||
|
||||
// Other GIF implementations accept GIF files that aren't completely spec
|
||||
|
||||
Reference in new issue
Block a user