From: Kostya Shishkov Date: Sun, 6 Oct 2019 13:10:38 +0000 (+0200) Subject: move GenericCache to common place X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=1fdbd53e295c3876df7602cc5c5397730711ed24;p=nihav.git move GenericCache to common place --- diff --git a/nihav-core/src/data/mod.rs b/nihav-core/src/data/mod.rs new file mode 100644 index 0000000..ff5f190 --- /dev/null +++ b/nihav-core/src/data/mod.rs @@ -0,0 +1,38 @@ +pub struct GenericCache { + pub height: usize, + pub stride: usize, + pub xpos: usize, + pub data: Vec, + pub default: T, +} + +impl GenericCache { + pub 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 + } + pub fn full_size(&self) -> usize { self.stride * (self.height + 1) } + pub fn reset(&mut self) { + self.data.truncate(0); + let size = self.full_size(); + self.data.resize(size, self.default); + self.xpos = self.stride + 1; + } + pub 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; + } +} + diff --git a/nihav-core/src/lib.rs b/nihav-core/src/lib.rs index a3e2df1..4b6729c 100644 --- a/nihav-core/src/lib.rs +++ b/nihav-core/src/lib.rs @@ -26,4 +26,6 @@ pub mod scale; #[allow(clippy::unreadable_literal)] pub mod dsp; +pub mod data; + pub mod test; diff --git a/nihav-duck/src/codecs/vp56.rs b/nihav-duck/src/codecs/vp56.rs index c626be8..d0a991f 100644 --- a/nihav-duck/src/codecs/vp56.rs +++ b/nihav-duck/src/codecs/vp56.rs @@ -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 { - pub height: usize, - pub stride: usize, - pub xpos: usize, - pub data: Vec, - pub default: T, -} - -impl GenericCache { - 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, diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index f7f5334..dde0b04 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -3,49 +3,12 @@ use nihav_core::frame::{NABufferType, NAVideoInfo, NAVideoBuffer, NAVideoBufferR use nihav_core::codecs::{NADecoderSupport, MV, ZERO_MV, DecoderError, DecoderResult, IPBShuffler}; use nihav_core::io::bitreader::{BitReader,BitReaderMode}; use nihav_core::io::intcode::*; +use nihav_core::data::GenericCache; use std::mem; use super::rv34codes::*; use super::rv34dsp::*; -pub struct GenericCache { - pub height: usize, - pub stride: usize, - pub xpos: usize, - pub data: Vec, - pub default: T, -} - -impl GenericCache { - pub 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) } - pub fn reset(&mut self) { - self.data.truncate(0); - let size = self.full_size(); - self.data.resize(size, self.default); - self.xpos = self.stride + 1; - } - pub 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; - } -} - trait RV34MVScale { fn scale(&self, trd: u16, trb: u16) -> (MV, MV); }