Struct image2::Image

source ·
pub struct Image<T: Type, C: Color> {
    pub meta: Meta<T, C>,
    pub data: Box<dyn ImageData<T>>,
}
Expand description

Image type

Fields§

§meta: Meta<T, C>

Metadata

§data: Box<dyn ImageData<T>>

Pixel data

Implementations§

source§

impl<T: Type, C: Color> Image<T, C>

source

pub fn hash(&self) -> Hash

Get image hash

source§

impl<T: Type, C: Color> Image<T, C>

source

pub fn new_with_data( size: impl Into<Size>, data: impl 'static + ImageData<T> ) -> Result<Image<T, C>, Error>

Create a new image with the given size and data, returns Err if the provided ImageData isn’t big enough for the specified dimensions

source

pub fn new(size: impl Into<Size>) -> Image<T, C>

Create a new image

source

pub fn new_like(&self) -> Image<T, C>

Create a new image with the same size, type and color

source

pub fn new_like_with_type<U: Type>(&self) -> Image<U, C>

Create a new image with the same size and color as an existing image with the given type

source

pub fn new_like_with_color<D: Color>(&self) -> Image<T, D>

Create a new image with the same size and type as an existing image with the given color

source

pub fn new_like_with_type_and_color<U: Type, D: Color>(&self) -> Image<U, D>

Create a new image with the same size as an existing image with the given type and color

source

pub fn new_mmap( filename: impl AsRef<Path>, meta: Option<Meta<T, C>> ) -> Result<Image<T, C>, Error>

New memory mapped image - if meta is None then it is assumed the image already exists on disk otherwise it will be created

source

pub fn mmap(self, filename: impl AsRef<Path>) -> Result<Image<T, C>, Error>

Map an existing image to disk, this consumes the original and returns the memory mapped image

source

pub fn channels(&self) -> Channel

Returns the number of channels

source

pub fn meta(&self) -> Meta<T, C>

Get image meta

source

pub fn width(&self) -> usize

Image width

source

pub fn height(&self) -> usize

Image height

source

pub fn shape(&self) -> (usize, usize, Channel)

Returns (width, height, channels)

source

pub fn size(&self) -> Size

Get image size

source

pub fn with_color<D: Color>(self) -> Image<T, D>

Update the colorspace associated with an image without performing any conversion

source

pub fn buffer(&self) -> &[u8]

Get image data as bytes

source

pub fn buffer_mut(&mut self) -> &mut [u8]

Get image data as mutable bytes

source

pub fn get(&self, pt: impl Into<Point>) -> Data<'_, T, C>

Get data at specified index

source

pub fn get_mut(&mut self, pt: impl Into<Point>) -> DataMut<'_, T, C>

Get mutable data at specified index

source

pub fn set(&mut self, pt: impl Into<Point>, data: impl AsRef<[T]>)

Set data to specified location

source

pub fn in_bounds(&self, pt: impl Into<Point>) -> bool

Returns true when (x, y) is in bounds for the given image

source

pub fn at(&self, pt: impl Into<Point>, px: impl AsMut<[T]>) -> bool

Get image data from an image, reusing an existing data buffer big enough for a single pixel

source

pub fn pixel_at(&self, pt: impl Into<Point>, px: &mut Pixel<C>) -> bool

Load data from and Image into an existing Pixel structure

source

pub fn new_pixel(&self) -> Pixel<C>

Get an empty pixel for the image color type

source

pub fn get_pixel(&self, pt: impl Into<Point>) -> Pixel<C>

Get a normalized pixel from an image

source

pub fn set_pixel(&mut self, pt: impl Into<Point>, px: &Pixel<C>)

Set a normalized pixel to the specified location

source

pub fn get_f(&self, pt: impl Into<Point>, c: Channel) -> f64

Get a normalized float value

source

pub fn set_f(&mut self, pt: impl Into<Point>, c: Channel, f: f64)

Set normalized float value

source

pub fn row(&self, y: usize) -> Data<'_, T, C>

Get row

source

pub fn row_mut(&mut self, y: usize) -> DataMut<'_, T, C>

Get mutable row

source

pub fn rows(&self) -> impl ParallelIterator<Item = (usize, &[T])>

Iterate over image rows

source

pub fn rows_mut(&mut self) -> impl ParallelIterator<Item = (usize, &mut [T])>

Iterate over mutable image rows

source

pub fn row_range( &self, y: usize, height: usize ) -> impl ParallelIterator<Item = (usize, &[T])>

Iterate over image rows

source

pub fn row_range_mut( &mut self, y: usize, height: usize ) -> impl ParallelIterator<Item = (usize, &mut [T])>

Iterate over mutable image rows

source

pub fn open(path: impl AsRef<Path>) -> Result<Image<T, C>, Error>

Read an image from disk

source

pub fn save(&self, path: impl AsRef<Path>) -> Result<(), Error>

Write an image to disk

source

pub fn iter_region_mut( &mut self, roi: Region ) -> impl ParallelIterator<Item = (Point, DataMut<'_, T, C>)>

Iterate over part of an image with mutable data access

source

pub fn iter_region( &self, roi: Region ) -> impl ParallelIterator<Item = (Point, Data<'_, T, C>)>

Iterate over part of an image

source

pub fn iter(&self) -> impl ParallelIterator<Item = (Point, Data<'_, T, C>)>

Get pixel iterator

source

pub fn iter_mut( &mut self ) -> impl ParallelIterator<Item = (Point, DataMut<'_, T, C>)>

Get mutable pixel iterator

source

pub fn for_each<F: Sync + Send + Fn(Point, DataMut<'_, T, C>)>(&mut self, f: F)

Iterate over each pixel applying f to every pixel

source

pub fn for_each_region<F: Sync + Send + Fn(Point, DataMut<'_, T, C>)>( &mut self, roi: Region, f: F )

Iterate over a region of pixels qpplying f to every pixel

source

pub fn for_each2<F: Sync + Send + Fn(Point, DataMut<'_, T, C>, Data<'_, T, C>)>( &mut self, other: &Image<T, C>, f: F )

Iterate over each pixel of two images at once

source

pub fn each_pixel<F: Sync + Send + FnMut(Point, &Pixel<C>)>(&self, f: F)

Iterate over pixels, with a mutable closure

source

pub fn each_pixel_region<F: Sync + Send + FnMut(Point, &Pixel<C>)>( &self, region: Region, f: F )

Iterate over pixels in region, with a mutable closure

source

pub fn each_pixel_mut<F: Sync + Send + FnMut(Point, &mut Pixel<C>)>( &mut self, f: F )

Iterate over mutable pixels, with a mutable closure

source

pub fn each_pixel_region_mut<F: Sync + Send + FnMut(Point, &mut Pixel<C>)>( &mut self, region: Region, f: F )

Iterate over mutable pixels in region, with a mutable closure

source

pub fn crop(&self, roi: Region) -> Image<T, C>

Copy a region of an image to a new image

source

pub fn copy_from_region( &mut self, offs: impl Into<Point>, other: &Image<T, C>, roi: Region )

Copy into a region from another image starting at the given offset

source

pub fn apply<U: Type, D: Color>( &mut self, filter: impl Filter<U, D, T, C>, input: &[&Image<U, D>] ) -> &mut Self

Apply a filter using an Image as output

source

pub async fn apply_async<'a, U: Type, D: Color>( &mut self, mode: AsyncMode, filter: impl Filter<U, D, T, C> + Unpin, input: &[&Image<U, D>] ) -> &mut Self

Apply an async filter using an Image as output

source

pub fn run_in_place(&mut self, filter: impl Filter<T, C>) -> &mut Self

Run a filter using the same Image as input and output

source

pub fn run<U: Type, D: Color>( &self, filter: impl Filter<T, C, U, D>, output: Option<Meta<U, D>> ) -> Image<U, D>

Run a filter using an Image as input

source

pub async fn run_async<'a, U: 'a + Type, D: 'a + Color>( &self, mode: AsyncMode, filter: impl Filter<T, C, U, D> + Unpin, output: Option<Meta<U, D>> ) -> Image<U, D>

Run an async filter using an Image as input

source

pub fn convert<U: Type, D: Color>(&self) -> Image<U, D>

Convert image type/color

source

pub fn convert_to<U: Type, D: Color>(&self, dest: &mut Image<U, D>)

Convert image type/color

source

pub fn histogram(&self, bins: usize) -> Vec<Histogram>

Get image histogram

source

pub fn gamma(&mut self, value: f64)

Gamma correction

source

pub fn set_gamma_log(&mut self)

Convert to log RGB

source

pub fn set_gamma_lin(&mut self)

Convert to linear RGB

source

pub fn resize(&self, size: impl Into<Size>) -> Image<T, C>

Resize an image

source

pub fn scale(&self, width: f64, height: f64) -> Image<T, C>

Scale an image

source

pub fn data(&self) -> &[T]

Image data

source

pub fn data_mut(&mut self) -> &mut [T]

Mutable image data

source§

impl<T: Type, C: Color> Image<T, C>

source

pub fn draw_text<'a>( &mut self, text: impl AsRef<str>, font: &Font<'a>, size: f32, pos: impl Into<Point>, color: &Pixel<C> )

Draw text on image

Trait Implementations§

source§

impl<T: Type, C: Color> Clone for Image<T, C>

source§

fn clone(&self) -> Self

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<X: Into<Point>, T: Type, C: Color> Index<X> for Image<T, C>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, pt: X) -> &Self::Output

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

impl<X: Into<Point>, T: Type, C: Color> IndexMut<X> for Image<T, C>

source§

fn index_mut(&mut self, pt: X) -> &mut Self::Output

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

impl<T: Type, C: Color> PartialEq<Image<T, C>> for Image<T, C>

source§

fn eq(&self, other: &Self) -> 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 ToTexture<f32, Rgb> for Image<f32, Rgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_126u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<f32, Rgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<f32, Rgba> for Image<f32, Rgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_126u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<f32, Rgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<f32, Srgb> for Image<f32, Srgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_126u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<f32, Srgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<f32, Srgba> for Image<f32, Srgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_126u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<f32, Srgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<i16, Rgb> for Image<i16, Rgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_122u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<i16, Rgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<i16, Rgba> for Image<i16, Rgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_122u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<i16, Rgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<i16, Srgb> for Image<i16, Srgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_122u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<i16, Srgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<i16, Srgba> for Image<i16, Srgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_122u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<i16, Srgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u16, Rgb> for Image<u16, Rgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_123u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u16, Rgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u16, Rgba> for Image<u16, Rgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_123u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u16, Rgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u16, Srgb> for Image<u16, Srgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_123u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u16, Srgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u16, Srgba> for Image<u16, Srgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_123u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u16, Srgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u8, Rgb> for Image<u8, Rgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_121u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u8, Rgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u8, Rgba> for Image<u8, Rgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_121u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u8, Rgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u8, Srgb> for Image<u8, Srgb>

source§

const COLOR: u32 = 6_407u32

OpenGL color
source§

const KIND: u32 = 5_121u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u8, Srgb>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer
source§

impl ToTexture<u8, Srgba> for Image<u8, Srgba>

source§

const COLOR: u32 = 6_408u32

OpenGL color
source§

const KIND: u32 = 5_121u32

OpenGL type
source§

fn get_meta(&self) -> &Meta<u8, Srgba>

Get metadata
source§

fn get_data(&self) -> &[u8]

Get data buffer
source§

fn internal(&self) -> Result<u32, Error>

Get internal color type
source§

fn create_image_texture(&self, gl: &Context) -> Result<ImageTexture<T, C>, Error>

Create ImageTexture
source§

fn draw_image_texture( &self, gl: &Context, image_texture: &ImageTexture<T, C>, display_size: Size, offset: Point ) -> Result<(), Error>

Draw the texture on the framebuffer

Auto Trait Implementations§

§

impl<T, C> !RefUnwindSafe for Image<T, C>

§

impl<T, C> Send for Image<T, C>

§

impl<T, C> Sync for Image<T, C>

§

impl<T, C> Unpin for Image<T, C>

§

impl<T, C> !UnwindSafe for Image<T, C>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.