[][src]Struct pel::RawSurface

pub struct RawSurface<I> { /* fields omitted */ }

Raw, generic surface used by pel.

Methods

impl<I> RawSurface<I> where
    I: Default + Copy
[src]

pub fn new(w: usize, h: usize) -> Self[src]

Surface constructor.

pub fn width(&self) -> usize[src]

Surface width.

pub fn height(&self) -> usize[src]

Surface height.

pub fn size(&self) -> (usize, usize)[src]

Surface size as a (width, height) tuple.

pub fn into_raw_parts(self) -> (Vec<I>, usize, usize)[src]

Decomposes surface into its raw components.

  • buf - a vector of BGRA bytes;
  • w - surface width in pels;
  • h - surface height in pels.

pub fn from_raw_parts(buf: Vec<I>, w: usize, h: usize) -> Self[src]

Creates surface directly from the raw components of another surface.

Panics

If buf.len() isn't equal to w * h.

pub unsafe fn from_raw_parts_unchecked(buf: Vec<I>, w: usize, h: usize) -> Self[src]

Creates surface directly from the raw components of another surface without checking if buffer size is correct.

Safety

If buf.len() isn't equal to w * h, undefined behaviour may be invoked by later operations on this surface.

pub fn as_ptr(&self) -> *const I[src]

Returns a raw pointer to the surface's internal buffer.

The caller must ensure that the surface outlives the pointer this function returns, or else it will end up pointing to garbage. The caller must also ensure that the memory the pointer (non-transitively) points to is never written to (except inside an UnsafeCell) using this pointer or any pointer derived from it.

pub fn as_mut_ptr(&mut self) -> *mut I[src]

Returns an unsafe mutable pointer to the surface's internal buffer.

The caller must ensure that the surface outlives the pointer this function returns, or else it will end up pointing to garbage.

pub fn as_slice(&self) -> &[I][src]

Extracts a slice referencing entire underlying buffer.

pub fn as_mut_slice(&mut self) -> &mut [I][src]

Extracts a mutable slice referencing entire underlying buffer.

pub fn clear<O: Into<I>>(&mut self, value: O)[src]

Clears entire surface with pel value.

pub fn for_each<F, O>(&mut self, f: F) where
    F: Fn(O) -> O,
    O: From<I> + Into<I>, 
[src]

Transforms all pels using given function.

pub fn read<O: From<I>>(&self, x: usize, y: usize) -> Result<O>[src]

Reads pel value.

Errors

If indices are out of surface bounds, Error::OutOfBounds is returned.

pub fn write<O: Into<I>>(&mut self, x: usize, y: usize, value: O) -> Result<()>[src]

Writes pel value.

Errors

If indices are out of surface bounds, Error::OutOfBounds is returned.

pub unsafe fn read_unchecked<O: From<I>>(&self, x: usize, y: usize) -> O[src]

Reads pel value.

Safety

It is undefined behaviour to provide indices that are out of surface bounds.

pub unsafe fn write_unchecked<O: Into<I>>(
    &mut self,
    x: usize,
    y: usize,
    value: O
)
[src]

Writes pel value.

Safety

It is undefined behaviour to provide indices that are out of surface bounds.

pub fn index(&self, x: usize, y: usize) -> Result<usize>[src]

Calculates index of a pel at (x, y) of this surface.

(0, 0) is top left of the surface.

Errors

If indices are out of surface bounds, Error::OutOfBounds is returned.

pub fn index_unchecked(&self, x: usize, y: usize) -> usize[src]

Calculates index of a pel at (x, y) of this surface.

(0, 0) is top left of the surface.

This function doesn't check if index is in bounds, but is still safe.

Trait Implementations

impl<I: Clone> Clone for RawSurface<I>[src]

Auto Trait Implementations

impl<I> RefUnwindSafe for RawSurface<I> where
    I: RefUnwindSafe

impl<I> Send for RawSurface<I> where
    I: Send

impl<I> Sync for RawSurface<I> where
    I: Sync

impl<I> Unpin for RawSurface<I> where
    I: Unpin

impl<I> UnwindSafe for RawSurface<I> where
    I: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.