Struct PixFormat

Source
#[repr(C)]
pub struct PixFormat { /* private fields */ }
Expand description

Single-planar pixel format

Applications set width and height to request an image size, drivers return the closest possible values. In case of planar formats the width and height applies to the largest plane. To avoid ambiguities drivers must return values rounded up to a multiple of the scale factor of any smaller planes. For example when the image format is YUV 4:2:0, width and height must be multiples of two.

For compressed formats that contain the resolution information encoded inside the stream, when fed to a stateful mem2mem decoder, the fields may be zero to rely on the decoder to detect the right values. For more details see Memory-to-Memory Stateful Video Decoder Interface and format descriptions.

For compressed formats on the capture side of a stateful mem2mem encoder, the ields must be zero, since the coded size is expected to be calculated internally by the encoder itself, based on the OUTPUT side. For more details see Memory-to-Memory Stateful Video Encoder Interface and format descriptions.

Implementations§

Source§

impl PixFormat

Source

pub fn width(&self) -> u32

Image width in pixels

Source

pub fn height(&self) -> u32

Image height in pixels

If field is one of Field::Top, Field::Bottom or Field::Alternate then height refers to the number of lines in the field, otherwise it refers to the number of lines in the frame (which is twice the field height for interlaced formats).

Source

pub fn pixel_format(&self) -> FourCc

Pixel format

The pixel format or type of compression, set by the application. This is a little endian four character code. V4L2 defines standard RGB formats in RGB Formats, YUV formats in YUV Formats, and reserved codes in Reserved Image Formats.

Source

pub fn field(&self) -> Field

Field order, from enum Field.

Video images are typically interlaced. Applications can request to capture or output only the top or bottom field, or both fields interlaced or sequentially stored in one buffer or alternating in separate buffers. Drivers return the actual field order selected. For more details on fields see Field Order.

Source

pub fn bytes_per_line(&self) -> u32

Distance in bytes between the leftmost pixels in two adjacent lines.

Both applications and drivers can set bytes_per_line to request padding bytes at the end of each line. Drivers however may ignore the value requested by the application, returning width times bytes per pixel or a larger value required by the hardware. That implies applications can just set this field to zero to get a reasonable default.

Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider cases where padding bytes after the last line of an image cross a system page boundary. Input devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.

When the image format is planar the bytesperline value applies to the first plane and is divided by the same factor as the width field for the other planes. For example the Cb and Cr planes of a YUV 4:2:0 image have half as many padding bytes following each line as the Y plane. To avoid ambiguities drivers must return a bytesperline value rounded up to a multiple of the scale factor.

For compressed formats the bytesperline value makes no sense. Applications and drivers must set this to 0 in that case.

Source

pub fn size_image(&self) -> u32

Image size

Size in bytes of the buffer to hold a complete image, set by the driver. Usually this is bytesperline times height. When the image consists of variable length compressed data this is the number of bytes required by the codec to support the worst-case compression scenario.

The driver will set the value for uncompressed images.

Clients are allowed to set the sizeimage field for variable length compressed data flagged with FmtFlag::Compressed, but the driver may ignore it and set the value itself, or it may modify the provided value based on alignment requirements or minimum/maximum size requirements. If the client wants to leave this to the driver, then it should set sizeimage to 0.

Source

pub fn color_space(&self) -> ColorSpace

Image colorspace, from enum ColorSpace.

This information supplements the pixelformat and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific colorspace for the captured image data. If the driver cannot handle requested conversion, it will return another supported colorspace. The driver indicates that colorspace conversion is supported by setting the flag FmtFlag::CscColorSpace in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source

pub fn flags(&self) -> PixFmtFlag

Pixel format flags

Flags set by the application or driver, see PixFmtFlag.

Source

pub fn quantization(&self) -> Quantization

Quantization range, from enum Quantization.

This information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific quantization range for the captured image data. If the driver cannot handle requested conversion, it will return another supported quantization. The driver indicates that quantization conversion is supported by setting the flag FmtFlag::CscQuantization in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source

pub fn xfer_func(&self) -> XferFunc

Transfer function, from enum XferFunc.

This information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific transfer function for the captured image data. If the driver cannot handle requested conversion, it will return another supported transfer function. The driver indicates that XferFunc conversion is supported by setting the flag FmtFlag::CscXferFunc in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source§

impl PixFormat

Source

pub fn set_width(&mut self, val: u32) -> &mut Self

Image width in pixels

Source

pub fn set_height(&mut self, val: u32) -> &mut Self

Image height in pixels

If field is one of Field::Top, Field::Bottom or Field::Alternate then height refers to the number of lines in the field, otherwise it refers to the number of lines in the frame (which is twice the field height for interlaced formats).

Source

pub fn set_pixel_format(&mut self, val: FourCc) -> &mut Self

Pixel format

The pixel format or type of compression, set by the application. This is a little endian four character code. V4L2 defines standard RGB formats in RGB Formats, YUV formats in YUV Formats, and reserved codes in Reserved Image Formats.

Source

pub fn set_field(&mut self, val: Field) -> &mut Self

Field order, from enum Field.

Video images are typically interlaced. Applications can request to capture or output only the top or bottom field, or both fields interlaced or sequentially stored in one buffer or alternating in separate buffers. Drivers return the actual field order selected. For more details on fields see Field Order.

Source

pub fn set_bytes_per_line(&mut self, val: u32) -> &mut Self

Distance in bytes between the leftmost pixels in two adjacent lines.

Both applications and drivers can set bytes_per_line to request padding bytes at the end of each line. Drivers however may ignore the value requested by the application, returning width times bytes per pixel or a larger value required by the hardware. That implies applications can just set this field to zero to get a reasonable default.

Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider cases where padding bytes after the last line of an image cross a system page boundary. Input devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.

When the image format is planar the bytesperline value applies to the first plane and is divided by the same factor as the width field for the other planes. For example the Cb and Cr planes of a YUV 4:2:0 image have half as many padding bytes following each line as the Y plane. To avoid ambiguities drivers must return a bytesperline value rounded up to a multiple of the scale factor.

For compressed formats the bytesperline value makes no sense. Applications and drivers must set this to 0 in that case.

Source

pub fn set_size_image(&mut self, val: u32) -> &mut Self

Image size

Size in bytes of the buffer to hold a complete image, set by the driver. Usually this is bytesperline times height. When the image consists of variable length compressed data this is the number of bytes required by the codec to support the worst-case compression scenario.

The driver will set the value for uncompressed images.

Clients are allowed to set the sizeimage field for variable length compressed data flagged with FmtFlag::Compressed, but the driver may ignore it and set the value itself, or it may modify the provided value based on alignment requirements or minimum/maximum size requirements. If the client wants to leave this to the driver, then it should set sizeimage to 0.

Source

pub fn set_color_space(&mut self, val: ColorSpace) -> &mut Self

Image colorspace, from enum ColorSpace.

This information supplements the pixelformat and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific colorspace for the captured image data. If the driver cannot handle requested conversion, it will return another supported colorspace. The driver indicates that colorspace conversion is supported by setting the flag FmtFlag::CscColorSpace in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source

pub fn set_flags(&mut self, val: PixFmtFlag) -> &mut Self

Pixel format flags

Flags set by the application or driver, see PixFmtFlag.

Source

pub fn set_quantization(&mut self, val: Quantization) -> &mut Self

Quantization range, from enum Quantization.

This information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific quantization range for the captured image data. If the driver cannot handle requested conversion, it will return another supported quantization. The driver indicates that quantization conversion is supported by setting the flag FmtFlag::CscQuantization in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source

pub fn set_xfer_func(&mut self, val: XferFunc) -> &mut Self

Transfer function, from enum XferFunc.

This information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific transfer function for the captured image data. If the driver cannot handle requested conversion, it will return another supported transfer function. The driver indicates that XferFunc conversion is supported by setting the flag FmtFlag::CscXferFunc in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source§

impl PixFormat

Source

pub fn ycbcr_enc(&self) -> Option<YcbcrEncoding>

Get Y’CbCr encoding, from enum YcbcrEncoding

This information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific Y’CbCr encoding for the captured image data. If the driver cannot handle requested conversion, it will return another supported encoding. This field is ignored for HSV pixel formats. The driver indicates that YcbcrEncoding conversion is supported by setting the flag FmtFlag::CscYcbcrEnc in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source

pub fn set_ycbcr_enc(&mut self, ycbcr_enc: YcbcrEncoding)

Set Y’CbCr encoding, from enum YcbcrEncoding

Source

pub fn hsv_enc(&self) -> Option<HsvEncoding>

Get HSV encoding, from enum HsvEncoding

This information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see Colorspaces. If the application sets the flag PixFmtFlag::SetCsc then the application can set this field for a capture stream to request a specific HSV encoding for the captured image data. If the driver cannot handle requested conversion, it will return another supported encoding. This field is ignored for non-HSV pixel formats. The driver indicates that hsv_enc conversion is supported by setting the flag FmtFlag::CscYcbcrEnc in the corresponding struct FmtDesc during enumeration. See FmtFlag.

Source

pub fn set_hsv_enc(&mut self, hsv_enc: HsvEncoding)

Set HSV encoding, from enum HsvEncoding

Trait Implementations§

Source§

impl Clone for PixFormat

Source§

fn clone(&self) -> PixFormat

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 Display for PixFormat

Source§

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

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

impl From<FourCc> for PixFormat

Source§

fn from(pixel_format: FourCc) -> Self

Converts to this type from the input type.
Source§

impl IsFormatData for PixFormat

Source§

const TYPES: &'static [BufferType]

Buffer types which corresponds to format type
Source§

impl Copy for PixFormat

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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

Source§

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.