Type Alias image::GrayImage

source ·
pub type GrayImage = ImageBuffer<Luma<u8>, Vec<u8>>;
Expand description

Sendable grayscale image buffer

Aliased Type§

struct GrayImage { /* private fields */ }

Implementations§

source§

impl GrayImage

source

pub fn expand_palette( self, palette: &[(u8, u8, u8)], transparent_idx: Option<u8>, ) -> RgbaImage

Expands a color palette by re-using the existing buffer. Assumes 8 bit per pixel. Uses an optionally transparent index to adjust it’s alpha value accordingly.

source§

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

source

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

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

See save_buffer_with_format for supported types.

source§

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

source

pub fn write_to<W, F>(&self, writer: &mut W, format: F) -> ImageResult<()>

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.

See ImageOutputFormat for supported types.

source§

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

source

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

Writes the buffer with the given encoder.

source§

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

source

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).

source

pub fn into_raw(self) -> Container

Returns the underlying raw buffer

source

pub fn as_raw(&self) -> &Container

Returns the underlying raw buffer

source

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

The width and height of this image.

source

pub fn width(&self) -> u32

The width of this image.

source

pub fn height(&self) -> u32

The height of this image.

source

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

source

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.

source

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.

source

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.

source

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).

source

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).

source

pub fn sample_layout(&self) -> SampleLayout

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

source

pub fn into_flat_samples(self) -> FlatSamples<Container>
where Container: AsRef<[P::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.

source

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

Return a view on the raw sample buffer.

See into_flat_samples for more details.

source

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

Return a mutable view on the raw sample buffer.

See into_flat_samples for more details.

source§

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

source

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

Returns an iterator over the mutable pixels of this image.

source

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.

source

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.

source

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.

source

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).

source

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).

source

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).

source§

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

source

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

Saves the buffer to a file at the path specified.

The image format is derived from the file extension.

source§

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

source

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

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

§Panics

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

source

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

Constructs a new ImageBuffer by copying a pixel

§Panics

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

source

pub fn from_fn<F>( width: u32, height: u32, f: F, ) -> ImageBuffer<P, Vec<P::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.

source

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

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

source

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

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

Trait Implementations§

source§

impl From<DynamicImage> for GrayImage

source§

fn from(value: DynamicImage) -> Self

Converts to this type from the input type.
source§

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

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

source§

fn convert(&self) -> ImageBuffer<ToType, Vec<ToType::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();
source§

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

source§

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

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Self

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

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

§

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

The resulting type after dereferencing.
source§

fn deref(&self) -> &<Self as Deref>::Target

Dereferences the value.
source§

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

source§

fn deref_mut(&mut self) -> &mut <Self as Deref>::Target

Mutably dereferences the value.
source§

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

source§

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

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

source§

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.

source§

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
source§

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

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

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
source§

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

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

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.
source§

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

source§

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.
source§

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

The width and height of this image.
source§

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

👎Deprecated: This method has inconsistent behavior between implementations (#1829). Use dimensions instead
The bounding rectangle of this image.
source§

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

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

fn width(&self) -> u32

The width of this image.
source§

fn height(&self) -> u32

The height of this image.
source§

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

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

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
source§

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.
source§

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

source§

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

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
source§

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

§

type Output = P

The returned type after indexing.
source§

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

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

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

source§

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

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

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

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

source§

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