pub struct Image<T> {
pub pixels: T,
pub width: usize,
pub pitch: usize,
pub height: usize,
pub format: PixelFormat,
}
Expand description
An image with pixels of type T
.
Three variants of this type are commonly used:
Image<&[u8]>
: immutable reference to image data (input image for compression byCompressor
)Image<&mut [u8]>
: mutable reference to image data (output image for decompression byDecompressor
).Image<Vec<u8>>
: owned image data (you can convert it to a reference using.as_deref()
or.as_deref_mut()
).
Data for pixel in column x
and row y
is stored in pixels
at offset y*pitch + x*format.size()
.
Fields§
§pixels: T
Pixel data of the image (typically &[u8]
, &mut [u8]
or Vec<u8>
).
width: usize
Width of the image in pixels (number of columns).
pitch: usize
Pitch (stride) defines the size of one image row in bytes. Overlapping rows are not
supported, we require that pitch >= width * format.size()
.
height: usize
Height of the image in pixels (number of rows).
format: PixelFormat
Format of pixels in memory, determines the color format (RGB, RGBA, grayscale or CMYK) and the memory layout (RGB, BGR, RGBA, …).
Implementations§
source§impl<T> Image<T>
impl<T> Image<T>
sourcepub fn as_deref(&self) -> Image<&T::Target>where
T: Deref,
pub fn as_deref(&self) -> Image<&T::Target>where
T: Deref,
Converts from &Image<T>
to Image<&T::Target>
.
In particular, you can use this to get Image<&[u8]>
from Image<Vec<u8>>
.
sourcepub fn as_deref_mut(&mut self) -> Image<&mut T::Target>where
T: DerefMut,
pub fn as_deref_mut(&mut self) -> Image<&mut T::Target>where
T: DerefMut,
Converts from &mut Image<T>
to Image<&mut T::Target>
.
In particular, you can use this to get Image<&mut [u8]>
from Image<Vec<u8>>
.
source§impl Image<Vec<u8>>
impl Image<Vec<u8>>
sourcepub fn mandelbrot(
width: usize,
height: usize,
format: PixelFormat
) -> Image<Vec<u8>>
pub fn mandelbrot( width: usize, height: usize, format: PixelFormat ) -> Image<Vec<u8>>
Generates an image of the Mandelbrot set.
The generated image has the given width and height and uses the given pixel format. This method is intended for testing and demonstration purposes.
§Example
let image = turbojpeg::Image::mandelbrot(200, 200, turbojpeg::PixelFormat::BGRA);
assert_eq!((image.width, image.height), (200, 200));
assert_eq!(image.format, turbojpeg::PixelFormat::BGRA);