pub struct WebPLossyEncoder { /* private fields */ }Expand description
VP8 lossy encoder for WebP.
Produces valid VP8 keyframe bitstreams that can be embedded in a WebP RIFF container. The encoder generates intra-only (keyframe) frames using DC prediction and a configurable quality parameter.
§Examples
use oximedia_codec::webp::encoder::WebPLossyEncoder;
let encoder = WebPLossyEncoder::new(75);
// 2x2 red image
let rgb = [255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0];
let vp8_data = encoder.encode_rgb(&rgb, 2, 2).expect("encode");
// The output starts with a valid VP8 frame tag
assert!(!vp8_data.is_empty());Implementations§
Source§impl WebPLossyEncoder
impl WebPLossyEncoder
Sourcepub fn new(quality: u8) -> Self
pub fn new(quality: u8) -> Self
Creates a new lossy encoder with the given quality (0-100).
- 0 = lowest quality / smallest size
- 100 = highest quality / largest size
Sourcepub fn encode_rgb(
&self,
data: &[u8],
width: u32,
height: u32,
) -> CodecResult<Vec<u8>>
pub fn encode_rgb( &self, data: &[u8], width: u32, height: u32, ) -> CodecResult<Vec<u8>>
Encodes RGB data to a VP8 bitstream (without RIFF container).
The input data must contain width * height * 3 bytes in
row-major R, G, B order (8 bits per component).
Returns the raw VP8 bitstream bytes suitable for wrapping in a WebP RIFF container.
§Errors
Returns CodecError::InvalidParameter if dimensions are zero or
the data length does not match width * height * 3.
Sourcepub fn encode_rgba(
&self,
data: &[u8],
width: u32,
height: u32,
) -> CodecResult<(Vec<u8>, Vec<u8>)>
pub fn encode_rgba( &self, data: &[u8], width: u32, height: u32, ) -> CodecResult<(Vec<u8>, Vec<u8>)>
Encodes RGBA data to VP8 bitstream + separate alpha channel.
Returns (vp8_data, alpha_data) where alpha_data contains
the raw alpha plane bytes (width * height, row-major, uncompressed).
§Errors
Returns CodecError::InvalidParameter if dimensions are zero or
the data length does not match width * height * 4.
Auto Trait Implementations§
impl Freeze for WebPLossyEncoder
impl RefUnwindSafe for WebPLossyEncoder
impl Send for WebPLossyEncoder
impl Sync for WebPLossyEncoder
impl Unpin for WebPLossyEncoder
impl UnsafeUnpin for WebPLossyEncoder
impl UnwindSafe for WebPLossyEncoder
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more