pub trait GenericImageView {
type Pixel: Pixel;
// Required methods
fn dimensions(&self) -> (u32, u32);
fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel;
// Provided methods
fn width(&self) -> u32 { ... }
fn height(&self) -> u32 { ... }
fn in_bounds(&self, x: u32, y: u32) -> bool { ... }
unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> Self::Pixel { ... }
fn pixels(&self) -> Pixels<'_, Self> ⓘ
where Self: Sized { ... }
fn view(&self, x: u32, y: u32, width: u32, height: u32) -> SubImage<&Self>
where Self: Sized { ... }
fn try_view(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
) -> Result<SubImage<&Self>, ImageError>
where Self: Sized { ... }
fn buffer_like(
&self,
) -> ImageBuffer<Self::Pixel, Vec<<Self::Pixel as Pixel>::Subpixel>> { ... }
fn buffer_with_dimensions(
&self,
width: u32,
height: u32,
) -> ImageBuffer<Self::Pixel, Vec<<Self::Pixel as Pixel>::Subpixel>> { ... }
}
Expand description
Trait to inspect an image.
use image::{GenericImageView, Rgb, RgbImage};
let buffer = RgbImage::new(10, 10);
let image: &dyn GenericImageView<Pixel = Rgb<u8>> = &buffer;
Required Associated Types§
Required Methods§
Sourcefn dimensions(&self) -> (u32, u32)
fn dimensions(&self) -> (u32, u32)
The width and height of this image.
Provided Methods§
Sourcefn in_bounds(&self, x: u32, y: u32) -> bool
fn in_bounds(&self, x: u32, y: u32) -> bool
Returns true if this x, y coordinate is contained inside the image.
Sourceunsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> Self::Pixel
unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> Self::Pixel
Sourcefn pixels(&self) -> Pixels<'_, Self> ⓘwhere
Self: Sized,
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
Sourcefn view(&self, x: u32, y: u32, width: u32, height: u32) -> SubImage<&Self>where
Self: Sized,
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.
§Panics
Panics if the dimensions provided fall out of bounds.
Sourcefn try_view(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
) -> Result<SubImage<&Self>, ImageError>where
Self: Sized,
fn try_view(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
) -> Result<SubImage<&Self>, ImageError>where
Self: Sized,
Returns a subimage that is an immutable view into this image so long as the provided coordinates and dimensions are within the bounds of this Image.
Sourcefn buffer_like(
&self,
) -> ImageBuffer<Self::Pixel, Vec<<Self::Pixel as Pixel>::Subpixel>>
fn buffer_like( &self, ) -> ImageBuffer<Self::Pixel, Vec<<Self::Pixel as Pixel>::Subpixel>>
Create an empty ImageBuffer
with the same pixel type as this image.
This should ensure metadata such as the color space are transferred without copying any of the pixel data. The idea is to prepare a buffer ready to be filled with a filtered or portion of the channel data from the current image without performing the work of copying the data into that buffer twice.
The default implementation defers to GenericImageView::buffer_like
.
Sourcefn buffer_with_dimensions(
&self,
width: u32,
height: u32,
) -> ImageBuffer<Self::Pixel, Vec<<Self::Pixel as Pixel>::Subpixel>>
fn buffer_with_dimensions( &self, width: u32, height: u32, ) -> ImageBuffer<Self::Pixel, Vec<<Self::Pixel as Pixel>::Subpixel>>
Create an empty ImageBuffer
with different dimensions.
See GenericImageView::buffer_like
.
Uses for this are for instances preparing a buffer for only a portion of the image, or extracting the metadata to prepare a buffer of a different pixel type.