pub trait GenericImageView {
    type Pixel: Pixel;
    type InnerImageView: GenericImageView<Pixel = Self::Pixel>;

    // Required methods
    fn dimensions(&self) -> (u32, u32);
    fn bounds(&self) -> (u32, u32, u32, u32);
    fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel;
    fn inner(&self) -> &Self::InnerImageView;

    // 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>  { ... }
    fn view(
        &self,
        x: u32,
        y: u32,
        width: u32,
        height: u32
    ) -> SubImage<&Self::InnerImageView> { ... }
}
Expand description

Trait to inspect an image.

Required Associated Types§

source

type Pixel: Pixel

The type of pixel.

source

type InnerImageView: GenericImageView<Pixel = Self::Pixel>

Underlying image type. This is mainly used by SubImages in order to always have a reference to the original image. This allows for less indirections and it eases the use of nested SubImages.

Required Methods§

source

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

The width and height of this image.

source

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

The bounding rectangle of this image.

source

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

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

Panics

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

TODO: change this signature to &P

source

fn inner(&self) -> &Self::InnerImageView

Returns a reference to the underlying image.

Provided Methods§

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

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

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

This function can be implemented in a way that ignores bounds checking.

Safety

The coordinates must be in_bounds of the image.

source

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

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::InnerImageView>

Returns an 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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl GenericImageView for DynamicImage

source§

impl<Buffer, P> GenericImageView for View<Buffer, P>
where P: Pixel, Buffer: AsRef<[<P as Pixel>::Subpixel]>,

§

type Pixel = P

§

type InnerImageView = View<Buffer, P>

source§

impl<Buffer, P> GenericImageView for ViewMut<Buffer, P>
where P: Pixel, Buffer: AsMut<[<P as Pixel>::Subpixel]> + AsRef<[<P as Pixel>::Subpixel]>,

§

type Pixel = P

§

type InnerImageView = ViewMut<Buffer, P>

source§

impl<I> GenericImageView for SubImage<I>
where I: Deref, <I as Deref>::Target: GenericImageView + Sized,

source§

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

§

type Pixel = P

§

type InnerImageView = ImageBuffer<P, Container>