[−][src]Crate imgref
In graphics code it's very common to pass width
and height
along with a Vec
of pixels,
all as separate arguments. This is tedious, and can lead to errors.
This crate is a simple struct that adds dimensions to the underlying buffer. This makes it easier to correctly keep track of the image size and allows passing images with just one function argument instead three or four.
Additionally, it has a concept of a stride
, which allows defining sub-regions of images without copying,
as well as handling padding (e.g. buffers for video frames may require to be a multiple of 8, regardless of logical image size).
For convenience, there are iterators over rows or all pixels of a (sub)image and
pixel-based indexing directly with img[(x,y)]
(where x
/y
can be u32
as well as usize
).
Img<Container>
type has aliases for common uses:
- Owned:
ImgVec<T>
→Img<Vec<T>>
(use it instruct
s and return types) - Reference:
ImgRef<T>
→Img<&[T]>
(use it in function arguments) - Mutable reference:
ImgRefMut<T>
→Img<&mut [T]>
It is assumed that the container is one element per pixel, e.g. Vec<RGBA>
,
and not a Vec<u8>
where 4 u8
elements are interpreted as one pixel.
Structs
Img | Basic struct used for both owned (alias |
PixelsIter | Iterates over pixels in the (sub)image. Call |
PixelsIterMut | Iterates over pixels in the (sub)image. Call |
RowsIter | Rows of the image. Call |
RowsIterMut | Rows of the image. Call |
Traits
ImgExt | Additional methods that depend on buffer size |
ImgExtMut | Additional methods that depend on buffer size |
Type Definitions
ImgRef | Reference to pixels inside another image.
Pass this structure by value (i.e. |
ImgRefMut | Same as |
ImgVec | Image owning its pixels. |