37 #include "libavutil/avassert.h"
39 #include "libavutil/common.h"
40 #include "libavutil/pixdesc.h"
41 #include "libavutil/imgutils.h"
47 #define FF_COLOR_NA -1
48 #define FF_COLOR_RGB 0
49 #define FF_COLOR_GRAY 1
50 #define FF_COLOR_YUV 2
51 #define FF_COLOR_YUV_JPEG 3
54 #define deinterlace_line_inplace ff_deinterlace_line_inplace_mmx
55 #define deinterlace_line ff_deinterlace_line_mmx
57 #define deinterlace_line_inplace deinterlace_line_inplace_c
58 #define deinterlace_line deinterlace_line_c
61 #define pixdesc_has_alpha(pixdesc) \
62 ((pixdesc)->nb_components == 2 || (pixdesc)->nb_components == 4 || (pixdesc)->flags & AV_PIX_FMT_FLAG_PAL)
80 if(desc->
name && !strncmp(desc->
name,
"yuvj", 4))
102 *min = INT_MAX, *max = -INT_MAX;
112 unsigned *lossp,
unsigned consider)
116 int src_color, dst_color;
117 int src_min_depth, src_max_depth, dst_min_depth, dst_max_depth;
118 int ret, loss, i, nb_components;
119 int score = INT_MAX - 1;
127 if (dst_pix_fmt == src_pix_fmt)
139 for (i = 0; i < nb_components; i++)
184 if (src_color != dst_color)
188 if(loss & FF_LOSS_COLORSPACE)
222 enum AVPixelFormat src_pix_fmt,
int has_alpha,
int *loss_ptr)
225 int loss1, loss2, loss_mask;
230 loss_mask= loss_ptr?~*loss_ptr:~0;
238 if (score1 == score2) {
245 dst_pix_fmt = score1 < score2 ? dst_pix_fmt2 : dst_pix_fmt1;
253 #if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
256 int has_alpha,
int *loss_ptr){
261 enum AVPixelFormat src_pix_fmt,
int has_alpha,
int *loss_ptr)
269 int has_alpha,
int *loss_ptr){
289 for(;height > 0; height--) {
293 for(w = width;w >= 4; w-=4) {
294 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
295 d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
296 d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
297 d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
303 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
322 for(;height > 0; height--) {
328 for(w = width;w > 0; w--) {
329 d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
330 s2[0] + s2[1] + s2[2] + s2[3] +
331 s3[0] + s3[1] + s3[2] + s3[3] +
332 s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
351 for(;height > 0; height--) {
352 for(w = width;w > 0; w--) {
355 tmp += src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7];
358 *(dst++) = (tmp + 32)>>6;
359 src += 8 - 8*src_wrap;
361 src += 8*src_wrap - 8*
width;
362 dst += dst_wrap -
width;
370 int planes[4] = { 0 };
402 dst->
data[1] = src->
data[1] + ((top_band >> y_shift) * src->
linesize[1]) + (left_band >> x_shift);
403 dst->
data[2] = src->
data[2] + ((top_band >> y_shift) * src->
linesize[2]) + (left_band >> x_shift);
405 if(top_band % (1<<y_shift) || left_band % (1<<x_shift))
432 for (i = 0; i < 3; i++) {
436 if (padtop || padleft) {
437 memset(dst->
data[i], color[i],
438 dst->
linesize[i] * (padtop >> y_shift) + (padleft >> x_shift));
441 if (padleft || padright) {
442 optr = dst->
data[i] + dst->
linesize[i] * (padtop >> y_shift) +
443 (dst->
linesize[i] - (padright >> x_shift));
444 yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
445 for (y = 0; y < yheight; y++) {
446 memset(optr, color[i], (padleft + padright) >> x_shift);
453 optr = dst->
data[i] + dst->
linesize[i] * (padtop >> y_shift) +
454 (padleft >> x_shift);
455 memcpy(optr, iptr, (width - padleft - padright) >> x_shift);
457 optr = dst->
data[i] + dst->
linesize[i] * (padtop >> y_shift) +
458 (dst->
linesize[i] - (padright >> x_shift));
459 yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
460 for (y = 0; y < yheight; y++) {
461 memset(optr, color[i], (padleft + padright) >> x_shift);
462 memcpy(optr + ((padleft + padright) >> x_shift), iptr,
463 (width - padleft - padright) >> x_shift);
469 if (padbottom || padright) {
471 ((height - padbottom) >> y_shift) - (padright >> x_shift);
472 memset(optr, color[i],dst->
linesize[i] *
473 (padbottom >> y_shift) + (padright >> x_shift));
479 #if FF_API_DEINTERLACE
481 #if !HAVE_MMX_EXTERNAL
483 static void deinterlace_line_c(
uint8_t *dst,
492 for(;size > 0;size--) {
494 sum += lum_m3[0] << 2;
495 sum += lum_m2[0] << 1;
496 sum += lum_m1[0] << 2;
498 dst[0] = cm[(sum + 4) >> 3];
508 static void deinterlace_line_inplace_c(
uint8_t *lum_m4,
uint8_t *lum_m3,
515 for(;size > 0;size--) {
517 sum += lum_m3[0] << 2;
518 sum += lum_m2[0] << 1;
520 sum += lum_m1[0] << 2;
522 lum_m2[0] = cm[(sum + 4) >> 3];
535 static void deinterlace_bottom_field(
uint8_t *dst,
int dst_wrap,
536 const uint8_t *src1,
int src_wrap,
539 const uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
544 src_0=&src_m1[src_wrap];
545 src_p1=&src_0[src_wrap];
546 src_p2=&src_p1[src_wrap];
547 for(y=0;y<(height-2);y+=2) {
548 memcpy(dst,src_m1,width);
554 src_p1 += 2*src_wrap;
555 src_p2 += 2*src_wrap;
558 memcpy(dst,src_m1,width);
564 static void deinterlace_bottom_field_inplace(
uint8_t *src1,
int src_wrap,
565 int width,
int height)
567 uint8_t *src_m1, *src_0, *src_p1, *src_p2;
573 memcpy(buf,src_m1,width);
574 src_0=&src_m1[src_wrap];
575 src_p1=&src_0[src_wrap];
576 src_p2=&src_p1[src_wrap];
577 for(y=0;y<(height-2);y+=2) {
581 src_p1 += 2*src_wrap;
582 src_p2 += 2*src_wrap;
602 if ((width & 3) != 0 || (height & 3) != 0)
628 deinterlace_bottom_field_inplace(dst->
data[i], dst->
linesize[i],
651 if(!desc || !desc->
name) {
static int get_pix_fmt_depth(int *min, int *max, enum AVPixelFormat pix_fmt)
#define deinterlace_line_inplace
#define FF_LOSS_COLORQUANT
loss due to color quantization
attribute_deprecated int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height)
deinterlace - if not supported return -1
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
static int is_yuv_planar(const AVPixFmtDescriptor *desc)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Various defines for YUV<->RGB conversion.
int av_picture_crop(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int top_band, int left_band)
Crop image top and left side.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt, unsigned *lossp, unsigned consider)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
int avcodec_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...
#define FF_COLOR_YUV_JPEG
YUV color space.
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
enum AVPixelFormat pix_fmt
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
uint16_t depth_minus1
number of bits in the component minus 1
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *pix_fmt_list, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Find the best pixel format to convert to given a certain source pixel format.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Libavcodec external API header.
AVPixelFormat
Pixel format.
#define FF_LOSS_ALPHA
loss of alpha bits
uint8_t nb_components
The number of components each pixel has, (1-4)
void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void avcodec_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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
#define pixdesc_has_alpha(pixdesc)
enum AVPixelFormat avcodec_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)
Find the best pixel format to convert to given a certain source pixel format and a selection of two d...
attribute_deprecated enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define AV_LOG_INFO
Standard information.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FF_COLOR_RGB
RGB color space.
#define FF_LOSS_CHROMA
loss of chroma (e.g.
#define FF_LOSS_DEPTH
loss due to color depth change
BYTE int const BYTE int int int height
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
static int get_color_type(const AVPixFmtDescriptor *desc)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define FF_LOSS_COLORSPACE
loss due to color space conversion
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
static double lum(void *priv, double x, double y)
uint16_t plane
which of the 4 planes contains the component
common internal api header.
#define FF_COLOR_GRAY
gray color space
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright, int *color)
Pad image.
#define FF_COLOR_YUV
YUV color space.
#define FF_LOSS_RESOLUTION
loss due to resolution change
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 ...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
8 bit with PIX_FMT_RGB32 palette
int main(int argc, char **argv)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...