na_mpeg2_decoder/video/
frame.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2pub enum PixelFormat {
3 Yuv420p,
4 Yuv422p,
5 Yuv444p,
6}
7
8#[derive(Clone, Debug)]
9pub struct Frame {
10 pub width: usize,
11 pub height: usize,
12 pub format: PixelFormat,
13 pub data_y: Vec<u8>,
14 pub data_u: Vec<u8>,
15 pub data_v: Vec<u8>,
16 pub linesize_y: usize,
17 pub linesize_u: usize,
18 pub linesize_v: usize,
19 pub pts_90k: Option<i64>,
20}
21
22impl Frame {
23 pub fn new(width: usize, height: usize, format: PixelFormat) -> Self {
24 let (cx, cy) = match format {
25 PixelFormat::Yuv420p => (1usize, 1usize),
26 PixelFormat::Yuv422p => (1usize, 0usize),
27 PixelFormat::Yuv444p => (0usize, 0usize),
28 };
29 let w_uv = width >> cx;
30 let h_uv = height >> cy;
31 let y = vec![0u8; width * height];
32 let u = vec![128u8; w_uv * h_uv];
33 let v = vec![128u8; w_uv * h_uv];
34 Self {
35 width,
36 height,
37 format,
38 data_y: y,
39 data_u: u,
40 data_v: v,
41 linesize_y: width,
42 linesize_u: w_uv,
43 linesize_v: w_uv,
44 pts_90k: None,
45 }
46 }
47
48 #[inline]
49 pub fn chroma_shifts(&self) -> (usize, usize) {
50 match self.format {
51 PixelFormat::Yuv420p => (1, 1),
52 PixelFormat::Yuv422p => (1, 0),
53 PixelFormat::Yuv444p => (0, 0),
54 }
55 }
56}