diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2023-06-03 09:45:13 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2023-06-03 09:45:13 +0200 |
commit | 7460b53e64c4ff4678b310789fa9a3c4f5096324 (patch) | |
tree | f5934925723697438daab30c0bf29d55ebb6e4ca /nihav-commonfmt/src/codecs/cinepakenc.rs | |
parent | 13704efd78d1055406fead7d801edada74c2ddf3 (diff) | |
download | nihav-7460b53e64c4ff4678b310789fa9a3c4f5096324.tar.gz |
cinepakenc: factor out ELBG quantisation
This will be useful in the upcoming fast VQ mode.
Diffstat (limited to 'nihav-commonfmt/src/codecs/cinepakenc.rs')
-rw-r--r-- | nihav-commonfmt/src/codecs/cinepakenc.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/nihav-commonfmt/src/codecs/cinepakenc.rs b/nihav-commonfmt/src/codecs/cinepakenc.rs index 99194ce..897bd3e 100644 --- a/nihav-commonfmt/src/codecs/cinepakenc.rs +++ b/nihav-commonfmt/src/codecs/cinepakenc.rs @@ -265,6 +265,16 @@ fn patch_size(bw: &mut ByteWriter, pos: u64) -> EncoderResult<()> { Ok(()) } +fn elbg_quant(entries: &[YUVCode], codebook: &mut [YUVCode]) -> usize { + let cb_len = quantise_median_cut::<YUVCode, YUVCodeSum>(entries, codebook); + if cb_len < codebook.len() { + cb_len + } else { + let mut elbg: ELBG<YUVCode, YUVCodeSum> = ELBG::new(codebook); + elbg.quantise(entries, codebook) + } +} + impl CinepakEncoder { fn new() -> Self { Self { @@ -604,24 +614,12 @@ impl CinepakEncoder { fn quant_vectors(&mut self) { match self.qmode { QuantMode::ELBG => { - let v1_len = quantise_median_cut::<YUVCode, YUVCodeSum>(&self.v1_entries, &mut self.v1_cur_cb[self.cur_strip]); - let v4_len = if !self.force_v1 { - quantise_median_cut::<YUVCode, YUVCodeSum>(&self.v4_entries, &mut self.v4_cur_cb[self.cur_strip]) + self.v1_len = elbg_quant(&self.v1_entries, &mut self.v1_cur_cb[self.cur_strip]); + self.v4_len = if !self.force_v1 { + elbg_quant(&self.v4_entries, &mut self.v4_cur_cb[self.cur_strip]) } else { 0 }; - self.v1_len = if v1_len < 256 { - v1_len - } else { - let mut elbg_v1: ELBG<YUVCode, YUVCodeSum> = ELBG::new(&self.v1_cur_cb[self.cur_strip]); - elbg_v1.quantise(&self.v1_entries, &mut self.v1_cur_cb[self.cur_strip]) - }; - self.v4_len = if v4_len < 256 { - v4_len - } else { - let mut elbg_v4: ELBG<YUVCode, YUVCodeSum> = ELBG::new(&self.v4_cur_cb[self.cur_strip]); - elbg_v4.quantise(&self.v4_entries, &mut self.v4_cur_cb[self.cur_strip]) - }; }, QuantMode::MedianCut => { self.v1_len = quantise_median_cut::<YUVCode, YUVCodeSum>(&self.v1_entries, &mut self.v1_cur_cb[self.cur_strip]); |