pub struct CameraFrame {
pub width: u32,
pub height: u32,
pub format: FrameFormat,
pub rotation_degrees: u16,
pub sequence: u64,
pub bytes: Vec<u8>,
}Expand description
One frame from the viewfinder.
Fields§
§width: u32§height: u32§format: FrameFormat§rotation_degrees: u16How far the frame must be rotated clockwise to be the right way up, which is the sensor’s mounting plus the device’s rotation.
sequence: u64Which frame this is in the session, so a consumer can tell a repeat from a new one and count what it missed.
bytes: Vec<u8>The pixels, in format.
Implementations§
Source§impl CameraFrame
impl CameraFrame
Sourcepub fn new(
width: u32,
height: u32,
format: FrameFormat,
rotation_degrees: u16,
sequence: u64,
bytes: Vec<u8>,
) -> Option<Self>
pub fn new( width: u32, height: u32, format: FrameFormat, rotation_degrees: u16, sequence: u64, bytes: Vec<u8>, ) -> Option<Self>
A frame, or None when the bytes do not match the size and format —
which is a backend bug, and one that reads as corrupted video rather
than as an error if it is let through.
Sourcepub fn to_rgba8(&self) -> Vec<u8> ⓘ
pub fn to_rgba8(&self) -> Vec<u8> ⓘ
The frame as tightly packed RGBA8, converting only when it has to.
One pass over the bytes with no allocation beyond the result, because this runs per frame: a conversion that allocates per row shows up as dropped frames rather than as a slow function.
Sourcepub fn upright_rgba8(&self) -> UprightRgba
pub fn upright_rgba8(&self) -> UprightRgba
The frame as tightly packed RGBA8 with
rotation_degrees applied, so the pixels are
the right way up whatever the sensor’s mounting was.
The turn happens in the same pass as the format conversion, because this runs on every previewed frame: converting and then turning would walk the pixels twice. A rotation that is not a quarter turn is left alone — no camera produces one.