1use crate::plane::VideoPlane;
2
3pub struct VideoFrame {
4 pub width: usize,
5 pub height: usize,
6 pub plane_y: VideoPlane,
7 pub plane_u: VideoPlane,
8 pub plane_v: VideoPlane,
9}
10
11impl VideoFrame {
12 pub fn new(width: usize, height: usize) -> VideoFrame {
13 assert!(width % 2 == 0 && height % 2 == 0);
14
15 let plane_y = VideoPlane::new(width, height);
16 let mut plane_u = VideoPlane::new(width / 2, height / 2);
17 let mut plane_v = VideoPlane::new(width / 2, height / 2);
18
19 plane_u.pixels.fill(128);
20 plane_v.pixels.fill(128);
21
22 VideoFrame { width: width, height: height,
23 plane_y: plane_y,
24 plane_u: plane_u,
25 plane_v: plane_v }
26 }
27
28 pub fn new_padded(width: usize, height: usize) -> VideoFrame {
29 let pad_width: usize = width + (16 - (width % 16)) % 16;
30 let pad_height = height + (16 - (height % 16)) % 16;
31
32 let chroma_width = width / 2;
33 let chroma_height = height / 2;
34
35 let chroma_pad_width: usize = chroma_width + (16 - (chroma_width % 16)) % 16;
36 let chroma_pad_height = chroma_height + (16 - (chroma_height % 16)) % 16;
37
38 let plane_y = VideoPlane::new(pad_width, pad_height);
39 let mut plane_u = VideoPlane::new(chroma_pad_width, chroma_pad_height);
40 let mut plane_v = VideoPlane::new(chroma_pad_width, chroma_pad_height);
41
42 plane_u.pixels.fill(128);
43 plane_v.pixels.fill(128);
44
45 VideoFrame { width: width, height: height,
46 plane_y: plane_y,
47 plane_u: plane_u,
48 plane_v: plane_v }
49 }
50
51 pub fn from_planes(width: usize, height: usize, plane_y: VideoPlane, plane_u: VideoPlane, plane_v: VideoPlane) -> VideoFrame {
52 assert!(plane_y.width == width && plane_y.height == height);
53 assert!(plane_u.width == width && plane_u.height == height);
54 assert!(plane_v.width == width && plane_v.height == height);
55
56 VideoFrame { width: width, height: height,
57 plane_y: plane_y,
58 plane_u: plane_u.reduce(),
59 plane_v: plane_v.reduce() }
60 }
61}