Struct turbojpeg::Image

source ·
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 by Compressor)
  • Image<&mut [u8]>: mutable reference to image data (output image for decompression by Decompressor).
  • 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>

source

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>>.

source

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>>

source

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);

Trait Implementations§

source§

impl<T: Clone> Clone for Image<T>

source§

fn clone(&self) -> Image<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Image<T>

source§

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

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

impl<T: Copy> Copy for Image<T>

Auto Trait Implementations§

§

impl<T> Freeze for Image<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Image<T>
where T: RefUnwindSafe,

§

impl<T> Send for Image<T>
where T: Send,

§

impl<T> Sync for Image<T>
where T: Sync,

§

impl<T> Unpin for Image<T>
where T: Unpin,

§

impl<T> UnwindSafe for Image<T>
where T: 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.