#[non_exhaustive]
pub enum DynamicImage {
    ImageLuma8(GrayImage),
    ImageLumaA8(GrayAlphaImage),
    ImageRgb8(RgbImage),
    ImageRgba8(RgbaImage),
    ImageLuma16(ImageBuffer<Luma<u16>, Vec<u16>>),
    ImageLumaA16(ImageBuffer<LumaA<u16>, Vec<u16>>),
    ImageRgb16(ImageBuffer<Rgb<u16>, Vec<u16>>),
    ImageRgba16(ImageBuffer<Rgba<u16>, Vec<u16>>),
    ImageRgb32F(Rgb32FImage),
    ImageRgba32F(Rgba32FImage),
}
Expand description

A Dynamic Image

This represents a matrix of pixels which are convertible from and to an RGBA representation. More variants that adhere to these principles may get added in the future, in particular to cover other combinations typically used.

Usage

This type can act as a converter between specific ImageBuffer instances.

use image::{DynamicImage, GrayImage, RgbImage};

let rgb: RgbImage = RgbImage::new(10, 10);
let luma: GrayImage = DynamicImage::ImageRgb8(rgb).into_luma8();

Design

There is no goal to provide an all-encompassing type with all possible memory layouts. This would hardly be feasible as a simple enum, due to the sheer number of combinations of channel kinds, channel order, and bit depth. Rather, this type provides an opinionated selection with normalized channel order which can store common pixel values without loss.

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

ImageLuma8(GrayImage)

Each pixel in this image is 8-bit Luma

ImageLumaA8(GrayAlphaImage)

Each pixel in this image is 8-bit Luma with alpha

ImageRgb8(RgbImage)

Each pixel in this image is 8-bit Rgb

ImageRgba8(RgbaImage)

Each pixel in this image is 8-bit Rgb with alpha

ImageLuma16(ImageBuffer<Luma<u16>, Vec<u16>>)

Each pixel in this image is 16-bit Luma

ImageLumaA16(ImageBuffer<LumaA<u16>, Vec<u16>>)

Each pixel in this image is 16-bit Luma with alpha

ImageRgb16(ImageBuffer<Rgb<u16>, Vec<u16>>)

Each pixel in this image is 16-bit Rgb

ImageRgba16(ImageBuffer<Rgba<u16>, Vec<u16>>)

Each pixel in this image is 16-bit Rgb with alpha

ImageRgb32F(Rgb32FImage)

Each pixel in this image is 32-bit float Rgb

ImageRgba32F(Rgba32FImage)

Each pixel in this image is 32-bit float Rgb with alpha

Implementations

Creates a dynamic image backed by a buffer of gray pixels.

Creates a dynamic image backed by a buffer of gray pixels with transparency.

Creates a dynamic image backed by a buffer of RGB pixels.

Creates a dynamic image backed by a buffer of RGBA pixels.

Creates a dynamic image backed by a buffer of gray pixels.

Creates a dynamic image backed by a buffer of gray pixels with transparency.

Creates a dynamic image backed by a buffer of RGB pixels.

Creates a dynamic image backed by a buffer of RGBA pixels.

Creates a dynamic image backed by a buffer of RGB pixels.

Creates a dynamic image backed by a buffer of RGBA pixels.

Decodes an encoded image into a dynamic image.

Returns a copy of this image as an RGB image.

Returns a copy of this image as an RGB image.

Returns a copy of this image as an RGB image.

Returns a copy of this image as an RGBA image.

Returns a copy of this image as an RGBA image.

Returns a copy of this image as an RGBA image.

Returns a copy of this image as a Luma image.

Returns a copy of this image as a Luma image.

Returns a copy of this image as a Luma image.

Returns a copy of this image as a LumaA image.

Returns a copy of this image as a LumaA image.

Returns a copy of this image as a LumaA image.

Consume the image and returns a RGB image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a RGB image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a RGB image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a RGBA image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a RGBA image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a RGBA image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a Luma image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a Luma image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a LumaA image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Consume the image and returns a LumaA image.

If the image was already the correct format, it is returned as is. Otherwise, a copy is created.

Return a cut-out of this image delimited by the bounding rectangle.

Note: this method does not modify the object, and its signature will be replaced with crop_imm()’s in the 0.24 release

Return a cut-out of this image delimited by the bounding rectangle.

Return a reference to an 8bit RGB image

Return a mutable reference to an 8bit RGB image

Return a reference to an 8bit RGBA image

Return a mutable reference to an 8bit RGBA image

Return a reference to an 8bit Grayscale image

Return a mutable reference to an 8bit Grayscale image

Return a reference to an 8bit Grayscale image with an alpha channel

Return a mutable reference to an 8bit Grayscale image with an alpha channel

Return a reference to an 16bit RGB image

Return a mutable reference to an 16bit RGB image

Return a reference to an 16bit RGBA image

Return a mutable reference to an 16bit RGBA image

Return a reference to an 16bit RGB image

Return a mutable reference to an 32bit RGB image

Return a reference to an 32bit RGBA image

Return a mutable reference to an 16bit RGBA image

Return a reference to an 16bit Grayscale image

Return a mutable reference to an 16bit Grayscale image

Return a reference to an 16bit Grayscale image with an alpha channel

Return a mutable reference to an 16bit Grayscale image with an alpha channel

Return a view on the raw sample buffer for 8 bit per channel images.

Return a view on the raw sample buffer for 16 bit per channel images.

Return a view on the raw sample buffer for 32bit per channel images.

Return this image’s pixels as a native endian byte slice.

Return this image’s pixels as a byte vector. If the ImageBuffer container is Vec<u8>, this operation is free. Otherwise, a copy is returned.

👎Deprecated since 0.24.0: use image.into_bytes() or image.as_bytes().to_vec() instead

Return a copy of this image’s pixels as a byte vector. Deprecated, because it does nothing but hide an expensive clone operation.

Return this image’s color type.

Returns the width of the underlying image

Returns the height of the underlying image

Return a grayscale version of this image. Returns Luma images in most cases. However, for f32 images, this will return a grayscale Rgb/Rgba image instead.

Invert the colors of this image. This method operates inplace.

Resize this image using the specified filter algorithm. Returns a new image. The image’s aspect ratio is preserved. The image is scaled to the maximum possible size that fits within the bounds specified by nwidth and nheight.

Resize this image using the specified filter algorithm. Returns a new image. Does not preserve aspect ratio. nwidth and nheight are the new image’s dimensions

Scale this image down to fit within a specific size. Returns a new image. The image’s aspect ratio is preserved. The image is scaled to the maximum possible size that fits within the bounds specified by nwidth and nheight.

This method uses a fast integer algorithm where each source pixel contributes to exactly one target pixel. May give aliasing artifacts if new size is close to old size.

Scale this image down to a specific size. Returns a new image. Does not preserve aspect ratio. nwidth and nheight are the new image’s dimensions. This method uses a fast integer algorithm where each source pixel contributes to exactly one target pixel. May give aliasing artifacts if new size is close to old size.

Resize this image using the specified filter algorithm. Returns a new image. The image’s aspect ratio is preserved. The image is scaled to the maximum possible size that fits within the larger (relative to aspect ratio) of the bounds specified by nwidth and nheight, then cropped to fit within the other bound.

Performs a Gaussian blur on this image. sigma is a measure of how much to blur by.

Performs an unsharpen mask on this image. sigma is the amount to blur the image by. threshold is a control of how much to sharpen.

See https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking

Filters this image with the specified 3x3 kernel.

Adjust the contrast of this image. contrast is the amount to adjust the contrast by. Negative values decrease the contrast and positive values increase the contrast.

Brighten the pixels of this image. value is the amount to brighten each pixel by. Negative values decrease the brightness and positive values increase it.

Hue rotate the supplied image. value is the degrees to rotate each pixel by. 0 and 360 do nothing, the rest rotates by the given degree value. just like the css webkit filter hue-rotate(180)

Flip this image vertically

Flip this image horizontally

Rotate this image 90 degrees clockwise.

Rotate this image 180 degrees clockwise.

Rotate this image 270 degrees clockwise.

Encode this image and write it to w.

Assumes the writer is buffered. In most cases, you should wrap your writer in a BufWriter for best performance.

Saves the buffer to a file at the path specified.

The image format is derived from the file extension.

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

See save_buffer_with_format for supported types.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
👎Deprecated since 0.24.0: Use get_pixel and put_pixel instead.

Do not use is function: It is unimplemented!

Put a pixel at location (x, y). Indexed from top left. Read more
👎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
Puts a pixel at location (x, y). Indexed from top left. Read more
Copies all of the pixels from another image into this image. Read more
Copies all of the pixels from one part of this image to another part of this image. Read more
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. Read more
The type of pixel.
The width and height of this image.
The bounding rectangle of this image.
Returns the pixel located at (x, y). Indexed from top left. Read more
The width of this image.
The height of this image.
Returns true if this x, y coordinate is contained inside the image.
Returns the pixel located at (x, y). Indexed from top left. Read more
Returns an Iterator over the pixels of this image. The iterator yields the coordinates of each pixel along with their value Read more
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. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.