pub struct Buffer { /* private fields */ }
Expand description
A buffer returned by a camera to accommodate custom decoding.
Contains information of Resolution, the buffer’s FrameFormat
, and the buffer.
Note that decoding on the main thread will decrease your performance and lead to dropped frames.
Implementations§
source§impl Buffer
impl Buffer
sourcepub fn new(
res: Resolution,
buf: &[u8],
source_frame_format: FrameFormat
) -> Buffer
pub fn new( res: Resolution, buf: &[u8], source_frame_format: FrameFormat ) -> Buffer
Creates a new buffer with a [&[u8]
].
sourcepub fn resolution(&self) -> Resolution
pub fn resolution(&self) -> Resolution
Get the Resolution
of this buffer.
sourcepub fn buffer_bytes(&self) -> Bytes
pub fn buffer_bytes(&self) -> Bytes
Get a owned version of this buffer.
sourcepub fn source_frame_format(&self) -> FrameFormat
pub fn source_frame_format(&self) -> FrameFormat
Get the FrameFormat
of this buffer.
sourcepub fn decode_image<F>(
&self
) -> Result<ImageBuffer<<F as FormatDecoder>::Output, Vec<u8, Global>>, NokhwaError>where
F: FormatDecoder,
pub fn decode_image<F>( &self ) -> Result<ImageBuffer<<F as FormatDecoder>::Output, Vec<u8, Global>>, NokhwaError>where F: FormatDecoder,
Decodes a image with allocation using the provided FormatDecoder
.
Errors
Will error when the decoding fails.
sourcepub fn decode_image_to_buffer<F>(
&self,
buffer: &mut [u8]
) -> Result<(), NokhwaError>where
F: FormatDecoder,
pub fn decode_image_to_buffer<F>( &self, buffer: &mut [u8] ) -> Result<(), NokhwaError>where F: FormatDecoder,
Decodes a image with allocation using the provided FormatDecoder
into a buffer
.
Errors
Will error when the decoding fails, or the provided buffer is too small.
sourcepub fn decode_opencv_mat<F>(&mut self) -> Result<Mat, NokhwaError>where
F: FormatDecoder,
Available on crate feature opencv-mat
only.
pub fn decode_opencv_mat<F>(&mut self) -> Result<Mat, NokhwaError>where F: FormatDecoder,
opencv-mat
only.Decodes a image with allocation using the provided FormatDecoder
into a Mat
.
Note that this does a clone when creating the buffer, to decouple the lifetime of the internal data to the temporary Buffer. If you want to avoid this, please see decode_opencv_mat
.
Errors
Will error when the decoding fails, or OpenCV
failed to create/copy the Mat
.
Safety
This function uses unsafe
in order to create the Mat
. Please see Mat::new_rows_cols_with_data
for more.
Most notably, the data
must stay in scope for the duration of the Mat
or bad, bad things happen.
Trait Implementations§
source§impl PartialEq<Buffer> for Buffer
impl PartialEq<Buffer> for Buffer
source§impl PartialOrd<Buffer> for Buffer
impl PartialOrd<Buffer> for Buffer
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Buffer
impl StructuralEq for Buffer
impl StructuralPartialEq for Buffer
Auto Trait Implementations§
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.