Type Alias RgbImage

pub type RgbImage = ImageBuffer<Rgb<u8>, Vec<u8>>;
Available on crate feature dep_image only.
Expand description

Sendable Rgb image buffer

Aliased Type§

struct RgbImage { /* private fields */ }

Implementations

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel + Send + Sync, <P as Pixel>::Subpixel: Send + Sync, Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,

pub fn par_pixels_mut(&mut self) -> PixelsMutPar<'_, P>

Returns a parallel iterator over the mutable pixels of this image, usable with rayon. See pixels_mut for more information.

pub fn par_enumerate_pixels_mut(&mut self) -> EnumeratePixelsMutPar<'_, P>

Returns a parallel iterator over the mutable pixels of this image and their coordinates, usable with rayon. See enumerate_pixels_mut for more information.

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel + Sync, <P as Pixel>::Subpixel: Sync, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

pub fn par_pixels(&self) -> PixelsPar<'_, P>

Returns a parallel iterator over the pixels of this image, usable with rayon. See pixels for more information.

pub fn par_enumerate_pixels(&self) -> EnumeratePixelsPar<'_, P>

Returns a parallel iterator over the pixels of this image and their coordinates, usable with rayon. See enumerate_pixels for more information.

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,

pub fn pixels_mut(&mut self) -> PixelsMut<'_, P>

Returns an iterator over the mutable pixels of this image.

pub fn rows_mut(&mut self) -> RowsMut<'_, P>

Returns an iterator over the mutable rows of this image.

Only non-empty rows can be iterated in this manner. In particular the iterator will not yield any item when the width of the image is 0 or a pixel type without any channels is used. This ensures that its length can always be represented by usize.

pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P>

Enumerates over the pixels of the image. The iterator yields the coordinates of each pixel along with a mutable reference to them.

pub fn enumerate_rows_mut(&mut self) -> EnumerateRowsMut<'_, P>

Enumerates over the rows of the image. The iterator yields the y-coordinate of each row along with a mutable reference to them.

pub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P

Gets a reference to the mutable pixel at location (x, y)

§Panics

Panics if (x, y) is out of the bounds (width, height).

pub fn get_pixel_mut_checked(&mut self, x: u32, y: u32) -> Option<&mut P>

Gets a reference to the mutable pixel at location (x, y) or returns None if the index is out of the bounds (width, height).

pub fn put_pixel(&mut self, x: u32, y: u32, pixel: P)

Puts a pixel at location (x, y)

§Panics

Panics if (x, y) is out of the bounds (width, height).

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

pub fn from_raw( width: u32, height: u32, buf: Container, ) -> Option<ImageBuffer<P, Container>>

Constructs a buffer from a generic container (for example a Vec or a slice)

Returns None if the container is not big enough (including when the image dimensions necessitate an allocation of more bytes than supported by the container).

pub fn into_raw(self) -> Container

Returns the underlying raw buffer

pub fn as_raw(&self) -> &Container

Returns the underlying raw buffer

pub fn dimensions(&self) -> (u32, u32)

The width and height of this image.

pub fn width(&self) -> u32

The width of this image.

pub fn height(&self) -> u32

The height of this image.

pub fn pixels(&self) -> Pixels<'_, P>

Returns an iterator over the pixels of this image. The iteration order is x = 0 to width then y = 0 to height

pub fn rows(&self) -> Rows<'_, P>

Returns an iterator over the rows of this image.

Only non-empty rows can be iterated in this manner. In particular the iterator will not yield any item when the width of the image is 0 or a pixel type without any channels is used. This ensures that its length can always be represented by usize.

pub fn enumerate_pixels(&self) -> EnumeratePixels<'_, P>

Enumerates over the pixels of the image. The iterator yields the coordinates of each pixel along with a reference to them. The iteration order is x = 0 to width then y = 0 to height Starting from the top left.

pub fn enumerate_rows(&self) -> EnumerateRows<'_, P>

Enumerates over the rows of the image. The iterator yields the y-coordinate of each row along with a reference to them.

pub fn get_pixel(&self, x: u32, y: u32) -> &P

Gets a reference to the pixel at location (x, y)

§Panics

Panics if (x, y) is out of the bounds (width, height).

pub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P>

Gets a reference to the pixel at location (x, y) or returns None if the index is out of the bounds (width, height).

pub fn sample_layout(&self) -> SampleLayout

Get the format of the buffer when viewed as a matrix of samples.

pub fn into_flat_samples(self) -> FlatSamples<Container>
where Container: AsRef<[<P as Pixel>::Subpixel]>,

Return the raw sample buffer with its stride an dimension information.

The returned buffer is guaranteed to be well formed in all cases. It is laid out by colors, width then height, meaning channel_stride <= width_stride <= height_stride. All strides are in numbers of elements but those are mostly u8 in which case the strides are also byte strides.

pub fn as_flat_samples(&self) -> FlatSamples<&[<P as Pixel>::Subpixel]>
where Container: AsRef<[<P as Pixel>::Subpixel]>,

Return a view on the raw sample buffer.

See into_flat_samples for more details.

pub fn as_flat_samples_mut( &mut self, ) -> FlatSamples<&mut [<P as Pixel>::Subpixel]>
where Container: AsMut<[<P as Pixel>::Subpixel]>,

Return a mutable view on the raw sample buffer.

See into_flat_samples for more details.

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel, [<P as Pixel>::Subpixel]: EncodableLayout, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

pub fn save<Q>(&self, path: Q) -> Result<(), ImageError>

Saves the buffer to a file at the path specified.

The image format is derived from the file extension.

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel, [<P as Pixel>::Subpixel]: EncodableLayout, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

pub fn save_with_format<Q>( &self, path: Q, format: ImageFormat, ) -> Result<(), ImageError>

Saves the buffer to a file at the specified path in the specified format.

See save_buffer_with_format for supported types.

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel, [<P as Pixel>::Subpixel]: EncodableLayout, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

pub fn write_to<W>( &self, writer: &mut W, format: ImageFormat, ) -> Result<(), ImageError>
where W: Write + Seek, P: PixelWithColorType,

Writes the buffer to a writer in the specified format.

Assumes the writer is buffered. In most cases, you should wrap your writer in a BufWriter for best performance.

§

impl<P, Container> ImageBuffer<P, Container>
where P: Pixel, [<P as Pixel>::Subpixel]: EncodableLayout, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

pub fn write_with_encoder<E>(&self, encoder: E) -> Result<(), ImageError>

Writes the buffer with the given encoder.

§

impl<P> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
where P: Pixel + Send + Sync, <P as Pixel>::Subpixel: Send + Sync,

pub fn from_par_fn<F>( width: u32, height: u32, f: F, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
where F: Fn(u32, u32) -> P + Send + Sync,

Constructs a new ImageBuffer by repeated application of the supplied function, utilizing multi-threading via rayon.

The arguments to the function are the pixel’s x and y coordinates.

§Panics

Panics when the resulting image is larger the the maximum size of a vector.

§

impl<P> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
where P: Pixel,

pub fn new( width: u32, height: u32, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>

Creates a new image buffer based on a Vec<P::Subpixel>.

all the pixels of this image have a value of zero, regardless of the data type or number of channels.

§Panics

Panics when the resulting image is larger than the maximum size of a vector.

pub fn from_pixel( width: u32, height: u32, pixel: P, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>

Constructs a new ImageBuffer by copying a pixel

§Panics

Panics when the resulting image is larger the the maximum size of a vector.

pub fn from_fn<F>( width: u32, height: u32, f: F, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
where F: FnMut(u32, u32) -> P,

Constructs a new ImageBuffer by repeated application of the supplied function.

The arguments to the function are the pixel’s x and y coordinates.

§Panics

Panics when the resulting image is larger the the maximum size of a vector.

pub fn from_vec( width: u32, height: u32, buf: Vec<<P as Pixel>::Subpixel>, ) -> Option<ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>>

Creates an image buffer out of an existing buffer. Returns None if the buffer is not big enough.

pub fn into_vec(self) -> Vec<<P as Pixel>::Subpixel>

Consumes the image buffer and returns the underlying data as an owned buffer

Trait Implementations

§

impl<P, Container> Clone for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + Clone,

§

fn clone(&self) -> ImageBuffer<P, Container>

Returns a copy of the value. Read more
§

fn clone_from(&mut self, source: &ImageBuffer<P, Container>)

Performs copy-assignment from source. Read more
§

impl<Container, FromType, ToType> ConvertBuffer<ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>> for ImageBuffer<FromType, Container>
where FromType: Pixel, ToType: Pixel + FromColor<FromType>, Container: Deref<Target = [<FromType as Pixel>::Subpixel]>,

§

fn convert(&self) -> ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>

§Examples

Convert RGB image to gray image.

use image::buffer::ConvertBuffer;
use image::GrayImage;

let image_path = "examples/fractal.png";
let image = image::open(&image_path)
    .expect("Open file failed")
    .to_rgba8();

let gray_image: GrayImage = image.convert();
§

impl<P, Container> Debug for ImageBuffer<P, Container>
where P: Debug + Pixel, Container: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<P, Container> Default for ImageBuffer<P, Container>
where P: Pixel, Container: Default,

§

fn default() -> ImageBuffer<P, Container>

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

impl<P, Container> Deref for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

§

type Target = [<P as Pixel>::Subpixel]

The resulting type after dereferencing.
§

fn deref(&self) -> &<ImageBuffer<P, Container> as Deref>::Target

Dereferences the value.
§

impl<P, Container> DerefMut for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,

§

fn deref_mut(&mut self) -> &mut <ImageBuffer<P, Container> as Deref>::Target

Mutably dereferences the value.
§

impl From<DynamicImage> for ImageBuffer<Rgb<u8>, Vec<u8>>

§

fn from(value: DynamicImage) -> ImageBuffer<Rgb<u8>, Vec<u8>>

Converts to this type from the input type.
§

impl<P, Container> GenericImage for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,

§

unsafe fn unsafe_put_pixel(&mut self, x: u32, y: u32, pixel: P)

Puts a pixel at location (x, y), ignoring bounds checking.

§

fn blend_pixel(&mut self, x: u32, y: u32, p: P)

👎Deprecated since 0.24.0: Use iterator pixels_mut to blend the pixels directly

Put a pixel at location (x, y), taking into account alpha channels

DEPRECATED: This method will be removed. Blend the pixel directly instead.

§

fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P

👎Deprecated since 0.24.0: Use get_pixel and put_pixel instead.
Gets a reference to the mutable pixel at location (x, y). Indexed from top left. Read more
§

fn put_pixel(&mut self, x: u32, y: u32, pixel: P)

Put a pixel at location (x, y). Indexed from top left. Read more
§

fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool

Copies all of the pixels from one part of this image to another part of this image. Read more
§

fn copy_from<O>(&mut self, other: &O, x: u32, y: u32) -> Result<(), ImageError>
where O: GenericImageView<Pixel = Self::Pixel>,

Copies all of the pixels from another image into this image. Read more
§

fn sub_image( &mut self, x: u32, y: u32, width: u32, height: u32, ) -> SubImage<&mut Self>
where Self: Sized,

Returns a mutable subimage that is a view into this image. If you want an immutable subimage instead, use GenericImageView::view The coordinates set the position of the top left corner of the SubImage.
§

impl<P, Container> GenericImageView for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + Deref,

§

unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P

Returns the pixel located at (x, y), ignoring bounds checking.

§

type Pixel = P

The type of pixel.
§

fn dimensions(&self) -> (u32, u32)

The width and height of this image.
§

fn get_pixel(&self, x: u32, y: u32) -> P

Returns the pixel located at (x, y). Indexed from top left. Read more
§

fn width(&self) -> u32

The width of this image.
§

fn height(&self) -> u32

The height of this image.
§

fn in_bounds(&self, x: u32, y: u32) -> bool

Returns true if this x, y coordinate is contained inside the image.
§

fn pixels(&self) -> Pixels<'_, Self>
where Self: Sized,

Returns an Iterator over the pixels of this image. The iterator yields the coordinates of each pixel along with their value
§

fn view(&self, x: u32, y: u32, width: u32, height: u32) -> SubImage<&Self>
where Self: Sized,

Returns a subimage that is an immutable view into this image. You can use GenericImage::sub_image if you need a mutable view instead. The coordinates set the position of the top left corner of the view.
§

impl<P, Container> Hash for ImageBuffer<P, Container>
where P: Hash + Pixel, Container: Hash,

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<P, Container> Index<(u32, u32)> for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

§

type Output = P

The returned type after indexing.
§

fn index(&self, _: (u32, u32)) -> &P

Performs the indexing (container[index]) operation. Read more
§

impl<P, Container> IndexMut<(u32, u32)> for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]> + DerefMut,

§

fn index_mut(&mut self, _: (u32, u32)) -> &mut P

Performs the mutable indexing (container[index]) operation. Read more
§

impl<P, Container> PartialEq for ImageBuffer<P, Container>
where P: PartialEq + Pixel, Container: PartialEq,

§

fn eq(&self, other: &ImageBuffer<P, Container>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<P, Container> Eq for ImageBuffer<P, Container>
where P: Eq + Pixel, Container: Eq,

§

impl<P, Container> StructuralPartialEq for ImageBuffer<P, Container>
where P: Pixel,