Decode a GIF's transparent index

This commit is contained in:
Nigel Tao committed 2018-06-09 07:39:11 +10:00
1 parent 49cb260774
commit 2e14f0fc6d
2 files changed
+38 -4

No files matched your search

+14 -2
View File
@@ -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
// compliant. For example, the test/data/gifplayer-muybridge.gif file
// (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".
var palette slice base.u8
if use_local_palette {
if 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.
@@ -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,
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
// optional. Reset the GC related fields for the next decode_frame call.