libavcodec/imgconvert.c File Reference

misc image conversion routines More...

#include "avcodec.h"
#include "dsputil.h"
#include "internal.h"
#include "imgconvert.h"
#include "libavutil/colorspace.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"

Go to the source code of this file.

Data Structures

struct  PixFmtInfo

Defines

#define FF_COLOR_RGB   0
 RGB color space.
#define FF_COLOR_GRAY   1
 gray color space
#define FF_COLOR_YUV   2
 YUV color space.
#define FF_COLOR_YUV_JPEG   3
 YUV color space.
#define deinterlace_line_inplace   deinterlace_line_inplace_c
#define deinterlace_line   deinterlace_line_c

Functions

void avcodec_get_chroma_sub_sample (enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
const char * avcodec_get_pix_fmt_name (enum PixelFormat pix_fmt)
 Return the short name for a pixel format.
int ff_is_hwaccel_pix_fmt (enum PixelFormat pix_fmt)
 Determine whether pix_fmt is a hardware accelerated format.
int avpicture_fill (AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, int width, int height)
 Fill in the AVPicture fields.
int avpicture_layout (const AVPicture *src, enum PixelFormat pix_fmt, int width, int height, unsigned char *dest, int dest_size)
 Copy pixel data from an AVPicture into a buffer.
int avpicture_get_size (enum PixelFormat pix_fmt, int width, int height)
 Calculate the size in bytes that a picture of the given width and height would occupy if stored in the given picture format.
static int get_pix_fmt_depth (int *min, int *max, enum PixelFormat pix_fmt)
int avcodec_get_pix_fmt_loss (enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt, int has_alpha)
 Compute what kind of losses will occur when converting from one specific pixel format to another.
static int avg_bits_per_pixel (enum PixelFormat pix_fmt)
enum PixelFormat avcodec_find_best_pix_fmt (int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
 Find the best pixel format to convert to given a certain source pixel format.
enum PixelFormat avcodec_find_best_pix_fmt2 (enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2, enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
 Find the best pixel format to convert to given a certain source pixel format and a selection of two destination pixel formats.
void av_picture_copy (AVPicture *dst, const AVPicture *src, enum PixelFormat pix_fmt, int width, int height)
 Copy image src to dst.
void ff_shrink22 (uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
void ff_shrink44 (uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
void ff_shrink88 (uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
int avpicture_alloc (AVPicture *picture, enum PixelFormat pix_fmt, int width, int height)
 Allocate memory for a picture.
void avpicture_free (AVPicture *picture)
 Free a picture previously allocated by avpicture_alloc().
static int is_yuv_planar (enum PixelFormat fmt)
int av_picture_crop (AVPicture *dst, const AVPicture *src, enum PixelFormat pix_fmt, int top_band, int left_band)
 Crop image top and left side.
int av_picture_pad (AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright, int *color)
 Pad image.
static int get_alpha_info_pal8 (const AVPicture *src, int width, int height)
int img_get_alpha_info (const AVPicture *src, enum PixelFormat pix_fmt, int width, int height)
 Tell if an image really has transparent alpha values.
static void deinterlace_line_c (uint8_t *dst, const uint8_t *lum_m4, const uint8_t *lum_m3, const uint8_t *lum_m2, const uint8_t *lum_m1, const uint8_t *lum, int size)
static void deinterlace_line_inplace_c (uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum, int size)
static void deinterlace_bottom_field (uint8_t *dst, int dst_wrap, const uint8_t *src1, int src_wrap, int width, int height)
static void deinterlace_bottom_field_inplace (uint8_t *src1, int src_wrap, int width, int height)
int avpicture_deinterlace (AVPicture *dst, const AVPicture *src, enum PixelFormat pix_fmt, int width, int height)

Variables

static const PixFmtInfo pix_fmt_info [PIX_FMT_NB]


Detailed Description

misc image conversion routines

Definition in file imgconvert.c.


Define Documentation

#define deinterlace_line   deinterlace_line_c

Definition at line 55 of file imgconvert.c.

Referenced by deinterlace_bottom_field().

#define deinterlace_line_inplace   deinterlace_line_inplace_c

Definition at line 54 of file imgconvert.c.

Referenced by deinterlace_bottom_field_inplace().

#define FF_COLOR_GRAY   1

gray color space

Definition at line 46 of file imgconvert.c.

Referenced by avcodec_get_pix_fmt_loss().

#define FF_COLOR_RGB   0

RGB color space.

Definition at line 45 of file imgconvert.c.

Referenced by avcodec_get_pix_fmt_loss().

#define FF_COLOR_YUV   2

YUV color space.

16 <= Y <= 235, 16 <= U, V <= 240

Definition at line 47 of file imgconvert.c.

Referenced by avcodec_get_pix_fmt_loss(), and is_yuv_planar().

#define FF_COLOR_YUV_JPEG   3

YUV color space.

0 <= Y <= 255, 0 <= U, V <= 255

Definition at line 48 of file imgconvert.c.

Referenced by avcodec_get_pix_fmt_loss(), and is_yuv_planar().


Function Documentation

void av_picture_copy ( AVPicture dst,
const AVPicture src,
enum PixelFormat  pix_fmt,
int  width,
int  height 
)

Copy image src to dst.

Wraps av_picture_data_copy() above.

Definition at line 525 of file imgconvert.c.

Referenced by avcodec_default_reget_buffer(), copy_frame(), qtrle_encode_frame(), queue_picture(), and roq_decode_frame().

int av_picture_crop ( AVPicture dst,
const AVPicture src,
enum PixelFormat  pix_fmt,
int  top_band,
int  left_band 
)

Crop image top and left side.

Definition at line 660 of file imgconvert.c.

int av_picture_pad ( AVPicture dst,
const AVPicture src,
int  height,
int  width,
enum PixelFormat  pix_fmt,
int  padtop,
int  padbottom,
int  padleft,
int  padright,
int *  color 
)

Pad image.

Definition at line 690 of file imgconvert.c.

enum PixelFormat avcodec_find_best_pix_fmt ( int64_t  pix_fmt_mask,
enum PixelFormat  src_pix_fmt,
int  has_alpha,
int *  loss_ptr 
)

Find the best pixel format to convert to given a certain source pixel format.

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. avcodec_find_best_pix_fmt() searches which of the given pixel formats should be used to suffer the least amount of loss. The pixel formats from which it chooses one, are determined by the pix_fmt_mask parameter.

Note, only the first 64 pixel formats will fit in pix_fmt_mask.

 src_pix_fmt = PIX_FMT_YUV420P;
 pix_fmt_mask = (1 << PIX_FMT_YUV422P) | (1 << PIX_FMT_RGB24);
 dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);

Parameters:
[in] pix_fmt_mask bitmask determining which pixel format to choose from
[in] src_pix_fmt source pixel format
[in] has_alpha Whether the source pixel format alpha channel is used.
[out] loss_ptr Combination of flags informing you what kind of losses will occur.
Returns:
The best pixel format to convert to or -1 if none was found.

Definition at line 468 of file imgconvert.c.

enum PixelFormat avcodec_find_best_pix_fmt2 ( enum PixelFormat  dst_pix_fmt1,
enum PixelFormat  dst_pix_fmt2,
enum PixelFormat  src_pix_fmt,
int  has_alpha,
int *  loss_ptr 
)

Find the best pixel format to convert to given a certain source pixel format and a selection of two destination pixel formats.

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. avcodec_find_best_pix_fmt2() selects which of the given pixel formats should be used to suffer the least amount of loss.

If one of the destination formats is PIX_FMT_NONE the other pixel format (if valid) will be returned.

 src_pix_fmt = PIX_FMT_YUV420P;
 dst_pix_fmt1= PIX_FMT_RGB24;
 dst_pix_fmt2= PIX_FMT_GRAY8;
 dst_pix_fmt3= PIX_FMT_RGB8;
 loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored.
 dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss);
 dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss);

Parameters:
[in] dst_pix_fmt1 One of the two destination pixel formats to choose from
[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from
[in] src_pix_fmt Source pixel format
[in] has_alpha Whether the source pixel format alpha channel is used.
[in,out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e. NULL or value of zero means we care about all losses. Out: the loss that occurs when converting from src to selected dst pixel format.
Returns:
The best pixel format to convert to or -1 if none was found.

Definition at line 485 of file imgconvert.c.

Referenced by avcodec_find_best_pix_fmt(), and choose_pixel_fmt().

void avcodec_get_chroma_sub_sample ( enum PixelFormat  pix_fmt,
int *  h_shift,
int *  v_shift 
)

int avcodec_get_pix_fmt_loss ( enum PixelFormat  dst_pix_fmt,
enum PixelFormat  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. avcodec_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_fmt destination pixel format
[in] src_pix_fmt source pixel format
[in] has_alpha Whether 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).

Definition at line 391 of file imgconvert.c.

Referenced by avcodec_find_best_pix_fmt2().

const char* avcodec_get_pix_fmt_name ( enum PixelFormat  pix_fmt  ) 

Return the short name for a pixel format.

See also:
av_get_pix_fmt(), av_get_pix_fmt_string().
Deprecated:
Deprecated in favor of av_get_pix_fmt_name().

Definition at line 288 of file imgconvert.c.

static int avg_bits_per_pixel ( enum PixelFormat  pix_fmt  )  [static]

Definition at line 459 of file imgconvert.c.

Referenced by avcodec_find_best_pix_fmt2().

int avpicture_alloc ( AVPicture picture,
enum PixelFormat  pix_fmt,
int  width,
int  height 
)

Allocate memory for a picture.

Call avpicture_free() to free it.

See also:
avpicture_fill()
Parameters:
picture the picture to be filled in
pix_fmt the format of the picture
width the width of the picture
height the height of the picture
Returns:
zero if successful, a negative value if not

Definition at line 619 of file imgconvert.c.

Referenced by do_video_resample(), ff_create_schro_frame(), libschroedinger_handle_first_access_unit(), and qtrle_encode_init().

int avpicture_deinterlace ( AVPicture dst,
const AVPicture src,
enum PixelFormat  pix_fmt,
int  width,
int  height 
)

Definition at line 907 of file imgconvert.c.

Referenced by pre_process_video_frame().

int avpicture_fill ( AVPicture picture,
uint8_t *  ptr,
enum PixelFormat  pix_fmt,
int  width,
int  height 
)

Fill in the AVPicture fields.

The fields of the given AVPicture are filled in by using the 'ptr' address which points to the image data buffer. Depending on the specified picture format, one or multiple image data pointers and line sizes will be set. If a planar format is specified, several pointers will be set pointing to the different picture planes and the line sizes of the different planes will be stored in the lines_sizes array. Call with ptr == NULL to get the required size for the ptr buffer.

To allocate the buffer and fill in the AVPicture fields in one call, use avpicture_alloc().

Parameters:
picture AVPicture whose fields are to be filled in
ptr Buffer which will contain or contains the actual image data
pix_fmt The format in which the picture data is stored.
width the width of the image in pixels
height the height of the image in pixels
Returns:
size of the image data in bytes

Definition at line 299 of file imgconvert.c.

Referenced by alloc_picture(), avpicture_get_size(), copy_frame(), do_streamcopy(), libdirac_decode_frame(), libschroedinger_decode_frame(), pre_process_video_frame(), raw_decode(), and sdl_write_packet().

void avpicture_free ( AVPicture picture  ) 

Free a picture previously allocated by avpicture_alloc().

The data buffer used by the AVPicture is freed, but the AVPicture structure itself is not.

Parameters:
picture the AVPicture to be freed

Definition at line 632 of file imgconvert.c.

Referenced by FreeSchroFrame(), libschroedinger_decode_close(), and qtrle_encode_end().

int avpicture_get_size ( enum PixelFormat  pix_fmt,
int  width,
int  height 
)

Calculate the size in bytes that a picture of the given width and height would occupy if stored in the given picture format.

Note that this returns the size of a compact representation as generated by avpicture_layout(), which can be smaller than the size required for e.g. avpicture_fill().

Parameters:
pix_fmt the given picture format
width the width of the image
height the height of the image
Returns:
Image data size in bytes or -1 on error (e.g. too large dimensions).

Definition at line 356 of file imgconvert.c.

Referenced by alloc_picture(), avpicture_layout(), dc1394_read_header(), lavfi_read_packet(), libdirac_decode_frame(), libdirac_encode_init(), libschroedinger_encode_init(), pam_encode_frame(), pnm_encode_frame(), pnm_parse(), pre_process_video_frame(), raw_init_decoder(), rawvideo_read_packet(), targa_encode_frame(), utvideo_decode_init(), v4l2_read_header(), vble_decode_init(), and yuv4_read_packet().

int avpicture_layout ( const AVPicture src,
enum PixelFormat  pix_fmt,
int  width,
int  height,
unsigned char *  dest,
int  dest_size 
)

Copy pixel data from an AVPicture into a buffer.

The data is stored compactly, without any gaps for alignment or padding which may be applied by avpicture_fill().

See also:
avpicture_get_size()
Parameters:
[in] src AVPicture containing image data
[in] pix_fmt The format in which the picture data is stored.
[in] width the width of the image in pixels.
[in] height the height of the image in pixels.
[out] dest A buffer into which picture data will be copied.
[in] dest_size The size of 'dest'.
Returns:
The number of bytes written to dest, or a negative value (error code) on error.

Definition at line 313 of file imgconvert.c.

Referenced by encode_frame(), lavfi_read_packet(), libdirac_encode_frame(), libschroedinger_frame_from_data(), and raw_encode().

static void deinterlace_bottom_field ( uint8_t *  dst,
int  dst_wrap,
const uint8_t *  src1,
int  src_wrap,
int  width,
int  height 
) [static]

Definition at line 853 of file imgconvert.c.

Referenced by avpicture_deinterlace().

static void deinterlace_bottom_field_inplace ( uint8_t *  src1,
int  src_wrap,
int  width,
int  height 
) [static]

Definition at line 882 of file imgconvert.c.

Referenced by avpicture_deinterlace().

static void deinterlace_line_c ( uint8_t *  dst,
const uint8_t *  lum_m4,
const uint8_t *  lum_m3,
const uint8_t *  lum_m2,
const uint8_t *  lum_m1,
const uint8_t *  lum,
int  size 
) [static]

Definition at line 801 of file imgconvert.c.

static void deinterlace_line_inplace_c ( uint8_t *  lum_m4,
uint8_t *  lum_m3,
uint8_t *  lum_m2,
uint8_t *  lum_m1,
uint8_t *  lum,
int  size 
) [static]

Definition at line 826 of file imgconvert.c.

int ff_is_hwaccel_pix_fmt ( enum PixelFormat  pix_fmt  ) 

Determine whether pix_fmt is a hardware accelerated format.

Definition at line 294 of file imgconvert.c.

Referenced by avcodec_default_get_format().

void ff_shrink22 ( uint8_t *  dst,
int  dst_wrap,
const uint8_t *  src,
int  src_wrap,
int  width,
int  height 
)

Definition at line 533 of file imgconvert.c.

Referenced by dsputil_init().

void ff_shrink44 ( uint8_t *  dst,
int  dst_wrap,
const uint8_t *  src,
int  src_wrap,
int  width,
int  height 
)

Definition at line 566 of file imgconvert.c.

Referenced by dsputil_init().

void ff_shrink88 ( uint8_t *  dst,
int  dst_wrap,
const uint8_t *  src,
int  src_wrap,
int  width,
int  height 
)

Definition at line 597 of file imgconvert.c.

Referenced by dsputil_init().

static int get_alpha_info_pal8 ( const AVPicture src,
int  width,
int  height 
) [static]

Definition at line 752 of file imgconvert.c.

Referenced by img_get_alpha_info().

static int get_pix_fmt_depth ( int *  min,
int *  max,
enum PixelFormat  pix_fmt 
) [static]

Definition at line 373 of file imgconvert.c.

Referenced by avcodec_get_pix_fmt_loss().

int img_get_alpha_info ( const AVPicture src,
enum PixelFormat  pix_fmt,
int  width,
int  height 
)

Tell if an image really has transparent alpha values.

Returns:
ored mask of FF_ALPHA_xxx constants

Definition at line 777 of file imgconvert.c.

static int is_yuv_planar ( enum PixelFormat  fmt  )  [inline, static]

Definition at line 638 of file imgconvert.c.

Referenced by av_picture_crop(), and av_picture_pad().


Variable Documentation

const PixFmtInfo pix_fmt_info[PIX_FMT_NB] [static]

Definition at line 65 of file imgconvert.c.


Generated on Fri Oct 26 02:43:48 2012 for FFmpeg by  doxygen 1.5.8