[][src]Struct dither::img::Img

pub struct Img<P> { /* fields omitted */ }

A rectangular image on N pixels.

Methods

impl<P> Img<P>[src]

pub fn new(
    buf: impl IntoIterator<Item = P>,
    width: u32
) -> Option<Self>
[src]

create an Img

from a buf and width. fails if buf.len() is not an exact multiple of width.

pub const unsafe fn from_raw_buf(buf: Vec<P>, width: u32) -> Self[src]

create an Img

from a buf and length directly, skipping the bounds check.

pub fn into_vec(self) -> Vec<P>[src]

pull the buffer out of the image as a vec

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

get the width of the image

pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter[src]

returns an iterator over the pixels in the buffer

pub fn iter_mut(&mut self) -> <&mut Self as IntoIterator>::IntoIter[src]

returns an iterator that allows modifying each pixel

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

the height of the image; i.e, buf.len() / width

pub fn convert_with<Q>(
    self,
    convert: impl Fn(P) -> Q
) -> Img<Q>
[src]

map a function on P across the image buffer, converting an Img<P> to an Img<Q>

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

pub fn is_empty(&self) -> bool[src]

pub fn get(&self, (x, y): (u32, u32)) -> Option<&P>[src]

Returns a reference to an element.

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

Returns a pair (width, height).

impl<N: From<u8>> Img<RGB<N>>[src]

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>[src]

impl Img<RGB<u8>>[src]

pub fn save<P: AsRef<Path>>(self, path: P) -> Result<()>[src]

save an image as a .png or .jpg to the path. the path extension determines the image type

pub fn raw_buf(self) -> Vec<u8>[src]

the raw_buf flattens out each RGB triplet;

use dither::prelude::*;
let img: Img<RGB<u8>> = Img::new(vec![RGB(0, 1, 2), RGB(1, 1, 1)], 1).unwrap();
assert_eq!(img.raw_buf(), vec![0, 1, 2, 1, 1, 1]);

Trait Implementations

impl<P> IntoIterator for Img<P>[src]

type Item = P

The type of the elements being iterated over.

type IntoIter = IntoIter<P>

Which kind of iterator are we turning this into?

impl<'a, P> IntoIterator for &'a Img<P>[src]

type Item = &'a P

The type of the elements being iterated over.

type IntoIter = Iter<'a, P>

Which kind of iterator are we turning this into?

impl<'a, P> IntoIterator for &'a mut Img<P>[src]

type Item = &'a mut P

The type of the elements being iterated over.

type IntoIter = IterMut<'a, P>

Which kind of iterator are we turning this into?

impl<P: Clone> Clone for Img<P>[src]

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

Performs copy-assignment from source. Read more

impl<P: PartialEq> PartialEq<Img<P>> for Img<P>[src]

impl<P> Index<(u32, u32)> for Img<P>[src]

type Output = P

The returned type after indexing.

impl<P> IndexMut<(u32, u32)> for Img<P>[src]

impl<P: Debug> Debug for Img<P>[src]

Auto Trait Implementations

impl<P> Send for Img<P> where
    P: Send

impl<P> Sync for Img<P> where
    P: Sync

Blanket Implementations

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.