Debian Codegraph @

.cargo/vendor/v_frame/src/frame.rs

raw
1 // Copyright (c) 2018-2020, The rav1e contributors. All rights reserved
2 //
3 // This source code is subject to the terms of the BSD 2 Clause License and
4 // the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
5 // was not distributed with this source code in the LICENSE file, you can
6 // obtain it at www.aomedia.org/license/software. If the Alliance for Open
7 // Media Patent License 1.0 was not distributed with this source code in the
8 // PATENTS file, you can obtain it at www.aomedia.org/license/patent.
9
10 use crate::math::*;
11 use crate::pixel::*;
12 use crate::plane::*;
13
14 #[cfg(feature = "serialize")]
15 use serde::{Deserialize, Serialize};
16
17 /// Represents a raw video frame
18 #[derive(Debug, Clone, Eq, PartialEq)]
19 #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
20 pub struct Frame<T: Pixel> {
21 /// Planes constituting the frame.
22 pub planes: [Plane<T>; 3],
23 }
24
25 impl<T: Pixel> Frame<T> {
26 /// Creates a new frame with the given parameters.
27 ///
28 /// Allocates data for the planes.
29 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 }