Skip to content

Commit 608fe79

Browse files
authored
fix: dispose transparent animated frames (#171)
1 parent a09c415 commit 608fe79

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/decoder.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -785,12 +785,6 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
785785
let use_alpha_blending = frame_info & 0b00000010 == 0;
786786
let dispose = frame_info & 0b00000001 != 0;
787787

788-
let clear_color = if self.animation.dispose_next_frame {
789-
info.background_color
790-
} else {
791-
None
792-
};
793-
794788
// Read normal bitstream now
795789
let (chunk, chunk_size, chunk_size_rounded) = read_chunk_header(&mut self.r)?;
796790
if chunk_size_rounded + 24 > anmf_size {
@@ -864,6 +858,16 @@ impl<R: BufRead + Seek> WebPDecoder<R> {
864858
_ => return Err(DecodingError::ChunkHeaderInvalid(chunk.to_fourcc())),
865859
};
866860

861+
let clear_color = if self.animation.dispose_next_frame {
862+
match (info.background_color, frame_has_alpha) {
863+
(color @ Some(_), _) => color,
864+
(_, true) => Some([0, 0, 0, 0]),
865+
_ => None,
866+
}
867+
} else {
868+
None
869+
};
870+
867871
// fill starting canvas with clear color
868872
if self.animation.canvas.is_none() {
869873
self.animation.canvas = {

0 commit comments

Comments
 (0)