Skip to main content

Image

Struct Image 

Source
pub struct Image { /* private fields */ }
Expand description

A decoded image in memory that libwebp allocated, which the image owns.

§Examples

use webp::api::decode::{decode, ColorMode, Config};

let image = decode(&file, &Config::new(ColorMode::Bgra))?;
assert_eq!((image.mode(), image.width(), image.height()), (ColorMode::Bgra, 4, 2));
assert_eq!(&image.samples()[..4], &[33, 22, 11, 44]);
let samples: Vec<u8> = image.into_samples();
assert_eq!(samples.len(), 4 * 4 * 2);

Implementations§

Source§

impl Image

Source

pub const fn mode(&self) -> ColorMode

The color mode of the samples.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

assert_eq!(decode(&file, &Config::new(ColorMode::Yuv))?.mode(), ColorMode::Yuv);
Source

pub const fn width(&self) -> u32

The width in pixels, after crop and scale.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

let image = decode(&file, &Config::new(ColorMode::Rgb).scale(3, 2))?;
assert_eq!((image.width(), image.height()), (3, 2));
Source

pub const fn height(&self) -> u32

The height in pixels, after crop and scale.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

assert_eq!(decode(&file, &Config::new(ColorMode::Rgb).crop(0, 2, 8, 4))?.height(), 4);
Source

pub fn rows(&self) -> Option<Rows<'_>>

The rows of an RGB mode, top to bottom, or None for a YUV mode.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

let flipped = decode(&file, &Config::new(ColorMode::Rgba).flip(true))?;
assert_eq!(flipped.rows().unwrap().row(0), Some(&[5_u8, 6, 7, 8][..]));
assert!(decode(&file, &Config::new(ColorMode::Yuva))?.rows().is_none());
Source

pub fn planes(&self) -> Option<YuvaRows<'_>>

The planes of a YUV mode, or None for an RGB mode.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

let image = decode(&file, &Config::new(ColorMode::Yuv))?;
let planes = image.planes().unwrap();
assert_eq!(planes.y.row(0), Some(&[235_u8, 235][..])); // white, limited range
assert!(planes.a.is_none());
Source

pub fn samples(&self) -> &[u8] ⓘ

All the memory of the image: the rows of an RGB mode, or the Y, U, V and alpha planes one after the other, as libwebp lays them out.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

// 3 by 3 luma, 2 by 2 U and V, 3 by 3 alpha.
assert_eq!(decode(&file, &Config::new(ColorMode::Yuva))?.samples().len(), 9 + 4 + 4 + 9);
Source

pub fn into_samples(self) -> Vec<u8> ⓘ

The memory of the image, without a copy; see Image::samples.

§Examples
use webp::api::decode::{decode, ColorMode, Config};

assert_eq!(decode(&file, &Config::new(ColorMode::Rgba))?.into_samples(), vec![3_u8; 8]);

Trait Implementations§

Source§

impl Clone for Image

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 Debug for Image

Source§

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

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

impl Eq for Image

Source§

impl PartialEq for Image

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 Image

Auto Trait Implementations§

§

impl Forget for Image

§

impl Freeze for Image

§

impl Move for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnsafeUnpin for Image

§

impl UnwindSafe for Image

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.