move GenericCache to common place
[nihav.git] / nihav-duck / src / codecs / vp56.rs
index c626be82ac7d9e08c986a25442b1f70076ae2de6..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,