From 8fd97a64ae503561eb4a9778ece792cbabe3ed17 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Mon, 11 Sep 2023 12:08:52 +0200 Subject: [PATCH] gifenc: improve no-compression mode by keeping code lengths the same --- nihav-commonfmt/src/codecs/gifenc.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nihav-commonfmt/src/codecs/gifenc.rs b/nihav-commonfmt/src/codecs/gifenc.rs index 6bb9263..3055acc 100644 --- a/nihav-commonfmt/src/codecs/gifenc.rs +++ b/nihav-commonfmt/src/codecs/gifenc.rs @@ -134,7 +134,12 @@ impl LZWEncoder { match self.level { CompressionLevel::None => { + let sym_limit = 1 << (clr_bits + 1); for &b in src.iter() { + if self.dict.cur_size >= sym_limit { + bw.write(u32::from(self.dict.clear_code), self.dict.bit_len); + self.dict.reset(); + } bw.write(u32::from(b), self.dict.bit_len); self.dict.add(usize::from(b), 0); } @@ -636,7 +641,7 @@ mod test { let enc_options = &[ NAOption { name: "compr", value: NAValue::String("none".to_string()) }, ]; - test_gif_encoder_single("none.gif", enc_options, &[0x2767a289, 0xdef9ad30, 0xca4c289b, 0x1fd0ec19]); + test_gif_encoder_single("none.gif", enc_options, &[0x32900cff, 0xef979bb0, 0x2d0355e8, 0x424bddee]); } #[test] fn test_gif_single_fast() { -- 2.30.2