1use crate::math::*;
11use crate::pixel::*;
12use crate::plane::*;
13
14#[cfg(feature = "serialize")]
15use serde::{Deserialize, Serialize};
16
17#[derive(Debug, Clone, Eq, PartialEq)]
19#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
20pub struct Frame<T: Pixel> {
21 pub planes: [Plane<T>; 3],
23}
24
25impl<T: Pixel> Frame<T> {
26 pub fn new_with_padding(
30 width: usize,
31 height: usize,
32 chroma_sampling: ChromaSampling,
33 luma_padding: usize,
34 ) -> Self {
35 let luma_width = width.align_power_of_two(3);
36 let luma_height = height.align_power_of_two(3);
37
38 let (chroma_decimation_x, chroma_decimation_y) =
39 chroma_sampling.get_decimation().unwrap_or((0, 0));
40 let (chroma_width, chroma_height) =
41 chroma_sampling.get_chroma_dimensions(luma_width, luma_height);
42 let chroma_padding_x = luma_padding >> chroma_decimation_x;
43 let chroma_padding_y = luma_padding >> chroma_decimation_y;
44
45 Frame {
46 planes: [
47 Plane::new(luma_width, luma_height, 0, 0, luma_padding, luma_padding),
48 Plane::new(
49 chroma_width,
50 chroma_height,
51 chroma_decimation_x,
52 chroma_decimation_y,
53 chroma_padding_x,
54 chroma_padding_y,
55 ),
56 Plane::new(
57 chroma_width,
58 chroma_height,
59 chroma_decimation_x,
60 chroma_decimation_y,
61 chroma_padding_x,
62 chroma_padding_y,
63 ),
64 ],
65 }
66 }
67}