pub struct Config { /* private fields */ }Expand description
Decoding options and the color mode: a WebPDecoderOptions with typed
setters, and the output colorspace.
The setters store their value and never fail; Config::validate, which
every decoding calls first, reports a value that the API refuses, and
Config::output_size checks the crop against an image.
§Examples
use webp::api::decode::{ColorMode, Config};
let config = Config::new(ColorMode::PremultipliedBgra)
.crop(64, 32, 640, 480)
.scale(320, 240)
.multithreaded(true)
.dithering(50);
config.validate()?;
assert_eq!(config.as_raw().use_cropping, 1);Implementations§
Source§impl Config
impl Config
Sourcepub fn new(mode: ColorMode) -> Self
pub fn new(mode: ColorMode) -> Self
A configuration for mode with libwebp’s default options: no crop,
scale, flip or dithering, the in-loop filter and fancy upsampling on,
one thread (C: WebPInitDecoderConfig).
§Examples
use webp::api::decode::{ColorMode, Config};
let config = Config::new(ColorMode::Yuva);
assert_eq!(config.mode(), ColorMode::Yuva);
assert_eq!(config.as_raw().no_fancy_upsampling, 0);Sourcepub fn crop(self, left: u32, top: u32, width: u32, height: u32) -> Self
pub fn crop(self, left: u32, top: u32, width: u32, height: u32) -> Self
Decodes only the rectangle of width by height pixels at left,
top (C: use_cropping, crop_left, crop_top, crop_width,
crop_height). left and top must be even: libwebp moves an odd
lossy crop to the even position, so the API refuses odd offsets for
every image. To read a rectangle at an odd position, crop one column or
row earlier and skip it. The crop applies before the scale.
§Examples
use webp::api::decode::{ColorMode, Config, DecodeError};
assert!(Config::new(ColorMode::Rgb).crop(2, 4, 3, 5).validate().is_ok());
assert!(Config::new(ColorMode::Rgb).crop(3, 4, 3, 5).validate().is_err());Sourcepub fn scale(self, width: u32, height: u32) -> Self
pub fn scale(self, width: u32, height: u32) -> Self
Scales the (cropped) image to width by height pixels, each 1 to
16383 (C: use_scaling, scaled_width, scaled_height). libwebp’s
rescaler disables fancy upsampling, and a scale below 3/4 in both
directions skips the in-loop filter. libwebp derives a side given as 0;
the API needs both, so that it can bound the output before decoding.
§Examples
use webp::api::decode::{ColorMode, Config, DecodeError};
assert!(Config::new(ColorMode::Rgb).scale(100, 50).validate().is_ok());
assert_eq!(
Config::new(ColorMode::Rgb).scale(100, 0).validate(),
Err(DecodeError::InvalidScale { width: 100, height: 0 })
);Sourcepub fn flip(self, on: bool) -> Self
pub fn flip(self, on: bool) -> Self
Flips the output vertically (C: flip).
§Examples
use webp::api::decode::{ColorMode, Config};
assert_eq!(Config::new(ColorMode::Rgb).flip(true).as_raw().flip, 1);Sourcepub fn bypass_filtering(self, on: bool) -> Self
pub fn bypass_filtering(self, on: bool) -> Self
Skips the in-loop filter of lossy images, which is faster and changes
the samples (C: bypass_filtering).
§Examples
use webp::api::decode::{ColorMode, Config};
assert_eq!(Config::new(ColorMode::Rgb).bypass_filtering(true).as_raw().bypass_filtering, 1);Sourcepub fn fancy_upsampling(self, on: bool) -> Self
pub fn fancy_upsampling(self, on: bool) -> Self
Fancy upsampling of the chroma of lossy images in the RGB modes, on
by default; off uses the faster point upsampler (C: the negation of
no_fancy_upsampling).
§Examples
use webp::api::decode::{ColorMode, Config};
let config = Config::new(ColorMode::Rgb).fancy_upsampling(false);
assert_eq!(config.as_raw().no_fancy_upsampling, 1);Sourcepub fn multithreaded(self, on: bool) -> Self
pub fn multithreaded(self, on: bool) -> Self
Decodes lossy images with a second thread for filtering and output
(C: use_threads); the samples do not change.
§Examples
use webp::api::decode::{ColorMode, Config};
assert_eq!(Config::new(ColorMode::Rgb).multithreaded(true).as_raw().use_threads, 1);Sourcepub fn dithering(self, strength: u8) -> Self
pub fn dithering(self, strength: u8) -> Self
The strength of the dither that libwebp adds to lossy output, 0 (off,
the default) to 100 (C: dithering_strength).
§Examples
use webp::api::decode::{ColorMode, Config, DecodeError};
assert!(Config::new(ColorMode::Rgb).dithering(100).validate().is_ok());
assert_eq!(
Config::new(ColorMode::Rgb).dithering(101).validate(),
Err(DecodeError::InvalidParameter { name: "dithering" })
);Sourcepub fn alpha_dithering(self, strength: u8) -> Self
pub fn alpha_dithering(self, strength: u8) -> Self
The strength of the smoothing of quantized alpha, 0 (off, the default)
to 100 (C: alpha_dithering_strength).
§Examples
use webp::api::decode::{ColorMode, Config};
let config = Config::new(ColorMode::Rgba).alpha_dithering(100);
assert_eq!(config.as_raw().alpha_dithering_strength, 100);Sourcepub const fn mode(&self) -> ColorMode
pub const fn mode(&self) -> ColorMode
The color mode of the output.
§Examples
use webp::api::decode::{ColorMode, Config};
assert_eq!(Config::default().mode(), ColorMode::Rgb);Sourcepub fn validate(&self) -> Result<(), DecodeError>
pub fn validate(&self) -> Result<(), DecodeError>
Checks what does not depend on the image: a crop of at least 1 by 1
pixel at even left and top, every value at most i32::MAX; a scale
of 1 to 16383 on each side; dithering strengths of at most 100; then
libwebp’s WebPValidateDecoderConfig.
§Errors
DecodeError::InvalidCrop, DecodeError::InvalidScale or
DecodeError::InvalidParameter for the API’s rules, and
DecodeError::InvalidParam if libwebp refused the configuration
after them.
§Examples
use webp::api::decode::{ColorMode, Config, DecodeError};
assert_eq!(
Config::new(ColorMode::Rgb).crop(0, 0, 0, 8).validate(),
Err(DecodeError::InvalidCrop { left: 0, top: 0, width: 0, height: 8 })
);Sourcepub fn output_size(
&self,
features: &Features,
) -> Result<(u32, u32), DecodeError>
pub fn output_size( &self, features: &Features, ) -> Result<(u32, u32), DecodeError>
The width and height of the output for an image with features: the
crop’s size, then the scale’s, after Config::validate and a check
that the crop lies inside the image (C: WebPCheckCropDimensions).
§Errors
The errors of Config::validate, and DecodeError::InvalidCrop
for a crop that does not lie inside the image.
§Examples
use webp::api::decode::{ColorMode, Config, Features};
let features = Features { width: 640, height: 480, has_alpha: false, has_animation: false, format: None };
let config = Config::new(ColorMode::Rgb).crop(320, 0, 320, 480).scale(160, 240);
assert_eq!(config.output_size(&features)?, (160, 240));
assert!(Config::new(ColorMode::Rgb).crop(322, 0, 320, 480).output_size(&features).is_err());Sourcepub const fn as_raw(&self) -> &WebPDecoderOptions
pub const fn as_raw(&self) -> &WebPDecoderOptions
The options as libwebp reads them (C: WebPDecoderOptions).
§Examples
use webp::api::decode::{ColorMode, Config};
let config = Config::new(ColorMode::Rgb).crop(0, 2, 10, 20);
let raw = config.as_raw();
assert_eq!((raw.crop_top, raw.crop_width, raw.crop_height), (2, 10, 20));Trait Implementations§
impl Copy for Config
Source§impl Default for Config
impl Default for Config
Source§fn default() -> Self
fn default() -> Self
ColorMode::Rgb without options, as WebPInitDecoderConfig leaves
a configuration.