From: Kostya Shishkov Date: Sat, 3 Jun 2023 07:45:13 +0000 (+0200) Subject: cinepakenc: factor out ELBG quantisation X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=7460b53e64c4ff4678b310789fa9a3c4f5096324;p=nihav.git cinepakenc: factor out ELBG quantisation This will be useful in the upcoming fast VQ mode. --- 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::(entries, codebook); + if cb_len < codebook.len() { + cb_len + } else { + let mut elbg: ELBG = 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::(&self.v1_entries, &mut self.v1_cur_cb[self.cur_strip]); - let v4_len = if !self.force_v1 { - quantise_median_cut::(&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 = 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 = 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::(&self.v1_entries, &mut self.v1_cur_cb[self.cur_strip]);