1 use super::super::vp7data::DEFAULT_MV_PROBS;
2 use super::super::vp78data::*;
3 pub use crate::codecs::vpenc::models::*;
7 pub coef_probs: [[[[u8; 11]; 3]; 8]; 4],
8 pub mv_probs: [[u8; 17]; 2],
9 pub kf_ymode_prob: [u8; 4],
10 pub kf_uvmode_prob: [u8; 3],
11 pub prob_intra_pred: u8,
12 pub prob_last_pred: u8,
13 pub feature_present: [u8; 4],
14 pub feature_tree_probs: [[u8; 3]; 4],
18 pub fn new() -> Self {
19 let mut obj: Self = unsafe { std::mem::zeroed() };
23 pub fn reset(&mut self) {
24 self.coef_probs.copy_from_slice(&DEFAULT_DCT_PROBS);
25 self.mv_probs.copy_from_slice(&DEFAULT_MV_PROBS);
26 self.kf_ymode_prob.copy_from_slice(Y_MODE_TREE_PROBS);
27 self.kf_uvmode_prob.copy_from_slice(UV_MODE_TREE_PROBS);
31 pub trait VP7ProbCounter {
32 fn to_prob8(self) -> u8;
33 fn to_prob8_worthy(&self, ref_prob: &mut u8);
36 impl VP7ProbCounter for ProbCounter {
37 fn to_prob8(self) -> u8 {
39 ((self.zeroes << 8) / self.total).min(255).max(1) as u8
44 fn to_prob8_worthy(&self, ref_prob: &mut u8) {
46 let new_prob = self.to_prob();
47 let new_bits = Self::est_bits(new_prob, self.zeroes, self.total);
48 let old_bits = Self::est_bits(*ref_prob, self.zeroes, self.total);
50 if new_bits + 8 < old_bits {
57 #[derive(Clone,Copy,Default)]
58 pub struct VP7ModelsStat {
59 pub coef_probs: [[[[ProbCounter; 11]; 3]; 8]; 4],
60 pub mv_probs: [[ProbCounter; 17]; 2],
61 pub kf_ymode_prob: [ProbCounter; 4],
62 pub kf_uvmode_prob: [ProbCounter; 3],
63 pub prob_intra_pred: ProbCounter,
64 pub prob_last_pred: ProbCounter,
65 pub feature_present: [ProbCounter; 4],
66 pub feature_tree_probs: [[ProbCounter; 3]; 4],
70 pub fn new() -> Self { Self::default() }
71 pub fn reset(&mut self) {
72 *self = Self::default();
74 pub fn generate(&self, dst: &mut VP7Models, is_intra: bool) {
75 for (dst, src) in dst.feature_present.iter_mut().zip(self.feature_present.iter()) {
76 *dst = src.to_prob8();
78 for (dst, src) in dst.feature_tree_probs.iter_mut().zip(self.feature_tree_probs.iter()) {
79 for (dst, src) in dst.iter_mut().zip(src.iter()) {
81 *dst = src.to_prob8();
87 for (dst, src) in dst.coef_probs.iter_mut().zip(self.coef_probs.iter()) {
88 for (dst, src) in dst.iter_mut().zip(src.iter()) {
89 for (dst, src) in dst.iter_mut().zip(src.iter()) {
90 for (dst, src) in dst.iter_mut().zip(src.iter()) {
91 src.to_prob8_worthy(dst);
98 dst.prob_intra_pred = self.prob_intra_pred.to_prob8();
99 dst.prob_last_pred = self.prob_last_pred.to_prob8();
101 for (dmv, smv) in dst.mv_probs.iter_mut().zip(self.mv_probs.iter()) {
102 for (dp, sp) in dmv.iter_mut().zip(smv.iter()) {
103 *dp = sp.to_prob_worthy(*dp);
107 for (dp, sp) in dst.kf_ymode_prob.iter_mut().zip(self.kf_ymode_prob.iter()) {
108 sp.to_prob8_worthy(dp);
110 for (dp, sp) in dst.kf_uvmode_prob.iter_mut().zip(self.kf_uvmode_prob.iter()) {
111 sp.to_prob8_worthy(dp);