Crate image
Overview
This crate provides native rust implementations of image encoding and decoding as well as some basic image manipulation functions. Additional documentation can currently also be found in the README.md file which is most easily viewed on github.
There are two core problems for which this library provides solutions: a unified interface for image encodings and simple generic buffers for their content. It's possible to use either feature without the other. The focus is on a small and stable set of common operations that can be supplemented by other specialized crates. The library also prefers safe solutions with few dependencies.
High level API
Load images using ImageReader:
use Cursor;
use ImageReader;
#
And save them using save or write_to methods:
# use ;
# use ;
#
#
#
With default features, the crate includes support for many common image formats.
Image buffers
The two main types for storing images:
ImageBufferwhich holds statically typed image contents.DynamicImagewhich is an enum over the supportedImageBufferformats and supports conversions between them.
As well as a few more specialized options:
GenericImagetrait for a mutable image buffer.GenericImageViewtrait for read only references to aGenericImage.flatmodule containing types for interoperability with generic channel matrices and foreign interfaces.
Low level encoding/decoding API
Implementations of ImageEncoder provides low level control over encoding:
# use Write;
# use DynamicImage;
# use ImageEncoder;
#
#
#
While ImageDecoder and ImageDecoderRect give access to more advanced decoding options:
# use ;
# use DynamicImage;
# use ImageDecoder;
#
#
#
Modules
-
buffer
Iterators and other auxiliary structure for the
ImageBuffertype. - codecs Encoding and decoding for various image file formats.
- error Contains detailed error representation.
- flat Image representations for ffi.
- imageops Image Processing Functions
-
io
deprecated io module the original io module has been renamed to
image_reader - math Mathematical helper functions and types.
- metadata Types describing image metadata
Structs
- Delay The delay of a frame relative to the previous one.
- FlatSamples A flat buffer over a (multi channel) image.
- Frame A single animation frame
- Frames An implementation dependent iterator, reading the frames as requested
- ImageBuffer Generic image buffer
- ImageReader A multi-format image reader.
- LimitSupport Set of supported strict limits for a decoder.
- Limits Resource limits for decoding.
- Luma Grayscale colors.
- LumaA Grayscale colors + alpha channel
- Pixels Immutable pixel iterator
- Rgb RGB colors.
- Rgba RGB colors + alpha channel
- SubImage A View into another image
Enums
- ColorType An enumeration over supported color types and bit depths
- DynamicImage A Dynamic Image
- ExtendedColorType An enumeration of color types encountered in image formats.
- ImageError The generic error type for image operations.
- ImageFormat An enumeration of supported image formats. Not all formats support both encoding and decoding.
Traits
-
AnimationDecoder
AnimationDecodertrait - EncodableLayout Types which are safe to treat as an immutable byte slice in a pixel layout for image encoding.
- GenericImage A trait for manipulating images.
- GenericImageView Trait to inspect an image.
- ImageDecoder The trait that all decoders implement
- ImageDecoderRect Specialized image decoding not be supported by all formats
- ImageEncoder The trait all encoders implement
- Pixel A generalized pixel.
-
PixelWithColorType
The pixel with an associated
ColorType. Not all possible pixels represent one of the predefinedColorTypes. -
Primitive
The type of each channel in a pixel. For example, this can be
u8,u16,f32.
Functions
- guess_format Guess image format from memory block
- image_dimensions Read a tuple containing the (width, height) of the image located at the specified path. This is faster than fully loading the image and then getting its dimensions.
- load Create a new image from a Reader.
- load_from_memory Create a new image from a byte slice
- load_from_memory_with_format Create a new image from a byte slice
- open Open the image located at the path specified. The image's format is determined from the path's file extension.
- save_buffer Saves the supplied buffer to a file at the path specified.
- save_buffer_with_format Saves the supplied buffer to a file at the path specified in the specified format.
- write_buffer_with_format Writes the supplied buffer to a writer in the specified format.
Type Aliases
- GrayAlphaImage Sendable grayscale + alpha channel image buffer
- GrayImage Sendable grayscale image buffer
- ImageResult Result of an image decoding/encoding process
- Rgb32FImage An image buffer for 32-bit float RGB pixels, where the backing container is a flattened vector of floats.
- RgbImage Sendable Rgb image buffer
- Rgba32FImage An image buffer for 32-bit float RGBA pixels, where the backing container is a flattened vector of floats.
- RgbaImage Sendable Rgb + alpha channel image buffer