]> git.nihav.org Git - nihav.git/blob - nihav-core/src/data/mod.rs
vp6: switch to MD5-based tests
[nihav.git] / nihav-core / src / data / mod.rs
1 pub struct GenericCache<T: Copy> {
2 pub height: usize,
3 pub stride: usize,
4 pub xpos: usize,
5 pub data: Vec<T>,
6 pub default: T,
7 }
8
9 impl<T:Copy> GenericCache<T> {
10 pub fn new(height: usize, stride: usize, default: T) -> Self {
11 let mut ret = Self {
12 stride,
13 height,
14 xpos: 0,
15 data: Vec::with_capacity((height + 1) * stride),
16 default,
17 };
18 ret.reset();
19 ret
20 }
21 pub fn full_size(&self) -> usize { self.stride * (self.height + 1) }
22 pub fn reset(&mut self) {
23 self.data.truncate(0);
24 let size = self.full_size();
25 self.data.resize(size, self.default);
26 self.xpos = self.stride + 1;
27 }
28 pub fn update_row(&mut self) {
29 for i in 0..self.stride {
30 self.data[i] = self.data[self.height * self.stride + i];
31 }
32 self.data.truncate(self.stride);
33 let size = self.full_size();
34 self.data.resize(size, self.default);
35 self.xpos = self.stride + 1;
36 }
37 }
38