pub struct Config { /* private fields */ }Expand description
Compression parameters: a WebPConfig with typed setters.
The setters store their value in the matching C field and never fail;
Config::validate, which every encoding calls first, reports a value
that is out of range. Config::raw_mut reaches the fields without a
setter (segments, filters, passes, partitions and the like).
§Examples
use webp::api::encode::{AlphaFilter, Config, ImageHint, Preset};
let lossy = Config::preset(Preset::Picture, 82.0)?
.method(6)
.alpha_quality(90)
.alpha_filter(AlphaFilter::Best)
.sharp_yuv(true);
lossy.validate()?;
let lossless = Config::new().lossless_level(9)?.exact(true).image_hint(ImageHint::Photo);
assert_eq!(lossless.as_raw().lossless, 1);Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
The default configuration: the default preset at quality 75, lossy
(C: WebPConfigInit).
§Examples
use webp::api::encode::Config;
let config = Config::new();
assert_eq!((config.as_raw().quality, config.as_raw().method), (75.0, 4));Sourcepub fn preset(preset: Preset, quality: f32) -> Result<Self, EncodeError>
pub fn preset(preset: Preset, quality: f32) -> Result<Self, EncodeError>
The configuration of preset at quality (C: WebPConfigPreset).
§Errors
EncodeError::InvalidParameter when quality is not finite or
outside 0 to 100.
§Examples
use webp::api::encode::{Config, EncodeError, Preset};
let config = Config::preset(Preset::Text, 90.0)?;
assert_eq!(config.as_raw().quality, 90.0);
assert_eq!(
Config::preset(Preset::Text, 100.5),
Err(EncodeError::InvalidParameter { name: "quality" })
);Sourcepub fn lossless_level(self, level: u8) -> Result<Self, EncodeError>
pub fn lossless_level(self, level: u8) -> Result<Self, EncodeError>
Switches to lossless encoding with the method and quality of level,
from 0 (fastest) to 9 (smallest), as cwebp -z does
(C: WebPConfigLosslessPreset).
§Errors
EncodeError::InvalidParameter when level is above 9.
§Examples
use webp::api::encode::Config;
let config = Config::new().lossless_level(6)?;
assert_eq!((config.as_raw().lossless, config.as_raw().method), (1, 4));
assert!(Config::new().lossless_level(10).is_err());Sourcepub fn lossless(self, on: bool) -> Self
pub fn lossless(self, on: bool) -> Self
Lossless (true) or lossy (false, the default) encoding
(C: lossless).
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().lossless(true).as_raw().lossless, 1);Sourcepub fn quality(self, quality: f32) -> Self
pub fn quality(self, quality: f32) -> Self
The quality, 0 to 100 (C: quality). Lossy: from small and poor to
large and good. Lossless: from fast to slow and small.
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().quality(30.0).as_raw().quality, 30.0);Sourcepub fn method(self, method: u8) -> Self
pub fn method(self, method: u8) -> Self
The trade-off between speed and size, 0 (fast) to 6 (slow, smaller)
(C: method).
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().method(6).as_raw().method, 6);Sourcepub fn image_hint(self, hint: ImageHint) -> Self
pub fn image_hint(self, hint: ImageHint) -> Self
A hint about the content for the lossless encoder (C: image_hint).
§Examples
use webp::api::encode::{Config, ImageHint};
assert_eq!(Config::new().image_hint(ImageHint::Photo).as_raw().image_hint.0, 2);Sourcepub fn target_size(self, bytes: u32) -> Self
pub fn target_size(self, bytes: u32) -> Self
A target size in bytes for a lossy encoding, 0 for none
(C: target_size). The C field is an int, so the value saturates at
i32::MAX, which no picture within the dimension limit reaches.
§Examples
use webp::api::encode::Config;
let config = Config::new().target_size(20_000);
assert_eq!(config.as_raw().target_size, 20_000);
assert_eq!(Config::new().target_size(u32::MAX).as_raw().target_size, i32::MAX);Sourcepub fn target_psnr(self, db: f32) -> Self
pub fn target_psnr(self, db: f32) -> Self
A target PSNR in dB for a lossy encoding, 0 for none (C: target_PSNR);
it takes precedence over Config::target_size.
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().target_psnr(42.0).as_raw().target_psnr, 42.0);Sourcepub fn alpha_compression(self, on: bool) -> Self
pub fn alpha_compression(self, on: bool) -> Self
Lossless compression of the alpha plane in a lossy encoding (true,
the default) or no compression (C: alpha_compression).
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().alpha_compression(false).as_raw().alpha_compression, 0);Sourcepub fn alpha_filter(self, filter: AlphaFilter) -> Self
pub fn alpha_filter(self, filter: AlphaFilter) -> Self
The predictive filter of the alpha plane (C: alpha_filtering).
§Examples
use webp::api::encode::{AlphaFilter, Config};
assert_eq!(Config::new().alpha_filter(AlphaFilter::None).as_raw().alpha_filtering, 0);Sourcepub fn alpha_quality(self, quality: u8) -> Self
pub fn alpha_quality(self, quality: u8) -> Self
The quality of the alpha plane, 0 (smallest) to 100 (lossless, the
default) (C: alpha_quality).
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().alpha_quality(50).as_raw().alpha_quality, 50);Sourcepub fn exact(self, on: bool) -> Self
pub fn exact(self, on: bool) -> Self
Keeps the samples under fully transparent areas (C: exact); see the
module documentation for what the encoder writes otherwise.
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().exact(true).as_raw().exact, 1);Sourcepub fn near_lossless(self, level: u8) -> Self
pub fn near_lossless(self, level: u8) -> Self
Near-lossless preprocessing of a lossless encoding, 0 (most loss) to 100
(off, the default) (C: near_lossless).
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().lossless(true).near_lossless(60).as_raw().near_lossless, 60);Sourcepub fn sharp_yuv(self, on: bool) -> Self
pub fn sharp_yuv(self, on: bool) -> Self
The sharp (iterative, slower) RGB-to-YUV conversion of a lossy encoding
of ARGB samples (C: use_sharp_yuv).
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().sharp_yuv(true).as_raw().use_sharp_yuv, 1);Sourcepub fn multithreaded(self, on: bool) -> Self
pub fn multithreaded(self, on: bool) -> Self
Lets the encoder use one more thread inside the call (C:
thread_level). The output depends on this setting, not on the
machine; the writer and the progress hook stay on the calling thread.
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().multithreaded(true).as_raw().thread_level, 1);Sourcepub fn validate(&self) -> Result<(), EncodeError>
pub fn validate(&self) -> Result<(), EncodeError>
Checks the configuration as every encoding does before it starts:
first the API’s own rules (quality finite and in 0 to 100,
target_psnr finite, which C does not check), then libwebp’s
validation (C: WebPValidateConfig).
§Errors
EncodeError::InvalidParameter for the API’s rules,
EncodeError::InvalidConfiguration for libwebp’s.
§Examples
use webp::api::encode::{Config, EncodeError};
assert_eq!(Config::new().validate(), Ok(()));
assert_eq!(Config::new().method(7).validate(), Err(EncodeError::InvalidConfiguration));Sourcepub const fn as_raw(&self) -> &WebPConfig
pub const fn as_raw(&self) -> &WebPConfig
The configuration of the translation.
§Examples
use webp::api::encode::Config;
assert_eq!(Config::new().as_raw().segments, 4);Sourcepub const fn raw_mut(&mut self) -> &mut WebPConfig
pub const fn raw_mut(&mut self) -> &mut WebPConfig
The configuration of the translation, mutably, for the fields without a
setter; Config::validate checks what is written.
§Examples
use webp::api::encode::Config;
let mut config = Config::new();
config.raw_mut().segments = 1;
config.raw_mut().pass = 6;
config.validate()?;Trait Implementations§
impl Copy for Config
Source§impl From<WebPConfig> for Config
impl From<WebPConfig> for Config
Source§fn from(raw: WebPConfig) -> Self
fn from(raw: WebPConfig) -> Self
Wraps a configuration of the translation as it is; Config::validate
checks it.