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 /// Compatibility alias for [`Self::width`].
19 pub fn get_width(&self) -> usize {
20 self.width
21 }
22
23 /// Returns the image height in pixels.
24 pub fn height(&self) -> usize {
25 self.height
26 }
27
28 /// Compatibility alias for [`Self::height`].
29 pub fn get_height(&self) -> usize {
30 self.height
31 }
32
33 /// Returns the packed RGBA8 buffer.
34 pub fn rgba(&self) -> &[u8] {
35 &self.rgba
36 }
37
38 /// Compatibility accessor that returns a cloned RGBA buffer.
39 pub fn buffer(&self) -> Vec<u8> {
40 self.rgba.clone()
41 }
42
43 /// Consumes the image and returns the packed RGBA8 buffer.
44 pub fn into_rgba(self) -> Vec<u8> {
45 self.rgba
46 }
47}