Skip to main content

webp_rust/
image.rs

1/// RGBA pixel buffer for a decoded or to-be-encoded still image.
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct ImageBuffer {
4    /// Image width in pixels.
5    pub width: usize,
6    /// Image height in pixels.
7    pub height: usize,
8    /// Packed RGBA8 pixels in row-major order.
9    pub rgba: Vec<u8>,
10}
11
12impl ImageBuffer {
13    /// Returns the image width in pixels.
14    pub fn width(&self) -> usize {
15        self.width
16    }
17
18    /// Returns the image height in pixels.
19    pub fn height(&self) -> usize {
20        self.height
21    }
22
23    /// Returns the packed RGBA8 buffer.
24    pub fn rgba(&self) -> &[u8] {
25        &self.rgba
26    }
27
28    /// Consumes the image and returns the packed RGBA8 buffer.
29    pub fn into_rgba(self) -> Vec<u8> {
30        self.rgba
31    }
32}