Skip to main content

Features

Struct Features 

Source
pub struct Features {
    pub width: u32,
    pub height: u32,
    pub has_alpha: bool,
    pub has_animation: bool,
    pub format: Option<Format>,
}
Expand description

What a WebP file says about itself before decoding (C: WebPBitstreamFeatures).

§Examples

use webp::api::decode::{DecodeError, Features};

let features = Features::parse(&file)?;
assert_eq!((features.width, features.height), (5, 3));
assert!(features.has_alpha && !features.has_animation);

// A prefix that ends before the dimensions asks for more data.
assert_eq!(Features::parse(&file[..10]), Err(DecodeError::NotEnoughData));

Fields§

§width: u32

The width in pixels: the canvas of an extended (VP8X) file.

§height: u32

The height in pixels: the canvas of an extended (VP8X) file.

§has_alpha: bool

Whether the file declares alpha (the VP8X flag, an ALPH chunk or a lossless bitstream’s alpha bit).

§has_animation: bool

Whether the file is an animation; decode it with AnimationDecoder.

§format: Option<Format>

The compression of the image, or None when the parse did not reach a bitstream header (libwebp reports 0, “undefined”): for an animation, whose frames each carry their own format, and for an extended still image probed with a prefix that ends before its image chunk. Use has_animation to tell the two apart.

Implementations§

Source§

impl Features

Source

pub fn parse(data: &[u8]) -> Result<Self, DecodeError>

Reads the features from the start of a WebP file (C: WebPGetFeatures); a prefix is enough once it reaches the bitstream’s header, or the VP8X chunk of an extended file.

After the VP8X chunk of an extended still image the result can carry format: None, with the canvas as the size, until the prefix reaches the image chunk’s header; a caller who needs the format reads more until it is Some.

§Errors

DecodeError::NotEnoughData when the prefix ends too early, and DecodeError::BitstreamError for a file that is not a WebP file libwebp decodes.

§Examples
use webp::api::decode::{DecodeError, Features};

assert_eq!(Features::parse(b"RIFF"), Err(DecodeError::NotEnoughData));
assert_eq!(Features::parse(b"GIF89a, not a WebP file"), Err(DecodeError::BitstreamError));

A prefix of an extended still image that ends after the VP8X chunk gives the canvas but no format yet:

use webp::api::decode::{Features, Format};

// `file` is an extended 2 by 2 still image: a 12-byte RIFF header, an
// 18-byte `VP8X` chunk, then `ICCP`, `VP8L` and `EXIF` chunks.
let prefix = Features::parse(&file[..30])?;
assert_eq!((prefix.width, prefix.height), (2, 2));
assert_eq!((prefix.format, prefix.has_animation), (None, false));

assert_eq!(Features::parse(&file)?.format, Some(Format::Lossless));

Trait Implementations§

Source§

impl Clone for Features

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Features

Source§

impl Debug for Features

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Features

Source§

impl Hash for Features

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Features

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Features

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.