move GenericCache to common place
[nihav.git] / nihav-duck / src / codecs / vp56.rs
index 54c84a040a80157331fc7e4ec0effbf19df905d8..d0a991f32869c6d0175c6966dc0316bace200a58 100644 (file)
@@ -1,4 +1,5 @@
 use nihav_core::codecs::*;
+use nihav_core::data::GenericCache;
 use nihav_core::io::bitreader::*;
 use super::vpcommon::*;
 
@@ -295,44 +296,6 @@ impl FrameState {
     }
 }
 
-pub struct GenericCache<T: Copy> {
-    pub height: usize,
-    pub stride: usize,
-    pub xpos:   usize,
-    pub data:   Vec<T>,
-    pub default: T,
-}
-
-impl<T:Copy> GenericCache<T> {
-    fn new(height: usize, stride: usize, default: T) -> Self {
-        let mut ret = Self {
-                stride,
-                height,
-                xpos:   0,
-                data:   Vec::with_capacity((height + 1) * stride),
-                default,
-            };
-        ret.reset();
-        ret
-    }
-    fn full_size(&self) -> usize { self.stride * (self.height + 1) }
-    fn reset(&mut self) {
-        self.data.truncate(0);
-        let size = self.full_size();
-        self.data.resize(size, self.default);
-        self.xpos = self.stride + 1;
-    }
-    fn update_row(&mut self) {
-        for i in 0..self.stride {
-            self.data[i] = self.data[self.height * self.stride + i];
-        }
-        self.data.truncate(self.stride);
-        let size = self.full_size();
-        self.data.resize(size, self.default);
-        self.xpos = self.stride + 1;
-    }
-}
-
 pub struct VP56Decoder {
     version:    u8,
     has_alpha:  bool,
@@ -381,17 +344,7 @@ fn map_mb_type(mbtype: VPMBType) -> usize {
     }
 }
 
-pub const VP56_COEF_BASE: [i16; 6] = [ 5, 7, 11, 19, 35, 67 ];
 pub fn expand_token_bc(bc: &mut BoolCoder, val_probs: &[u8; 11], token: u8, version: u8) -> i16 {
-    const COEF_ADD_PROBS: [[u8; 12]; 6] = [
-        [ 159, 128,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0 ],
-        [ 165, 145, 128,   0,   0,   0,   0,   0,   0,   0,   0,   0 ],
-        [ 173, 148, 140, 128,   0,   0,   0,   0,   0,   0,   0,   0 ],
-        [ 176, 155, 140, 135, 128,   0,   0,   0,   0,   0,   0,   0 ],
-        [ 180, 157, 141, 134, 130, 128,   0,   0,   0,   0,   0,   0 ],
-        [ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 128 ],
-    ];
-
     let mut sign = false;
     let level;
     if token < TOKEN_LARGE {
@@ -409,7 +362,7 @@ pub fn expand_token_bc(bc: &mut BoolCoder, val_probs: &[u8; 11], token: u8, vers
             sign                                = bc.read_bool();
         }
         let mut add = 0i16;
-        let add_probs = &COEF_ADD_PROBS[cat];
+        let add_probs = &VP56_COEF_ADD_PROBS[cat];
         for prob in add_probs.iter() {
             if *prob == 128 { break; }
             add                                 = (add << 1) | (bc.read_prob(*prob) as i16);