FFmpeg 5.1.6
Data Structures | Macros | Functions
pixdesc.h File Reference
#include <inttypes.h>
#include "attributes.h"
#include "pixfmt.h"

Go to the source code of this file.

Data Structures

struct  AVComponentDescriptor
 
struct  AVPixFmtDescriptor
 Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes of an image. More...
 

Macros

#define AV_PIX_FMT_FLAG_BE   (1 << 0)
 Pixel format is big-endian. More...
 
#define AV_PIX_FMT_FLAG_PAL   (1 << 1)
 Pixel format has a palette in data[1], values are indexes in this palette. More...
 
#define AV_PIX_FMT_FLAG_BITSTREAM   (1 << 2)
 All values of a component are bit-wise packed end to end. More...
 
#define AV_PIX_FMT_FLAG_HWACCEL   (1 << 3)
 Pixel format is an HW accelerated format. More...
 
#define AV_PIX_FMT_FLAG_PLANAR   (1 << 4)
 At least one pixel component is not in the first data plane. More...
 
#define AV_PIX_FMT_FLAG_RGB   (1 << 5)
 The pixel format contains RGB-like data (as opposed to YUV/grayscale). More...
 
#define AV_PIX_FMT_FLAG_ALPHA   (1 << 7)
 The pixel format has an alpha channel. More...
 
#define AV_PIX_FMT_FLAG_BAYER   (1 << 8)
 The pixel format is following a Bayer pattern. More...
 
#define AV_PIX_FMT_FLAG_FLOAT   (1 << 9)
 The pixel format contains IEEE-754 floating point values. More...
 
#define FF_LOSS_RESOLUTION   0x0001
 loss due to resolution change More...
 
#define FF_LOSS_DEPTH   0x0002
 loss due to color depth change More...
 
#define FF_LOSS_COLORSPACE   0x0004
 loss due to color space conversion More...
 
#define FF_LOSS_ALPHA   0x0008
 loss of alpha bits More...
 
#define FF_LOSS_COLORQUANT   0x0010
 loss due to color quantization More...
 
#define FF_LOSS_CHROMA   0x0020
 loss of chroma (e.g. More...
 

Functions

int av_get_bits_per_pixel (const AVPixFmtDescriptor *pixdesc)
 Return the number of bits per pixel used by the pixel format described by pixdesc. More...
 
int av_get_padded_bits_per_pixel (const AVPixFmtDescriptor *pixdesc)
 Return the number of bits per pixel for the pixel format described by pixdesc, including any padding or unused bits. More...
 
const AVPixFmtDescriptorav_pix_fmt_desc_get (enum AVPixelFormat pix_fmt)
 
const AVPixFmtDescriptorav_pix_fmt_desc_next (const AVPixFmtDescriptor *prev)
 Iterate over all pixel format descriptors known to libavutil. More...
 
enum AVPixelFormat av_pix_fmt_desc_get_id (const AVPixFmtDescriptor *desc)
 
int av_pix_fmt_get_chroma_sub_sample (enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
 Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor. More...
 
int av_pix_fmt_count_planes (enum AVPixelFormat pix_fmt)
 
const char * av_color_range_name (enum AVColorRange range)
 
int av_color_range_from_name (const char *name)
 
const char * av_color_primaries_name (enum AVColorPrimaries primaries)
 
int av_color_primaries_from_name (const char *name)
 
const char * av_color_transfer_name (enum AVColorTransferCharacteristic transfer)
 
int av_color_transfer_from_name (const char *name)
 
const char * av_color_space_name (enum AVColorSpace space)
 
int av_color_space_from_name (const char *name)
 
const char * av_chroma_location_name (enum AVChromaLocation location)
 
int av_chroma_location_from_name (const char *name)
 
enum AVPixelFormat av_get_pix_fmt (const char *name)
 Return the pixel format corresponding to name. More...
 
const char * av_get_pix_fmt_name (enum AVPixelFormat pix_fmt)
 Return the short name for a pixel format, NULL in case pix_fmt is unknown. More...
 
char * av_get_pix_fmt_string (char *buf, int buf_size, enum AVPixelFormat pix_fmt)
 Print in buf the string corresponding to the pixel format with number pix_fmt, or a header if pix_fmt is negative. More...
 
void av_read_image_line2 (void *dst, const uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component, int dst_element_size)
 Read a line from an image, and write the values of the pixel format component c to dst. More...
 
void av_read_image_line (uint16_t *dst, const uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
 
void av_write_image_line2 (const void *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int src_element_size)
 Write the values from src to the pixel format component c of an image line. More...
 
void av_write_image_line (const uint16_t *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
 
enum AVPixelFormat av_pix_fmt_swap_endianness (enum AVPixelFormat pix_fmt)
 Utility function to swap the endianness of a pixel format. More...
 
int av_get_pix_fmt_loss (enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt, int has_alpha)
 Compute what kind of losses will occur when converting from one specific pixel format to another. More...
 
enum AVPixelFormat av_find_best_pix_fmt_of_2 (enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
 Compute what kind of losses will occur when converting from one specific pixel format to another. More...
 

Macro Definition Documentation

◆ AV_PIX_FMT_FLAG_BE

#define AV_PIX_FMT_FLAG_BE   (1 << 0)

Pixel format is big-endian.

Definition at line 116 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_PAL

#define AV_PIX_FMT_FLAG_PAL   (1 << 1)

Pixel format has a palette in data[1], values are indexes in this palette.

Definition at line 120 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_BITSTREAM

#define AV_PIX_FMT_FLAG_BITSTREAM   (1 << 2)

All values of a component are bit-wise packed end to end.

Definition at line 124 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_HWACCEL

#define AV_PIX_FMT_FLAG_HWACCEL   (1 << 3)

Pixel format is an HW accelerated format.

Definition at line 128 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_PLANAR

#define AV_PIX_FMT_FLAG_PLANAR   (1 << 4)

At least one pixel component is not in the first data plane.

Definition at line 132 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_RGB

#define AV_PIX_FMT_FLAG_RGB   (1 << 5)

The pixel format contains RGB-like data (as opposed to YUV/grayscale).

Definition at line 136 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_ALPHA

#define AV_PIX_FMT_FLAG_ALPHA   (1 << 7)

The pixel format has an alpha channel.

This is set on all formats that support alpha in some way, including AV_PIX_FMT_PAL8. The alpha is always straight, never pre-multiplied.

If a codec or a filter does not support alpha, it should set all alpha to opaque, or use the equivalent pixel formats without alpha component, e.g. AV_PIX_FMT_RGB0 (or AV_PIX_FMT_RGB24 etc.) instead of AV_PIX_FMT_RGBA.

Definition at line 147 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_BAYER

#define AV_PIX_FMT_FLAG_BAYER   (1 << 8)

The pixel format is following a Bayer pattern.

Definition at line 152 of file pixdesc.h.

◆ AV_PIX_FMT_FLAG_FLOAT

#define AV_PIX_FMT_FLAG_FLOAT   (1 << 9)

The pixel format contains IEEE-754 floating point values.

Precision (double, single, or half) should be determined by the pixel size (64, 32, or 16 bits).

Definition at line 158 of file pixdesc.h.

◆ FF_LOSS_RESOLUTION

#define FF_LOSS_RESOLUTION   0x0001

loss due to resolution change

Definition at line 360 of file pixdesc.h.

◆ FF_LOSS_DEPTH

#define FF_LOSS_DEPTH   0x0002

loss due to color depth change

Definition at line 361 of file pixdesc.h.

◆ FF_LOSS_COLORSPACE

#define FF_LOSS_COLORSPACE   0x0004

loss due to color space conversion

Definition at line 362 of file pixdesc.h.

◆ FF_LOSS_ALPHA

#define FF_LOSS_ALPHA   0x0008

loss of alpha bits

Definition at line 363 of file pixdesc.h.

◆ FF_LOSS_COLORQUANT

#define FF_LOSS_COLORQUANT   0x0010

loss due to color quantization

Definition at line 364 of file pixdesc.h.

◆ FF_LOSS_CHROMA

#define FF_LOSS_CHROMA   0x0020

loss of chroma (e.g.

RGB to gray conversion)

Definition at line 365 of file pixdesc.h.

Function Documentation

◆ av_get_bits_per_pixel()

int av_get_bits_per_pixel ( const AVPixFmtDescriptor pixdesc)

Return the number of bits per pixel used by the pixel format described by pixdesc.

Note that this is not the same as the number of bits per sample.

The returned number of bits refers to the number of bits actually used for storing the pixel information, that is padding bits are not counted.

◆ av_get_padded_bits_per_pixel()

int av_get_padded_bits_per_pixel ( const AVPixFmtDescriptor pixdesc)

Return the number of bits per pixel for the pixel format described by pixdesc, including any padding or unused bits.

◆ av_pix_fmt_desc_get()

const AVPixFmtDescriptor * av_pix_fmt_desc_get ( enum AVPixelFormat  pix_fmt)
Returns
a pixel format descriptor for provided pixel format or NULL if this pixel format is unknown.

◆ av_pix_fmt_desc_next()

const AVPixFmtDescriptor * av_pix_fmt_desc_next ( const AVPixFmtDescriptor prev)

Iterate over all pixel format descriptors known to libavutil.

Parameters
prevprevious descriptor. NULL to get the first descriptor.
Returns
next descriptor or NULL after the last descriptor

◆ av_pix_fmt_desc_get_id()

enum AVPixelFormat av_pix_fmt_desc_get_id ( const AVPixFmtDescriptor desc)
Returns
an AVPixelFormat id described by desc, or AV_PIX_FMT_NONE if desc is not a valid pointer to a pixel format descriptor.

◆ av_pix_fmt_get_chroma_sub_sample()

int av_pix_fmt_get_chroma_sub_sample ( enum AVPixelFormat  pix_fmt,
int *  h_shift,
int *  v_shift 
)

Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.

Parameters
[in]pix_fmtthe pixel format
[out]h_shiftstore log2_chroma_w (horizontal/width shift)
[out]v_shiftstore log2_chroma_h (vertical/height shift)
Returns
0 on success, AVERROR(ENOSYS) on invalid or unknown pixel format

◆ av_pix_fmt_count_planes()

int av_pix_fmt_count_planes ( enum AVPixelFormat  pix_fmt)
Returns
number of planes in pix_fmt, a negative AVERROR if pix_fmt is not a valid pixel format.

◆ av_color_range_name()

const char * av_color_range_name ( enum AVColorRange  range)
Returns
the name for provided color range or NULL if unknown.

◆ av_color_range_from_name()

int av_color_range_from_name ( const char *  name)
Returns
the AVColorRange value for name or an AVError if not found.

◆ av_color_primaries_name()

const char * av_color_primaries_name ( enum AVColorPrimaries  primaries)
Returns
the name for provided color primaries or NULL if unknown.

◆ av_color_primaries_from_name()

int av_color_primaries_from_name ( const char *  name)
Returns
the AVColorPrimaries value for name or an AVError if not found.

◆ av_color_transfer_name()

const char * av_color_transfer_name ( enum AVColorTransferCharacteristic  transfer)
Returns
the name for provided color transfer or NULL if unknown.

◆ av_color_transfer_from_name()

int av_color_transfer_from_name ( const char *  name)
Returns
the AVColorTransferCharacteristic value for name or an AVError if not found.

◆ av_color_space_name()

const char * av_color_space_name ( enum AVColorSpace  space)
Returns
the name for provided color space or NULL if unknown.

◆ av_color_space_from_name()

int av_color_space_from_name ( const char *  name)
Returns
the AVColorSpace value for name or an AVError if not found.

◆ av_chroma_location_name()

const char * av_chroma_location_name ( enum AVChromaLocation  location)
Returns
the name for provided chroma location or NULL if unknown.

◆ av_chroma_location_from_name()

int av_chroma_location_from_name ( const char *  name)
Returns
the AVChromaLocation value for name or an AVError if not found.

◆ av_get_pix_fmt()

enum AVPixelFormat av_get_pix_fmt ( const char *  name)

Return the pixel format corresponding to name.

If there is no pixel format with name name, then looks for a pixel format with the name corresponding to the native endian format of name. For example in a little-endian system, first looks for "gray16", then for "gray16le".

Finally if no pixel format has been found, returns AV_PIX_FMT_NONE.

◆ av_get_pix_fmt_name()

const char * av_get_pix_fmt_name ( enum AVPixelFormat  pix_fmt)

Return the short name for a pixel format, NULL in case pix_fmt is unknown.

See also
av_get_pix_fmt(), av_get_pix_fmt_string()
Examples
demuxing_decoding.c, and scaling_video.c.

Referenced by main(), and output_video_frame().

◆ av_get_pix_fmt_string()

char * av_get_pix_fmt_string ( char *  buf,
int  buf_size,
enum AVPixelFormat  pix_fmt 
)

Print in buf the string corresponding to the pixel format with number pix_fmt, or a header if pix_fmt is negative.

Parameters
bufthe buffer where to write the string
buf_sizethe size of buf
pix_fmtthe number of the pixel format to print the corresponding info string, or a negative value to print the corresponding header.

◆ av_read_image_line2()

void av_read_image_line2 ( void *  dst,
const uint8_t *  data[4],
const int  linesize[4],
const AVPixFmtDescriptor desc,
int  x,
int  y,
int  c,
int  w,
int  read_pal_component,
int  dst_element_size 
)

Read a line from an image, and write the values of the pixel format component c to dst.

Parameters
datathe array containing the pointers to the planes of the image
linesizethe array containing the linesizes of the image
descthe pixel format descriptor for the image
xthe horizontal coordinate of the first pixel to read
ythe vertical coordinate of the first pixel to read
wthe width of the line to read, that is the number of values to write to dst
read_pal_componentif not zero and the format is a paletted format writes the values corresponding to the palette component c in data[1] to dst, rather than the palette indexes in data[0]. The behavior is undefined if the format is not paletted.
dst_element_sizesize of elements in dst array (2 or 4 byte)

◆ av_read_image_line()

void av_read_image_line ( uint16_t *  dst,
const uint8_t *  data[4],
const int  linesize[4],
const AVPixFmtDescriptor desc,
int  x,
int  y,
int  c,
int  w,
int  read_pal_component 
)

◆ av_write_image_line2()

void av_write_image_line2 ( const void *  src,
uint8_t *  data[4],
const int  linesize[4],
const AVPixFmtDescriptor desc,
int  x,
int  y,
int  c,
int  w,
int  src_element_size 
)

Write the values from src to the pixel format component c of an image line.

Parameters
srcarray containing the values to write
datathe array containing the pointers to the planes of the image to write into. It is supposed to be zeroed.
linesizethe array containing the linesizes of the image
descthe pixel format descriptor for the image
xthe horizontal coordinate of the first pixel to write
ythe vertical coordinate of the first pixel to write
wthe width of the line to write, that is the number of values to write to the image line
src_element_sizesize of elements in src array (2 or 4 byte)

◆ av_write_image_line()

void av_write_image_line ( const uint16_t *  src,
uint8_t *  data[4],
const int  linesize[4],
const AVPixFmtDescriptor desc,
int  x,
int  y,
int  c,
int  w 
)

◆ av_pix_fmt_swap_endianness()

enum AVPixelFormat av_pix_fmt_swap_endianness ( enum AVPixelFormat  pix_fmt)

Utility function to swap the endianness of a pixel format.

Parameters
[in]pix_fmtthe pixel format
Returns
pixel format with swapped endianness if it exists, otherwise AV_PIX_FMT_NONE

◆ av_get_pix_fmt_loss()

int av_get_pix_fmt_loss ( enum AVPixelFormat  dst_pix_fmt,
enum AVPixelFormat  src_pix_fmt,
int  has_alpha 
)

Compute what kind of losses will occur when converting from one specific pixel format to another.

When converting from one pixel format to another, information loss may occur. For example, when converting from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when converting from some formats to other formats. These losses can involve loss of chroma, but also loss of resolution, loss of color depth, loss due to the color space conversion, loss of the alpha bits or loss due to color quantization. av_get_fix_fmt_loss() informs you about the various types of losses which will occur when converting from one pixel format to another.

Parameters
[in]dst_pix_fmtdestination pixel format
[in]src_pix_fmtsource pixel format
[in]has_alphaWhether the source pixel format alpha channel is used.
Returns
Combination of flags informing you what kind of losses will occur (maximum loss for an invalid dst_pix_fmt).

◆ av_find_best_pix_fmt_of_2()

enum AVPixelFormat av_find_best_pix_fmt_of_2 ( enum AVPixelFormat  dst_pix_fmt1,
enum AVPixelFormat  dst_pix_fmt2,
enum AVPixelFormat  src_pix_fmt,
int  has_alpha,
int *  loss_ptr 
)

Compute what kind of losses will occur when converting from one specific pixel format to another.

When converting from one pixel format to another, information loss may occur. For example, when converting from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when converting from some formats to other formats. These losses can involve loss of chroma, but also loss of resolution, loss of color depth, loss due to the color space conversion, loss of the alpha bits or loss due to color quantization. av_get_fix_fmt_loss() informs you about the various types of losses which will occur when converting from one pixel format to another.

Parameters
[in]dst_pix_fmtdestination pixel format
[in]src_pix_fmtsource pixel format
[in]has_alphaWhether the source pixel format alpha channel is used.
Returns
Combination of flags informing you what kind of losses will occur (maximum loss for an invalid dst_pix_fmt).