Skip to content

Commit be41ef5

Browse files
committed
Add index-based plane accessors to frame
1 parent d9d97e7 commit be41ef5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/frame.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@ pub struct Frame<T: Pixel> {
113113
pub bit_depth: NonZeroU8,
114114
}
115115

116+
impl<T: Pixel> Frame<T> {
117+
/// Returns a reference to the plane at the given 0-based index,
118+
/// if it exists in the frame. Otherwise, returns `None`.
119+
#[inline]
120+
#[must_use]
121+
pub fn plane(&self, index: usize) -> Option<&Plane<T>> {
122+
match index {
123+
0 => Some(&self.y_plane),
124+
1 => self.u_plane.as_ref(),
125+
2 => self.v_plane.as_ref(),
126+
_ => None,
127+
}
128+
}
129+
130+
/// Returns a mutable reference to the plane at the given 0-based index,
131+
/// if it exists in the frame. Otherwise, returns `None`.
132+
#[inline]
133+
#[must_use]
134+
pub fn plane_mut(&mut self, index: usize) -> Option<&mut Plane<T>> {
135+
match index {
136+
0 => Some(&mut self.y_plane),
137+
1 => self.u_plane.as_mut(),
138+
2 => self.v_plane.as_mut(),
139+
_ => None,
140+
}
141+
}
142+
}
143+
116144
/// A builder for constructing [`Frame`] instances with validation.
117145
///
118146
/// `FrameBuilder` uses the builder pattern to construct frames safely, validating

0 commit comments

Comments
 (0)