[][src]Struct pix::Raster

pub struct Raster<F: PixFmt> { /* fields omitted */ }

A 2D raster image.

Example

use pix::{Alpha, Cu8, Raster, Rgba};
let mut raster: Raster<Rgba<Cu8>> = Raster::new(10, 10);
let mut matte: Raster<Alpha<Cu8>> = Raster::new(10, 10);
let rgba = Rgba::new(128, 208, 208, 200);
matte.set_pixel(2, 4, Alpha::new(255));
matte.set_pixel(2, 5, Alpha::new(128));
raster.mask_over(&matte, 0, 0, rgba);
let p = raster.as_u8_slice();
// work with pixel data...

Methods

impl<F: PixFmt> Raster<F>[src]

pub fn new(width: u32, height: u32) -> Raster<F>[src]

Create a new raster image.

  • F Pixel format.
  • width Width in pixels.
  • height Height in pixels.

pub fn with_pixels<T: Into<Box<[F]>>>(
    width: u32,
    height: u32,
    pixels: T
) -> Raster<F>
[src]

Create a new raster image with owned pixel data. You can get ownership of the pixel data back from the Raster as either a Vec<F> or a Box<[F]> by calling into().

  • F Pixel format.
  • width Width in pixels.
  • height Height in pixels.
  • pixels Pixel data.

Panics

Panics if pixels length is not equal to width * height.

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

Get raster width.

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

Get raster height.

pub fn pixel(&self, x: u32, y: u32) -> F[src]

Get one pixel value.

pub fn set_pixel(&mut self, x: u32, y: u32, p: F)[src]

Set one pixel value.

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

Get the pixels as a slice.

pub fn as_slice_mut(&mut self) -> &mut [F][src]

Get the pixels as a mutable slice.

pub fn as_u8_slice(&self) -> &[u8][src]

Get the pixels as a u8 slice.

pub fn as_u8_slice_mut(&mut self) -> &mut [u8][src]

Get the pixels as a mutable u8 slice.

pub fn clear(&mut self)[src]

Clear all pixels.

pub fn set_rect(&mut self, x: u32, y: u32, w: u32, h: u32, clr: F)[src]

Set a rectangle to specified color.

  • x Left position of rectangle.
  • y Top position of rectangle.
  • w Width of rectangle.
  • h Height of rectangle.
  • clr Color to set.

pub fn mask_over(&mut self, mask: &Raster<Alpha<Cu8>>, x: i32, y: i32, clr: F)[src]

Blend pixels with an alpha mask.

  • mask Alpha mask for compositing.
  • x Left position of alpha mask.
  • y Top position of alpha mask.
  • clr Color to composite.

Trait Implementations

impl<F: PixFmt> Into<Box<[F]>> for Raster<F>[src]

fn into(self) -> Box<[F]>[src]

Get internal pixel data as boxed slice.

impl<F: PixFmt> Into<Vec<F>> for Raster<F>[src]

fn into(self) -> Vec<F>[src]

Get internal pixel data as Vec of pixels.

impl<F: Clone + PixFmt> Clone for Raster<F>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<F: Debug + PixFmt> Debug for Raster<F>[src]

Auto Trait Implementations

impl<F> Send for Raster<F> where
    F: Send

impl<F> Sync for Raster<F> where
    F: Sync

Blanket Implementations

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

impl<T> From for T[src]

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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