Skip to main content

WebPLossyEncoder

Struct WebPLossyEncoder 

Source
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

Source

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
Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.