Struct turbojpeg::YuvImage

source ·
pub struct YuvImage<T> {
    pub pixels: T,
    pub width: usize,
    pub align: usize,
    pub height: usize,
    pub subsamp: Subsamp,
}
Expand description

A YUV (YCbCr) planar image with pixels of type T.

This type stores an image in the JPEG color transform YCbCr (also called “YUV”). The image data first stores the Y plane, then the U (Cb) plane, and then the V (Cr) plane.

Two variants of this type are commonly used:

  • YuvImage<&mut [u8]>: mutable reference to YUV image data (output image for decompression by Decompressor).
  • YuvImage<Vec<u8>>: owned YUV image data (you can convert it to a reference using .as_deref() or .as_deref_mut()).

§Image format

The size of each image plane is determined by the width, height, chrominance subsampling and row alignment of the image:

§Example

For example, if the source image is 35 x 35 pixels and Sub2x1 subsampling is used, then the luminance plane would be 36 x 35 bytes, and each of the chrominance planes would be 18 x 35 bytes. If you specify a row alignment of 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, and each of the chrominance planes would be 20 x 35 bytes.

let img1 = turbojpeg::YuvImage {
    pixels: (),
    width: 35,
    align: 1,
    height: 35,
    subsamp: turbojpeg::Subsamp::Sub2x1,
};
assert_eq!(img1.y_size(), (36, 35));
assert_eq!(img1.uv_size(), (18, 35));

let img2 = turbojpeg::YuvImage { align: 4, ..img1 };
assert_eq!(img2.y_size(), (36, 35));
assert_eq!(img2.uv_size(), (20, 35));

Fields§

§pixels: T

Pixel data of the image (typically &mut [u8] or Vec<u8>).

§width: usize

Width of the image in pixels (number of columns).

§align: usize

Row alignment (in bytes) of the YUV image (must be a power of 2). Each row in each plane of the YUV image will be padded to the nearest multiple of align.

§height: usize

Height of the image in pixels (number of rows).

§subsamp: Subsamp

The level of chrominance subsampling used in the YUV image.

Implementations§

source§

impl<T> YuvImage<T>

source

pub fn as_deref(&self) -> YuvImage<&T::Target>
where T: Deref,

Converts from &YuvImage<T> to YuvImage<&T::Target>.

In particular, you can use this to get YuvImage<&[u8]> from YuvImage<Vec<u8>>.

source

pub fn as_deref_mut(&mut self) -> YuvImage<&mut T::Target>
where T: DerefMut,

Converts from &mut YuvImage<T> to YuvImage<&mut T::Target>.

In particular, you can use this to get YuvImage<&mut [u8]> from YuvImage<Vec<u8>>.

source

pub fn y_width(&self) -> usize

Computes width of the luminance (Y) plane.

This is the image width padded to the nearest multiple of the horizontal subsampling factor and then aligned to the row alignment.

source

pub fn y_height(&self) -> usize

Computes height of the luminance (Y) plane.

This is the image height padded to the nearest multiple of the vertical subsampling factor.

source

pub fn y_size(&self) -> (usize, usize)

Computes size of the luminance (Y) plane.

source

pub fn uv_width(&self) -> usize

Computes width of each chrominance (U, V) plane.

This is the Y plane width divided by the horizontal subsampling factor and then aligned to the row alignment.

source

pub fn uv_height(&self) -> usize

Computes height of each chrominance (U, V) plane.

This is the Y plane height divided by the vertical subsampling factor.

source

pub fn uv_size(&self) -> (usize, usize)

Computes size of each chrominance (U, V) plane.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for YuvImage<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, 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.