/rust/registry/src/index.crates.io-6f17d22bba15001f/rav1e-0.7.1/src/frame/mod.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2018-2022, 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 num_derive::FromPrimitive; |
11 | | |
12 | | use crate::api::{Opaque, T35}; |
13 | | use crate::context::SB_SIZE; |
14 | | use crate::mc::SUBPEL_FILTER_SIZE; |
15 | | use crate::util::*; |
16 | | |
17 | | use crate::tiling::*; |
18 | | |
19 | | mod plane; |
20 | | pub use plane::*; |
21 | | |
22 | | const FRAME_MARGIN: usize = 16 + SUBPEL_FILTER_SIZE; |
23 | | const LUMA_PADDING: usize = SB_SIZE + FRAME_MARGIN; |
24 | | |
25 | | /// Override the frame type decision |
26 | | /// |
27 | | /// Only certain frame types can be selected. |
28 | 0 | #[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive, Default)] Unexecuted instantiation: <rav1e::frame::FrameTypeOverride as num_traits::cast::FromPrimitive>::from_i64 Unexecuted instantiation: <rav1e::frame::FrameTypeOverride as num_traits::cast::FromPrimitive>::from_u64 |
29 | | #[repr(C)] |
30 | | pub enum FrameTypeOverride { |
31 | | /// Do not force any decision. |
32 | | #[default] |
33 | | No, |
34 | | /// Force the frame to be a Keyframe. |
35 | | Key, |
36 | | } |
37 | | |
38 | | /// Optional per-frame encoder parameters |
39 | | #[derive(Debug, Default)] |
40 | | pub struct FrameParameters { |
41 | | /// Force emitted frame to be of the type selected |
42 | | pub frame_type_override: FrameTypeOverride, |
43 | | /// Output the provided data in the matching encoded Packet |
44 | | pub opaque: Option<Opaque>, |
45 | | /// List of t35 metadata associated with this frame |
46 | | pub t35_metadata: Box<[T35]>, |
47 | | } |
48 | | |
49 | | pub use v_frame::frame::Frame; |
50 | | |
51 | | /// Public Trait Interface for Frame Allocation |
52 | | pub(crate) trait FrameAlloc { |
53 | | /// Initialise new frame default type |
54 | | fn new(width: usize, height: usize, chroma_sampling: ChromaSampling) |
55 | | -> Self; |
56 | | } |
57 | | |
58 | | impl<T: Pixel> FrameAlloc for Frame<T> { |
59 | | /// Creates a new frame with the given parameters. |
60 | | /// new function calls `new_with_padding` function which takes `luma_padding` |
61 | | /// as parameter |
62 | 0 | fn new( |
63 | 0 | width: usize, height: usize, chroma_sampling: ChromaSampling, |
64 | 0 | ) -> Self { |
65 | 0 | v_frame::frame::Frame::new_with_padding( |
66 | 0 | width, |
67 | 0 | height, |
68 | 0 | chroma_sampling, |
69 | 0 | LUMA_PADDING, |
70 | 0 | ) |
71 | 0 | } Unexecuted instantiation: <v_frame::frame::Frame<u16> as rav1e::frame::FrameAlloc>::new Unexecuted instantiation: <v_frame::frame::Frame<u8> as rav1e::frame::FrameAlloc>::new |
72 | | } |
73 | | |
74 | | /// Public Trait for calculating Padding |
75 | | pub(crate) trait FramePad { |
76 | | fn pad(&mut self, w: usize, h: usize, planes: usize); |
77 | | } |
78 | | |
79 | | impl<T: Pixel> FramePad for Frame<T> { |
80 | 0 | fn pad(&mut self, w: usize, h: usize, planes: usize) { |
81 | 0 | for pli in 0..planes { |
82 | 0 | self.planes[pli].pad(w, h); |
83 | 0 | } |
84 | 0 | } Unexecuted instantiation: <v_frame::frame::Frame<u16> as rav1e::frame::FramePad>::pad Unexecuted instantiation: <v_frame::frame::Frame<u8> as rav1e::frame::FramePad>::pad |
85 | | } |
86 | | |
87 | | /// Public Trait for new Tile of a frame |
88 | | pub(crate) trait AsTile<T: Pixel> { |
89 | | fn as_tile(&self) -> Tile<'_, T>; |
90 | | fn as_tile_mut(&mut self) -> TileMut<'_, T>; |
91 | | } |
92 | | |
93 | | impl<T: Pixel> AsTile<T> for Frame<T> { |
94 | | #[inline(always)] |
95 | 0 | fn as_tile(&self) -> Tile<'_, T> { |
96 | 0 | let PlaneConfig { width, height, .. } = self.planes[0].cfg; |
97 | 0 | Tile::new(self, TileRect { x: 0, y: 0, width, height }) |
98 | 0 | } Unexecuted instantiation: <v_frame::frame::Frame<u16> as rav1e::frame::AsTile<u16>>::as_tile Unexecuted instantiation: <v_frame::frame::Frame<u8> as rav1e::frame::AsTile<u8>>::as_tile |
99 | | #[inline(always)] |
100 | 0 | fn as_tile_mut(&mut self) -> TileMut<'_, T> { |
101 | 0 | let PlaneConfig { width, height, .. } = self.planes[0].cfg; |
102 | 0 | TileMut::new(self, TileRect { x: 0, y: 0, width, height }) |
103 | 0 | } Unexecuted instantiation: <v_frame::frame::Frame<u16> as rav1e::frame::AsTile<u16>>::as_tile_mut Unexecuted instantiation: <v_frame::frame::Frame<u8> as rav1e::frame::AsTile<u8>>::as_tile_mut |
104 | | } |