diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2023-09-11 12:08:52 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2023-09-11 12:08:52 +0200 |
commit | 8fd97a64ae503561eb4a9778ece792cbabe3ed17 (patch) | |
tree | dd4e05038a112237f762c6897a450c52064ca49c /nihav-commonfmt | |
parent | fc39649daffd54a1f7277656f470df2751fcf620 (diff) | |
download | nihav-8fd97a64ae503561eb4a9778ece792cbabe3ed17.tar.gz |
gifenc: improve no-compression mode by keeping code lengths the same
Diffstat (limited to 'nihav-commonfmt')
-rw-r--r-- | nihav-commonfmt/src/codecs/gifenc.rs | 7 |
1 files changed, 6 insertions, 1 deletions
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() { |