pub struct Pixmap {
width: u16,
height: u16,
buf: Vec<PremulRgba8>,
}
Expand description
A pixmap of premultiplied RGBA8 values backed by u8
.
Fields§
§width: u16
Width of the pixmap in pixels.
height: u16
Height of the pixmap in pixels.
buf: Vec<PremulRgba8>
Buffer of the pixmap in RGBA8 format.
Implementations§
Source§impl Pixmap
impl Pixmap
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Create a new pixmap with the given width and height in pixels.
Sourcepub fn from_parts(data: Vec<PremulRgba8>, width: u16, height: u16) -> Self
pub fn from_parts(data: Vec<PremulRgba8>, width: u16, height: u16) -> Self
Create a new pixmap with the given premultiplied RGBA8 data.
The data
vector must be of length width * height
exactly.
The pixels are in row-major order.
§Panics
Panics if the data
vector is not of length width * height
.
Sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resizes the pixmap container to the given width and height; this does not resize the contained image.
If the pixmap buffer has to grow to fit the new size, those pixels are set to transparent black. If the pixmap buffer is larger than required, the buffer is truncated and its reserved capacity is unchanged.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the capacity of the pixmap buffer to fit the pixmap’s current size.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
The reserved capacity (in pixels) of this pixmap.
When calling Pixmap::resize
with a width * height
smaller than this value, the pixmap
does not need to reallocate.
Sourcepub fn multiply_alpha(&mut self, alpha: u8)
pub fn multiply_alpha(&mut self, alpha: u8)
Apply an alpha value to the whole pixmap.
Sourcepub fn from_png(data: impl Read) -> Result<Self, DecodingError>
pub fn from_png(data: impl Read) -> Result<Self, DecodingError>
Create a pixmap from a PNG file.
Sourcepub fn into_png(self) -> Result<Vec<u8>, EncodingError>
pub fn into_png(self) -> Result<Vec<u8>, EncodingError>
Return the current content of the pixmap as a PNG.
Sourcepub fn data(&self) -> &[PremulRgba8]
pub fn data(&self) -> &[PremulRgba8]
Returns a reference to the underlying data as premultiplied RGBA8.
The pixels are in row-major order.
Sourcepub fn data_mut(&mut self) -> &mut [PremulRgba8]
pub fn data_mut(&mut self) -> &mut [PremulRgba8]
Returns a mutable reference to the underlying data as premultiplied RGBA8.
The pixels are in row-major order.
Sourcepub fn data_as_u8_slice(&self) -> &[u8] ⓘ
pub fn data_as_u8_slice(&self) -> &[u8] ⓘ
Returns a reference to the underlying data as premultiplied RGBA8.
The pixels are in row-major order. Each pixel consists of four bytes in the order
[r, g, b, a]
.
Sourcepub fn data_as_u8_slice_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_as_u8_slice_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the underlying data as premultiplied RGBA8.
The pixels are in row-major order. Each pixel consists of four bytes in the order
[r, g, b, a]
.
Sourcepub fn sample(&self, x: u16, y: u16) -> PremulRgba8
pub fn sample(&self, x: u16, y: u16) -> PremulRgba8
Sample a pixel from the pixmap.
The pixel data is premultiplied RGBA8.
Sourcepub fn sample_idx(&self, idx: u32) -> PremulRgba8
pub fn sample_idx(&self, idx: u32) -> PremulRgba8
Sample a pixel from a custom-calculated index. This index should be calculated assuming that the data is stored in row-major order.
Sourcepub fn take(self) -> Vec<PremulRgba8>
pub fn take(self) -> Vec<PremulRgba8>
Consume the pixmap, returning the data as the underlying Vec
of premultiplied RGBA8.
The pixels are in row-major order.
Sourcepub fn take_unpremultiplied(self) -> Vec<Rgba8>
pub fn take_unpremultiplied(self) -> Vec<Rgba8>
Consume the pixmap, returning the data as (unpremultiplied) RGBA8.
Not fast, but useful for saving to PNG etc.
The pixels are in row-major order.