[][src]Struct eimg::Img

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

Image as a flat buffer of pixels; accessible by (x, y) Index

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() % buf.width() != 0

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.

assert_eq!(
    unsafe{Img::from_raw_buf(vec![2, 4, 6, 8], 2)},
    Img::new(vec![2, 4, 6, 8], 2).unwrap()
);

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

pull the buffer out of the image as a vec.

assert_eq!(Img::new(1..=4, 2).unwrap().into_vec(), vec![1, 2, 3, 4]);

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

get the width of the image.

assert_eq!(Img::new(0..12, 3).unwrap().width(), 3);

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

assert_eq!(Img::new(0..12, 3).unwrap().height(), 4);

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>

let img: Img<u8> = Img::new(1..=4, 2).unwrap();
let doubled: Img<u16> = Img::new(vec![2, 4, 6, 8], 2).unwrap();
assert_eq!(img.convert_with(|x| u16::from(x*2)), doubled);

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

the length of the image, in pixels. equal to Img::width()*Img::height()

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(path: impl AsRef<Path>) -> Result<Self>[src]

load an image as an RGB after converting it. See image::open and image::DynamicImage::to_rgb

use eimg::*;
let img: Img<RGB<u8>> = Img::load("bunny.png").unwrap();
assert_eq!(img.size(), (480, 320));

impl Img<RGB<u8>>[src]

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

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

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

the raw_buf flattens out each RGB triplet;

use eimg::*;
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: PartialEq> PartialEq<Img<P>> for Img<P>[src]

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> 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: Debug> Debug 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]

Auto Trait Implementations

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

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

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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<U> for T where
    U: From<T>, 
[src]

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.

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

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

impl<T> Any for T where
    T: 'static + ?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.