Struct Pixmap

Source
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

Source

pub fn new(width: u16, height: u16) -> Self

Create a new pixmap with the given width and height in pixels.

Source

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.

Source

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.

Source

pub fn shrink_to_fit(&mut self)

Shrink the capacity of the pixmap buffer to fit the pixmap’s current size.

Source

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.

Source

pub fn width(&self) -> u16

Return the width of the pixmap.

Source

pub fn height(&self) -> u16

Return the height of the pixmap.

Source

pub fn multiply_alpha(&mut self, alpha: u8)

Apply an alpha value to the whole pixmap.

Source

pub fn from_png(data: impl Read) -> Result<Self, DecodingError>

Create a pixmap from a PNG file.

Source

pub fn into_png(self) -> Result<Vec<u8>, EncodingError>

Return the current content of the pixmap as a PNG.

Source

pub fn data(&self) -> &[PremulRgba8]

Returns a reference to the underlying data as premultiplied RGBA8.

The pixels are in row-major order.

Source

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.

Source

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].

Source

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].

Source

pub fn sample(&self, x: u16, y: u16) -> PremulRgba8

Sample a pixel from the pixmap.

The pixel data is premultiplied RGBA8.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Pixmap

Source§

fn clone(&self) -> Pixmap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pixmap

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Pixmap

§

impl RefUnwindSafe for Pixmap

§

impl Send for Pixmap

§

impl Sync for Pixmap

§

impl Unpin for Pixmap

§

impl UnwindSafe for Pixmap

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.