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>
impl<'a> EncodeRequest<'a>
Sourcepub fn lossy(
config: &'a LossyConfig,
pixels: &'a [u8],
color_type: PixelLayout,
width: u32,
height: u32,
) -> Self
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()?;Sourcepub fn lossless(
config: &'a LosslessConfig,
pixels: &'a [u8],
color_type: PixelLayout,
width: u32,
height: u32,
) -> Self
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()?;Sourcepub fn new(
config: &'a EncoderConfig,
pixels: &'a [u8],
color_type: PixelLayout,
width: u32,
height: u32,
) -> Self
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()?;Sourcepub fn with_progress(self, progress: &'a dyn EncodeProgress) -> Self
pub fn with_progress(self, progress: &'a dyn EncodeProgress) -> Self
Set a progress callback.
Sourcepub fn with_stride(self, stride_pixels: usize) -> Self
pub fn with_stride(self, stride_pixels: usize) -> Self
Set row stride in pixels. Must be >= width.
Sourcepub fn with_icc_profile(self, data: &'a [u8]) -> Self
pub fn with_icc_profile(self, data: &'a [u8]) -> Self
Set ICC profile to embed.
Sourcepub fn with_metadata(self, meta: ImageMetadata<'a>) -> Self
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()?;Sourcepub fn encode_into(self, output: &mut Vec<u8>) -> Result<(), EncodeError>
pub fn encode_into(self, output: &mut Vec<u8>) -> Result<(), EncodeError>
Encode to WebP bytes, appending to an existing Vec.
Sourcepub fn encode_with_stats(self) -> Result<(Vec<u8>, EncodeStats), EncodeError>
pub fn encode_with_stats(self) -> Result<(Vec<u8>, EncodeStats), EncodeError>
Encode to WebP bytes and return encoding statistics.