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
impl Image
Sourcepub const fn mode(&self) -> ColorMode
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);Sourcepub const fn width(&self) -> u32
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));Sourcepub const fn height(&self) -> u32
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);Sourcepub fn rows(&self) -> Option<Rows<'_>>
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());Sourcepub fn planes(&self) -> Option<YuvaRows<'_>>
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());Sourcepub fn samples(&self) -> &[u8] ⓘ
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);Sourcepub fn into_samples(self) -> Vec<u8> ⓘ
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§
impl Eq for Image
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more