Struct Image

Source
pub struct Image<P: Pixel, U: GenericImage<Pixel = P>> { /* private fields */ }
Expand description

Represents an image that can be passed to the merger. This is a wrapper around an image crate’s GenericImage and adds some additional functionality for the merger.

§Type Parameters

  • P - The pixel type of the underlying image.
  • U - The underlying image type.

§Example

use image_merger::{Image, Rgba};
use image::ImageBuffer;

let image: Image<Rgba<u8>, ImageBuffer<Rgba<u8>, Vec<u8>>> = Image::new(100, 100);
assert_eq!(image.capacity(), 100 * 100 * 4);

Note that this is for example, in practicality, you should use the BufferedImage type alias.

Implementations§

Source§

impl<P: Pixel, U: GenericImage<Pixel = P>> Image<P, U>

Source

pub fn capacity(&self) -> usize

Returns the capacity of the underlying image’s data buffer.

Source

pub fn into_buffer(self) -> U

Consumes the image and returns the underlying image buffer.

Source§

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

Source

pub fn new_from_raw( width: u32, height: u32, container: Container, ) -> Option<Self>

Creates a new image from a raw buffer. The buffer must be large enough to fit the image. Normally, you should use the new method to create a new image, as it is more idiomatic, unless you need to manually create an image from a raw buffer.

§Arguments
  • width - The width of the image.
  • height - The height of the image.
  • container - The raw buffer to create the image from.
§Returns

An Image with the given pixel and buffer type. Will return None if the buffer is not large enough to fit the image.

Source§

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

Source

pub fn new(width: u32, height: u32) -> Self

Creates a new image with the given width and height.

Source

pub fn new_from_pixel(width: u32, height: u32, pixel: P) -> Self

Examples found in repository?
examples/known_size_merger.rs (line 12)
10fn generate_known_image() -> BufferedImage<Rgba<u8>> {
11    // Create an image buffer with the given dimensions
12    BufferedImage::new_from_pixel(IMAGE_WIDTH, IMAGE_HEIGHT, Rgba([255, 0, 0, 255]))
13}

Trait Implementations§

Source§

impl<P: Debug + Pixel, U: Debug + GenericImage<Pixel = P>> Debug for Image<P, U>

Source§

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

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

impl<P: Pixel, U: GenericImage<Pixel = P>> Deref for Image<P, U>

Dereferences to the underlying image.

§Type Parameters

  • P - The pixel type of the underlying image.
  • U - The underlying image type.

§Example

use image_merger::{Image, Rgba, BufferedImage};
use image::ImageBuffer;

let image: BufferedImage<Rgba<u8>> = BufferedImage::new(100, 100);
let underlying: &ImageBuffer<Rgba<u8>, Vec<u8>> = &*image;
Source§

type Target = U

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<P: Pixel, U: GenericImage<Pixel = P>> DerefMut for Image<P, U>

Source§

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

Mutably dereferences the value.
Source§

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

A trait that allows the creation of an Image from a preexisting image::ImageBuffer.

§Type Parameters

  • P - The pixel type of the underlying image.
  • Container - The underlying image buffer type. This must be dereferenceable to a slice of the underlying image’s subpixels.

§Example

use image_merger::{Image, Rgba, BufferedImage};
use image::ImageBuffer;

let buf: ImageBuffer<Rgba<u8>, Vec<u8>> = ImageBuffer::new(100, 100);
let image: BufferedImage<Rgba<u8>> = BufferedImage::from(buf);
Source§

fn from(image: ImageBuffer<P, Container>) -> Self

Creates a new Image from a preexisting ImageBuffer.

§Arguments
  • image - The ImageBuffer to create an Image from.
Source§

impl<Container> FromWithFormat<Container> for Image<Luma<u16>, ImageBuffer<Luma<u16>, Vec<u16>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Luma, holding a subpixel type of u16 and an underlying ImageBuffer buffer that holds Vec<u16>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Luma<u8>, ImageBuffer<Luma<u8>, Vec<u8>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Luma, holding a subpixel type of u8 and an underlying ImageBuffer buffer that holds Vec<u8>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<LumaA<u16>, ImageBuffer<LumaA<u16>, Vec<u16>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of LumaA, holding a subpixel type of u16 and an underlying ImageBuffer buffer that holds Vec<u16>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<LumaA<u8>, ImageBuffer<LumaA<u8>, Vec<u8>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of LumaA, holding a subpixel type of u8 and an underlying ImageBuffer buffer that holds Vec<u8>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Rgb<f32>, ImageBuffer<Rgb<f32>, Vec<f32>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Rgb, holding a subpixel type of f32 and an underlying ImageBuffer buffer that holds Vec<f32>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Rgb<u16>, ImageBuffer<Rgb<u16>, Vec<u16>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Rgb, holding a subpixel type of u16 and an underlying ImageBuffer buffer that holds Vec<u16>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Rgb<u8>, ImageBuffer<Rgb<u8>, Vec<u8>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Rgb, holding a subpixel type of u8 and an underlying ImageBuffer buffer that holds Vec<u8>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Rgba<f32>, ImageBuffer<Rgba<f32>, Vec<f32>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Rgba, holding a subpixel type of f32 and an underlying ImageBuffer buffer that holds Vec<f32>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Rgba<u16>, ImageBuffer<Rgba<u16>, Vec<u16>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Rgba, holding a subpixel type of u16 and an underlying ImageBuffer buffer that holds Vec<u16>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<Container> FromWithFormat<Container> for Image<Rgba<u8>, ImageBuffer<Rgba<u8>, Vec<u8>>>
where Container: Deref<Target = [u8]>,

Implementation of FromWithFormat for an Image with a pixel type of Rgba, holding a subpixel type of u8 and an underlying ImageBuffer buffer that holds Vec<u8>’s.

Source§

fn from_with_format(container: Container, format: ImageFormat) -> Self

Transforms the given container and image format into an Image. Read more
Source§

impl<P: Hash + Pixel, U: Hash + GenericImage<Pixel = P>> Hash for Image<P, U>

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: PartialEq + Pixel, U: PartialEq + GenericImage<Pixel = P>> PartialEq for Image<P, U>

Source§

fn eq(&self, other: &Image<P, U>) -> 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.
Source§

impl<P: Eq + Pixel, U: Eq + GenericImage<Pixel = P>> Eq for Image<P, U>

Source§

impl<P: Pixel, U: GenericImage<Pixel = P>> StructuralPartialEq for Image<P, U>

Auto Trait Implementations§

§

impl<P, U> Freeze for Image<P, U>
where U: Freeze,

§

impl<P, U> RefUnwindSafe for Image<P, U>
where U: RefUnwindSafe,

§

impl<P, U> Send for Image<P, U>
where U: Send,

§

impl<P, U> Sync for Image<P, U>
where U: Sync,

§

impl<P, U> Unpin for Image<P, U>
where U: Unpin,

§

impl<P, U> UnwindSafe for Image<P, U>
where U: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.