ImageBuf

Type Alias ImageBuf 

Source
pub type ImageBuf<Color> = Image<Color, Vec<Color>>;
Expand description

An owned image buffer backed by a Vec.

This type consists of a width, a height, and a pixel buffer in row-major order. The length of the pixel Vec is guaranteed to match width * height and be less than or equal to MAX_PIXELS.

See ImageRef and ImageMut for borrowed variants of an image. Use as_ref or as_mut to create a borrowed image.

§Examples

Directly creating an ImageBuf from a Vec:

let (width, height) = (512, 512);
let pixels = vec![Srgb::new(0, 0, 0); (width * height) as usize];
let image = ImageBuf::new(width, height, pixels)?;

Converting a RgbImage from the image crate to an ImageBuf and vice versa:

let image = RgbImage::new(256, 256);
let image = ImageBuf::try_from(image)?;
let image: RgbImage = image.into();

Aliased Type§

pub struct ImageBuf<Color> { /* private fields */ }

Implementations§

Source§

impl<Color: Zeroable> ImageBuf<Color>

Source

pub fn zeroed(width: u32, height: u32) -> Option<Self>

Create a new ImageBuf from zeroed memory.

Returns None if width * height overflows a u32.

Source§

impl<Color: Clone> ImageBuf<Color>

Source

pub fn from_pixel(width: u32, height: u32, pixel: Color) -> Option<Self>

Create a new ImageBuf by cloning a specific color.

Returns None if width * height overflows a u32.

Trait Implementations§

Source§

impl<Color> Default for ImageBuf<Color>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Component> TryFrom<ImageBuffer<Rgb<Component>, Vec<Component>>> for ImageBuf<Srgb<Component>>
where Srgb<Component>: ArrayCast, <Srgb<Component> as ArrayCast>::Array: ArrayExt<Item = Component>, Rgb<Component>: Pixel<Subpixel = Component>, Vec<Component>: Deref<Target = [<Rgb<Component> as Pixel>::Subpixel]>,

Source§

type Error = CreateImageBufError<ImageBuffer<Rgb<Component>, Vec<Component>>>

The type returned in the event of a conversion error.
Source§

fn try_from( image: ImageBuffer<Rgb<Component>, Vec<Component>>, ) -> Result<Self, Self::Error>

Performs the conversion.