pub struct ImageFrame<P, E, D> { /* private fields */ }Expand description
A decoded still image. Not on the timeline — no pts, no duration
(the same fact AttachmentPacket
states on the packet side).
The fourth household, and the only one with no timestamps. Cover
art, an embedded thumbnail, a poster frame: one picture, present
for the whole file or not at all. Giving it pts / duration
seats that are always None would invite a caller to read them and
a backend to invent them, which is why they are absent rather than
empty.
Generic parameters — the same three VideoFrame carries:
P— pixel-format identifier.E— backend-specific frame extras (EXIF, ICC, side data).D— plane data buffer type (D: AsRef<[u8]>at the use site).
dimensions is the coded size and visible_rect (when
present) the displayable subregion — the distinction is not
academic for a still: a JPEG’s coded dimensions are rounded up to
its MCU grid (8 or 16 pixels), so a 30×30 photograph is coded 32×32
and only visible_rect says which of those pixels are the picture.
plane_count is the number of populated entries in planes, and
the four slots are the video household’s cap for the same reasons:
packed RGB = 1, MJPEG’s YUV = 3, either of those plus alpha = 4.
Implementations§
Source§impl<P, E, D> ImageFrame<P, E, D>
impl<P, E, D> ImageFrame<P, E, D>
Sourcepub const fn new(
dimensions: Dimensions,
pixel_format: P,
planes: [Plane<D>; 4],
plane_count: u8,
extra: E,
) -> Self
pub const fn new( dimensions: Dimensions, pixel_format: P, planes: [Plane<D>; 4], plane_count: u8, extra: E, ) -> Self
Constructs an ImageFrame. visible_rect defaults to None,
color to ColorInfo::UNSPECIFIED.
dimensions is the coded width/height pair (see
Dimensions and Self::dimensions for the visible-vs-coded
distinction).
§Panics
Panics if plane_count > 4. The fixed-size planes array has
four slots; passing a larger plane_count would later trip the
slice indexing inside Self::planes far from the construction
site. Asserting here fails fast with a clear message instead.
Prefer Self::try_new when plane_count can’t be statically
proven <= 4.
Sourcepub fn try_new(
dimensions: Dimensions,
pixel_format: P,
planes: [Plane<D>; 4],
plane_count: u8,
extra: E,
) -> Result<Self, FrameError>
pub fn try_new( dimensions: Dimensions, pixel_format: P, planes: [Plane<D>; 4], plane_count: u8, extra: E, ) -> Result<Self, FrameError>
Fallible counterpart to Self::new. Returns
FrameError::TooManyImagePlanes when plane_count > 4 (the
fixed plane array’s capacity) rather than panicking.
Not const fn — see the rationale on VideoFrame::try_new.
Sourcepub const fn dimensions(&self) -> Dimensions
pub const fn dimensions(&self) -> Dimensions
Returns the coded dimensions.
Sourcepub const fn visible_rect(&self) -> Option<Rect>
pub const fn visible_rect(&self) -> Option<Rect>
Returns the visible / true-picture rectangle, if any.
Sourcepub const fn pixel_format(&self) -> &P
pub const fn pixel_format(&self) -> &P
Returns a reference to the pixel format identifier.
Sourcepub const fn plane_count(&self) -> u8
pub const fn plane_count(&self) -> u8
Returns the populated plane count.
Sourcepub fn plane(&self, i: usize) -> Option<&Plane<D>>
pub fn plane(&self, i: usize) -> Option<&Plane<D>>
Returns one plane by index, or None if out of range.
Sourcepub fn color(&self) -> ColorInfo
pub fn color(&self) -> ColorInfo
Returns the color metadata.
Not const, for the same reason as VideoFrame::color.
Sourcepub const fn with_visible_rect(self, v: Option<Rect>) -> Self
pub const fn with_visible_rect(self, v: Option<Rect>) -> Self
Sets the visible rect (consuming builder).
Sourcepub fn with_color(self, v: ColorInfo) -> Self
pub fn with_color(self, v: ColorInfo) -> Self
Sets the color metadata (consuming builder).
Not const, for the same reason as VideoFrame::with_color.
Sourcepub const fn set_visible_rect(&mut self, v: Option<Rect>) -> &mut Self
pub const fn set_visible_rect(&mut self, v: Option<Rect>) -> &mut Self
Sets the visible rect in place.
Sourcepub fn set_color(&mut self, v: ColorInfo) -> &mut Self
pub fn set_color(&mut self, v: ColorInfo) -> &mut Self
Sets the color metadata in place.
Not const, for the same reason as VideoFrame::with_color.