1use num_derive::FromPrimitive;
11
12use crate::api::{Opaque, T35};
13use crate::context::SB_SIZE;
14use crate::mc::SUBPEL_FILTER_SIZE;
15use crate::util::*;
16
17use crate::tiling::*;
18
19mod plane;
20pub use plane::*;
21
22const FRAME_MARGIN: usize = 16 + SUBPEL_FILTER_SIZE;
23const LUMA_PADDING: usize = SB_SIZE + FRAME_MARGIN;
24
25#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive, Default)]
29#[repr(C)]
30pub enum FrameTypeOverride {
31 #[default]
33 No,
34 Key,
36}
37
38#[derive(Debug, Default)]
40pub struct FrameParameters {
41 pub frame_type_override: FrameTypeOverride,
43 pub opaque: Option<Opaque>,
45 pub t35_metadata: Box<[T35]>,
47}
48
49pub use v_frame::frame::Frame;
50
51pub(crate) trait FrameAlloc {
53 fn new(width: usize, height: usize, chroma_sampling: ChromaSampling)
55 -> Self;
56}
57
58impl<T: Pixel> FrameAlloc for Frame<T> {
59 fn new(
63 width: usize, height: usize, chroma_sampling: ChromaSampling,
64 ) -> Self {
65 v_frame::frame::Frame::new_with_padding(
66 width,
67 height,
68 chroma_sampling,
69 LUMA_PADDING,
70 )
71 }
72}
73
74pub(crate) trait FramePad {
76 fn pad(&mut self, w: usize, h: usize, planes: usize);
77}
78
79impl<T: Pixel> FramePad for Frame<T> {
80 fn pad(&mut self, w: usize, h: usize, planes: usize) {
81 for pli in 0..planes {
82 self.planes[pli].pad(w, h);
83 }
84 }
85}
86
87pub(crate) trait AsTile<T: Pixel> {
89 fn as_tile(&self) -> Tile<'_, T>;
90 fn as_tile_mut(&mut self) -> TileMut<'_, T>;
91}
92
93impl<T: Pixel> AsTile<T> for Frame<T> {
94 #[inline(always)]
95 fn as_tile(&self) -> Tile<'_, T> {
96 let PlaneConfig { width, height, .. } = self.planes[0].cfg;
97 Tile::new(self, TileRect { x: 0, y: 0, width, height })
98 }
99 #[inline(always)]
100 fn as_tile_mut(&mut self) -> TileMut<'_, T> {
101 let PlaneConfig { width, height, .. } = self.planes[0].cfg;
102 TileMut::new(self, TileRect { x: 0, y: 0, width, height })
103 }
104}