Skip to main content

EncodeRequest

Struct EncodeRequest 

Source
pub struct EncodeRequest<'a> { /* private fields */ }
Expand description

Encoding request that borrows configuration, pixel data, and optional callbacks. Short-lived — created, configured, and consumed in one call chain.

§Example

use zenwebp::{EncodeRequest, LossyConfig, PixelLayout};

let config = LossyConfig::new().with_quality(85.0);
let rgba = vec![0u8; 640 * 480 * 4];
let webp = EncodeRequest::lossy(&config, &rgba, PixelLayout::Rgba8, 640, 480)
    .encode()?;

Implementations§

Source§

impl<'a> EncodeRequest<'a>

Source

pub fn lossy( config: &'a LossyConfig, pixels: &'a [u8], color_type: PixelLayout, width: u32, height: u32, ) -> Self

Create an encoding request with a lossy configuration.

§Example
use zenwebp::{EncodeRequest, LossyConfig, PixelLayout};

let config = LossyConfig::new().with_quality(85.0).with_method(4);
let rgba = vec![0u8; 640 * 480 * 4];
let webp = EncodeRequest::lossy(&config, &rgba, PixelLayout::Rgba8, 640, 480)
    .encode()?;
Source

pub fn lossless( config: &'a LosslessConfig, pixels: &'a [u8], color_type: PixelLayout, width: u32, height: u32, ) -> Self

Create an encoding request with a lossless configuration.

§Example
use zenwebp::{EncodeRequest, LosslessConfig, PixelLayout};

let config = LosslessConfig::new().with_quality(90.0);
let rgba = vec![0u8; 640 * 480 * 4];
let webp = EncodeRequest::lossless(&config, &rgba, PixelLayout::Rgba8, 640, 480)
    .encode()?;
Source

pub fn new( config: &'a EncoderConfig, pixels: &'a [u8], color_type: PixelLayout, width: u32, height: u32, ) -> Self

Create an encoding request with an enum configuration (runtime selection).

Use this when you need to choose between lossy and lossless at runtime. For compile-time mode selection, use lossy() or lossless() instead.

§Example
use zenwebp::{EncodeRequest, EncoderConfig, PixelLayout};

let config = EncoderConfig::new_lossy().with_quality(85.0);
let rgba = vec![0u8; 640 * 480 * 4];
let webp = EncodeRequest::new(&config, &rgba, PixelLayout::Rgba8, 640, 480)
    .encode()?;
Source

pub fn with_stop(self, stop: &'a dyn Stop) -> Self

Set a cooperative cancellation token.

Source

pub fn with_progress(self, progress: &'a dyn EncodeProgress) -> Self

Set a progress callback.

Source

pub fn with_stride(self, stride_pixels: usize) -> Self

Set row stride in pixels. Must be >= width.

Source

pub fn with_icc_profile(self, data: &'a [u8]) -> Self

Set ICC profile to embed.

Source

pub fn with_exif(self, data: &'a [u8]) -> Self

Set EXIF metadata to embed.

Source

pub fn with_xmp(self, data: &'a [u8]) -> Self

Set XMP metadata to embed.

Source

pub fn with_metadata(self, meta: ImageMetadata<'a>) -> Self

Set all metadata at once from an ImageMetadata struct.

This is a convenience method that sets ICC profile, EXIF, and XMP metadata in a single call. For setting individual fields, use with_icc_profile(), with_exif(), or with_xmp().

§Example
use zenwebp::{EncodeRequest, LossyConfig, PixelLayout, ImageMetadata};

let config = LossyConfig::new();
let pixels = vec![255u8; 4 * 4 * 4];
let icc_data = vec![/* ICC data */];
let metadata = ImageMetadata::new()
    .with_icc_profile(&icc_data);

let webp = EncodeRequest::lossy(&config, &pixels, PixelLayout::Rgba8, 4, 4)
    .with_metadata(metadata)
    .encode()?;
Source

pub fn encode(self) -> Result<Vec<u8>, EncodeError>

Encode to WebP bytes.

Source

pub fn encode_into(self, output: &mut Vec<u8>) -> Result<(), EncodeError>

Encode to WebP bytes, appending to an existing Vec.

Source

pub fn encode_with_stats(self) -> Result<(Vec<u8>, EncodeStats), EncodeError>

Encode to WebP bytes and return encoding statistics.

Source

pub fn encode_to<W: Write>(self, writer: W) -> Result<(), EncodeError>

Encode to WebP, writing to an io::Write implementor.

Auto Trait Implementations§

§

impl<'a> Freeze for EncodeRequest<'a>

§

impl<'a> !RefUnwindSafe for EncodeRequest<'a>

§

impl<'a> Send for EncodeRequest<'a>

§

impl<'a> Sync for EncodeRequest<'a>

§

impl<'a> Unpin for EncodeRequest<'a>

§

impl<'a> !UnwindSafe for EncodeRequest<'a>

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, 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.