diff options
author | Kostya Shishkov <[email protected]> | 2018-05-05 12:36:55 +0200 |
---|---|---|
committer | Kostya Shishkov <[email protected]> | 2018-05-05 12:36:55 +0200 |
commit | c3e7a747a47fdcc3d099c32f017b9736d560e0fc (patch) | |
tree | f5f14fde04c4483ad3260504bcf8df35efe80c4f /src/codecs/mod.rs | |
parent | 8f4c4020be0e141b30799514fa838842790bc53d (diff) |
move MV stuff to codecs
Diffstat (limited to 'src/codecs/mod.rs')
-rw-r--r-- | src/codecs/mod.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/codecs/mod.rs b/src/codecs/mod.rs index 1ee9f0d..4897a7b 100644 --- a/src/codecs/mod.rs +++ b/src/codecs/mod.rs @@ -1,3 +1,6 @@ +use std::fmt; +use std::ops::{Add, AddAssign, Sub, SubAssign}; + use frame::*; use std::rc::Rc; use std::cell::RefCell; @@ -137,6 +140,74 @@ impl IPBShuffler { } } +#[derive(Debug,Clone,Copy)] +pub struct MV { + pub x: i16, + pub y: i16, +} + +impl MV { + pub fn new(x: i16, y: i16) -> Self { MV{ x: x, y: y } } + pub fn pred(a: MV, b: MV, c: MV) -> Self { + let x; + if a.x < b.x { + if b.x < c.x { + x = b.x; + } else { + if a.x < c.x { x = c.x; } else { x = a.x; } + } + } else { + if b.x < c.x { + if a.x < c.x { x = a.x; } else { x = c.x; } + } else { + x = b.x; + } + } + let y; + if a.y < b.y { + if b.y < c.y { + y = b.y; + } else { + if a.y < c.y { y = c.y; } else { y = a.y; } + } + } else { + if b.y < c.y { + if a.y < c.y { y = a.y; } else { y = c.y; } + } else { + y = b.y; + } + } + MV { x: x, y: y } + } +} + +pub const ZERO_MV: MV = MV { x: 0, y: 0 }; + +impl Add for MV { + type Output = MV; + fn add(self, other: MV) -> MV { MV { x: self.x + other.x, y: self.y + other.y } } +} + +impl AddAssign for MV { + fn add_assign(&mut self, other: MV) { self.x += other.x; self.y += other.y; } +} + +impl Sub for MV { + type Output = MV; + fn sub(self, other: MV) -> MV { MV { x: self.x - other.x, y: self.y - other.y } } +} + +impl SubAssign for MV { + fn sub_assign(&mut self, other: MV) { self.x -= other.x; self.y -= other.y; } +} + +impl fmt::Display for MV { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{},{}", self.x, self.y) + } +} + + pub trait NADecoder { fn init(&mut self, info: Rc<NACodecInfo>) -> DecoderResult<()>; fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<NAFrameRef>; |