Struct dither::prelude::Img [−][src]
pub struct Img<P> { /* fields omitted */ }
Image as a flat buffer of pixels; accessible by (x, y) Index
Implementations
impl<P> Img<P>
[src]
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]
impl<N: From<u8>> Img<RGB<N>>
[src]pub fn load(path: impl AsRef<Path>) -> Result<Self>
[src]
load an image as an RGB
use dither::prelude::*; let img: Img<RGB<u8>> = Img::load("bunny.png").unwrap(); assert_eq!(img.size(), (480, 320));
impl Img<RGB<u8>>
[src]
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 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]
impl<P> IntoIterator for Img<P>
[src]impl<'a, P> IntoIterator for &'a Img<P>
[src]
impl<'a, P> IntoIterator for &'a Img<P>
[src]impl<'a, P> IntoIterator for &'a mut Img<P>
[src]
impl<'a, P> IntoIterator for &'a mut Img<P>
[src]impl<P> StructuralPartialEq for Img<P>
[src]
impl<P> StructuralPartialEq for Img<P>
[src]Auto Trait Implementations
impl<P> RefUnwindSafe for Img<P> where
P: RefUnwindSafe,
impl<P> RefUnwindSafe for Img<P> where
P: RefUnwindSafe,
impl<P> UnwindSafe for Img<P> where
P: UnwindSafe,
impl<P> UnwindSafe for Img<P> where
P: UnwindSafe,