Skip to main content

ffmpeg_the_third/util/mathematics/
rounding.rs

1use crate::ffi::*;
2#[cfg(feature = "serialize")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Eq, PartialEq, Clone, Copy, Debug)]
6#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
7pub enum Rounding {
8    Zero,
9    Infinity,
10    Down,
11    Up,
12    NearInfinity,
13    PassMinMax,
14}
15
16impl From<AVRounding> for Rounding {
17    #[inline(always)]
18    fn from(value: AVRounding) -> Self {
19        use AVRounding as AV;
20
21        match value {
22            AV::ZERO => Rounding::Zero,
23            AV::INF => Rounding::Infinity,
24            AV::DOWN => Rounding::Down,
25            AV::UP => Rounding::Up,
26            AV::NEAR_INF => Rounding::NearInfinity,
27            AV::PASS_MINMAX => Rounding::PassMinMax,
28
29            _ => unimplemented!(),
30        }
31    }
32}
33
34impl From<Rounding> for AVRounding {
35    #[inline(always)]
36    fn from(value: Rounding) -> AVRounding {
37        use AVRounding as AV;
38
39        match value {
40            Rounding::Zero => AV::ZERO,
41            Rounding::Infinity => AV::INF,
42            Rounding::Down => AV::DOWN,
43            Rounding::Up => AV::UP,
44            Rounding::NearInfinity => AV::NEAR_INF,
45            Rounding::PassMinMax => AV::PASS_MINMAX,
46        }
47    }
48}