FFmpeg
Macros | Functions | Variables
swscale.c File Reference
#include <inttypes.h>
#include "config.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/x86/cpu.h"
#include "libavutil/cpu.h"
#include "libavutil/mem_internal.h"
#include "libavutil/pixdesc.h"

Go to the source code of this file.

Macros

#define YUV2YUVX_FUNC_MMX(opt, step)
 
#define YUV2YUVX_FUNC(opt, step)
 
#define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt)
 
#define SCALE_FUNCS(filter_n, opt)
 
#define SCALE_FUNCS_MMX(opt)
 
#define SCALE_FUNCS_SSE(opt)
 
#define VSCALEX_FUNC(size, opt)
 
#define VSCALEX_FUNCS(opt)
 
#define VSCALE_FUNC(size, opt)
 
#define VSCALE_FUNCS(opt1, opt2)
 
#define INPUT_Y_FUNC(fmt, opt)
 
#define INPUT_UV_FUNC(fmt, opt)
 
#define INPUT_FUNC(fmt, opt)
 
#define INPUT_FUNCS(opt)
 
#define RANGE_CONVERT_FUNCS(opt)
 
#define RANGE_CONVERT_FUNCS_DECL(opt)
 
#define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2)
 
#define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit)
 
#define ASSIGN_VSCALE_FUNC(vscalefn, opt)
 
#define case_rgb(x, X, opt)
 
#define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2)
 

Functions

 SCALE_FUNCS_SSE (sse2)
 
 SCALE_FUNCS_SSE (ssse3)
 
 SCALE_FUNCS_SSE (sse4)
 
 SCALE_FUNC (4, 8, 15, avx2)
 
 SCALE_FUNC (X4, 8, 15, avx2)
 
 VSCALEX_FUNC (8, mmxext)
 
 VSCALEX_FUNCS (sse2)
 
 VSCALEX_FUNCS (sse4)
 
 VSCALEX_FUNC (16, sse4)
 
 VSCALEX_FUNCS (avx)
 
 VSCALE_FUNCS (sse2, sse2)
 
 VSCALE_FUNC (16, sse4)
 
 VSCALE_FUNCS (avx, avx)
 
 INPUT_FUNCS (sse2)
 
 INPUT_FUNCS (ssse3)
 
 INPUT_FUNCS (avx)
 
 INPUT_FUNC (rgba, avx2)
 
 INPUT_FUNC (bgra, avx2)
 
 INPUT_FUNC (argb, avx2)
 
 INPUT_FUNC (abgr, avx2)
 
 INPUT_FUNC (rgb24, avx2)
 
 INPUT_FUNC (bgr24, avx2)
 
 RANGE_CONVERT_FUNCS_DECL (sse2)
 
 RANGE_CONVERT_FUNCS_DECL (avx2)
 
av_cold void ff_sws_init_range_convert_x86 (SwsInternal *c)
 
av_cold void ff_sws_init_swscale_x86 (SwsInternal *c)
 

Variables

const uint64_t ff_dither4 [2]
 
const uint64_t ff_dither8 [2]
 

Macro Definition Documentation

◆ YUV2YUVX_FUNC_MMX

#define YUV2YUVX_FUNC_MMX (   opt,
  step 
)
Value:
void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
uint8_t *dest, int dstW, \
const uint8_t *dither, int offset); \
static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
const int16_t **src, uint8_t *dest, int dstW, \
const uint8_t *dither, int offset) \
{ \
if(dstW > 0) \
ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, dstW + offset, dither, offset); \
return; \
}

Definition at line 182 of file swscale.c.

◆ YUV2YUVX_FUNC

#define YUV2YUVX_FUNC (   opt,
  step 
)
Value:
void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
uint8_t *dest, int dstW, \
const uint8_t *dither, int offset); \
static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
const int16_t **src, uint8_t *dest, int dstW, \
const uint8_t *dither, int offset) \
{ \
int remainder = (dstW % step); \
int pixelsProcessed = dstW - remainder; \
if(((uintptr_t)dest) & 15){ \
yuv2yuvX_mmxext(filter, filterSize, src, dest, dstW, dither, offset); \
return; \
} \
if(pixelsProcessed > 0) \
ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, pixelsProcessed + offset, dither, offset); \
if(remainder > 0){ \
ff_yuv2yuvX_mmxext(filter, filterSize - 1, pixelsProcessed, dest - offset, pixelsProcessed + remainder + offset, dither, offset); \
} \
return; \
}

Definition at line 195 of file swscale.c.

◆ SCALE_FUNC

#define SCALE_FUNC (   filter_n,
  from_bpc,
  to_bpc,
  opt 
)
Value:
void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
SwsInternal *c, int16_t *data, \
int dstW, const uint8_t *src, \
const int16_t *filter, \
const int32_t *filterPos, int filterSize)

Definition at line 227 of file swscale.c.

◆ SCALE_FUNCS

#define SCALE_FUNCS (   filter_n,
  opt 
)
Value:
SCALE_FUNC(filter_n, 8, 15, opt); \
SCALE_FUNC(filter_n, 9, 15, opt); \
SCALE_FUNC(filter_n, 10, 15, opt); \
SCALE_FUNC(filter_n, 12, 15, opt); \
SCALE_FUNC(filter_n, 14, 15, opt); \
SCALE_FUNC(filter_n, 16, 15, opt); \
SCALE_FUNC(filter_n, 8, 19, opt); \
SCALE_FUNC(filter_n, 9, 19, opt); \
SCALE_FUNC(filter_n, 10, 19, opt); \
SCALE_FUNC(filter_n, 12, 19, opt); \
SCALE_FUNC(filter_n, 14, 19, opt); \
SCALE_FUNC(filter_n, 16, 19, opt)

Definition at line 234 of file swscale.c.

◆ SCALE_FUNCS_MMX

#define SCALE_FUNCS_MMX (   opt)
Value:
SCALE_FUNCS(4, opt); \
SCALE_FUNCS(8, opt); \
SCALE_FUNCS(X, opt)

Definition at line 248 of file swscale.c.

◆ SCALE_FUNCS_SSE

#define SCALE_FUNCS_SSE (   opt)
Value:
SCALE_FUNCS(4, opt); \
SCALE_FUNCS(8, opt); \
SCALE_FUNCS(X4, opt); \
SCALE_FUNCS(X8, opt)

Definition at line 253 of file swscale.c.

◆ VSCALEX_FUNC

#define VSCALEX_FUNC (   size,
  opt 
)
Value:
void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
const int16_t **src, uint8_t *dest, int dstW, \
const uint8_t *dither, int offset)

Definition at line 266 of file swscale.c.

◆ VSCALEX_FUNCS

#define VSCALEX_FUNCS (   opt)
Value:
VSCALEX_FUNC(8, opt); \
VSCALEX_FUNC(9, opt); \
VSCALEX_FUNC(10, opt)

Definition at line 270 of file swscale.c.

◆ VSCALE_FUNC

#define VSCALE_FUNC (   size,
  opt 
)
Value:
void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
const uint8_t *dither, int offset)

Definition at line 281 of file swscale.c.

◆ VSCALE_FUNCS

#define VSCALE_FUNCS (   opt1,
  opt2 
)
Value:
VSCALE_FUNC(8, opt1); \
VSCALE_FUNC(9, opt2); \
VSCALE_FUNC(10, opt2); \
VSCALE_FUNC(16, opt1)

Definition at line 284 of file swscale.c.

◆ INPUT_Y_FUNC

#define INPUT_Y_FUNC (   fmt,
  opt 
)
Value:
void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
const uint8_t *unused1, const uint8_t *unused2, \
int w, uint32_t *unused, void *opq)

Definition at line 294 of file swscale.c.

◆ INPUT_UV_FUNC

#define INPUT_UV_FUNC (   fmt,
  opt 
)
Value:
void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
const uint8_t *unused0, \
const uint8_t *src1, \
const uint8_t *src2, \
int w, uint32_t *unused, void *opq)

Definition at line 298 of file swscale.c.

◆ INPUT_FUNC

#define INPUT_FUNC (   fmt,
  opt 
)
Value:
INPUT_Y_FUNC(fmt, opt); \
INPUT_UV_FUNC(fmt, opt)

Definition at line 304 of file swscale.c.

◆ INPUT_FUNCS

#define INPUT_FUNCS (   opt)
Value:
INPUT_FUNC(uyvy, opt); \
INPUT_FUNC(yuyv, opt); \
INPUT_UV_FUNC(nv12, opt); \
INPUT_UV_FUNC(nv21, opt); \
INPUT_FUNC(rgba, opt); \
INPUT_FUNC(bgra, opt); \
INPUT_FUNC(argb, opt); \
INPUT_FUNC(abgr, opt); \
INPUT_FUNC(rgb24, opt); \
INPUT_FUNC(bgr24, opt)

Definition at line 307 of file swscale.c.

◆ RANGE_CONVERT_FUNCS

#define RANGE_CONVERT_FUNCS (   opt)
Value:
do { \
if (c->dstBpc <= 14) { \
if (c->opts.src_range) { \
c->lumConvertRange = ff_lumRangeFromJpeg_ ##opt; \
c->chrConvertRange = ff_chrRangeFromJpeg_ ##opt; \
} else { \
c->lumConvertRange = ff_lumRangeToJpeg_ ##opt; \
c->chrConvertRange = ff_chrRangeToJpeg_ ##opt; \
} \
} \
} while (0)

Definition at line 454 of file swscale.c.

◆ RANGE_CONVERT_FUNCS_DECL

#define RANGE_CONVERT_FUNCS_DECL (   opt)
Value:
void ff_lumRangeFromJpeg_ ##opt(int16_t *dst, int width); \
void ff_chrRangeFromJpeg_ ##opt(int16_t *dstU, int16_t *dstV, int width); \
void ff_lumRangeToJpeg_ ##opt(int16_t *dst, int width); \
void ff_chrRangeToJpeg_ ##opt(int16_t *dstU, int16_t *dstV, int width); \

Definition at line 466 of file swscale.c.

◆ ASSIGN_SCALE_FUNC2

#define ASSIGN_SCALE_FUNC2 (   hscalefn,
  filtersize,
  opt1,
  opt2 
)
Value:
do { \
if (c->srcBpc == 8) { \
hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
ff_hscale8to19_ ## filtersize ## _ ## opt1; \
} else if (c->srcBpc == 9) { \
hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
ff_hscale9to19_ ## filtersize ## _ ## opt1; \
} else if (c->srcBpc == 10) { \
hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
ff_hscale10to19_ ## filtersize ## _ ## opt1; \
} else if (c->srcBpc == 12) { \
hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
ff_hscale12to19_ ## filtersize ## _ ## opt1; \
} else if (c->srcBpc == 14 || ((c->opts.src_format==AV_PIX_FMT_PAL8||isAnyRGB(c->opts.src_format)) && av_pix_fmt_desc_get(c->opts.src_format)->comp[0].depth<16)) { \
hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
ff_hscale14to19_ ## filtersize ## _ ## opt1; \
} else { /* c->srcBpc == 16 */ \
av_assert0(c->srcBpc == 16);\
hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
ff_hscale16to19_ ## filtersize ## _ ## opt1; \
} \
} while (0)

◆ ASSIGN_VSCALEX_FUNC

#define ASSIGN_VSCALEX_FUNC (   vscalefn,
  opt,
  do_16_case,
  condition_8bit 
)
Value:
switch(c->dstBpc){ \
case 16: do_16_case; break; \
case 10: if (!isBE(c->opts.dst_format) && !isSemiPlanarYUV(c->opts.dst_format)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
case 9: if (!isBE(c->opts.dst_format)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
}

◆ ASSIGN_VSCALE_FUNC

#define ASSIGN_VSCALE_FUNC (   vscalefn,
  opt 
)
Value:
switch(c->dstBpc){ \
case 16: if (!isBE(c->opts.dst_format)) vscalefn = ff_yuv2plane1_16_ ## opt; break; \
case 10: if (!isBE(c->opts.dst_format) && !isSemiPlanarYUV(c->opts.dst_format)) vscalefn = ff_yuv2plane1_10_ ## opt; break; \
case 9: if (!isBE(c->opts.dst_format)) vscalefn = ff_yuv2plane1_9_ ## opt; break; \
case 8: vscalefn = ff_yuv2plane1_8_ ## opt; break; \
default: av_assert0(c->dstBpc>8); \
}

◆ case_rgb

#define case_rgb (   x,
  X,
  opt 
)
Value:
case AV_PIX_FMT_ ## X: \
c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
if (!c->chrSrcHSubSample) \
c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
break

◆ ASSIGN_SSE_SCALE_FUNC

#define ASSIGN_SSE_SCALE_FUNC (   hscalefn,
  filtersize,
  opt1,
  opt2 
)
Value:
switch (filtersize) { \
case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
break; \
}

Function Documentation

◆ SCALE_FUNCS_SSE() [1/3]

SCALE_FUNCS_SSE ( sse2  )

◆ SCALE_FUNCS_SSE() [2/3]

SCALE_FUNCS_SSE ( ssse3  )

◆ SCALE_FUNCS_SSE() [3/3]

SCALE_FUNCS_SSE ( sse4  )

◆ SCALE_FUNC() [1/2]

SCALE_FUNC ( ,
,
15  ,
avx2   
)

◆ SCALE_FUNC() [2/2]

SCALE_FUNC ( X4  ,
,
15  ,
avx2   
)

◆ VSCALEX_FUNC() [1/2]

VSCALEX_FUNC ( ,
mmxext   
)

◆ VSCALEX_FUNCS() [1/3]

VSCALEX_FUNCS ( sse2  )

◆ VSCALEX_FUNCS() [2/3]

VSCALEX_FUNCS ( sse4  )

◆ VSCALEX_FUNC() [2/2]

VSCALEX_FUNC ( 16  ,
sse4   
)

◆ VSCALEX_FUNCS() [3/3]

VSCALEX_FUNCS ( avx  )

◆ VSCALE_FUNCS() [1/2]

VSCALE_FUNCS ( sse2  ,
sse2   
)

◆ VSCALE_FUNC()

VSCALE_FUNC ( 16  ,
sse4   
)

◆ VSCALE_FUNCS() [2/2]

VSCALE_FUNCS ( avx  ,
avx   
)

◆ INPUT_FUNCS() [1/3]

INPUT_FUNCS ( sse2  )

◆ INPUT_FUNCS() [2/3]

INPUT_FUNCS ( ssse3  )

◆ INPUT_FUNCS() [3/3]

INPUT_FUNCS ( avx  )

◆ INPUT_FUNC() [1/6]

INPUT_FUNC ( rgba  ,
avx2   
)

◆ INPUT_FUNC() [2/6]

INPUT_FUNC ( bgra  ,
avx2   
)

◆ INPUT_FUNC() [3/6]

INPUT_FUNC ( argb  ,
avx2   
)

◆ INPUT_FUNC() [4/6]

INPUT_FUNC ( abgr  ,
avx2   
)

◆ INPUT_FUNC() [5/6]

INPUT_FUNC ( rgb24  ,
avx2   
)

◆ INPUT_FUNC() [6/6]

INPUT_FUNC ( bgr24  ,
avx2   
)

◆ RANGE_CONVERT_FUNCS_DECL() [1/2]

RANGE_CONVERT_FUNCS_DECL ( sse2  )

◆ RANGE_CONVERT_FUNCS_DECL() [2/2]

RANGE_CONVERT_FUNCS_DECL ( avx2  )

◆ ff_sws_init_range_convert_x86()

av_cold void ff_sws_init_range_convert_x86 ( SwsInternal c)

Definition at line 475 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ ff_sws_init_swscale_x86()

av_cold void ff_sws_init_swscale_x86 ( SwsInternal c)

Definition at line 485 of file swscale.c.

Referenced by ff_sws_init_scale().

Variable Documentation

◆ ff_dither4

const uint64_t ff_dither4[2]
Initial value:
= {
0x0103010301030103LL,
0x0200020002000200LL,}

Definition at line 33 of file swscale.c.

◆ ff_dither8

const uint64_t ff_dither8[2]
Initial value:
= {
0x0602060206020602LL,
0x0004000400040004LL,}

Definition at line 37 of file swscale.c.

av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
src1
const pixel * src1
Definition: h264pred_template.c:421
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
w
uint8_t w
Definition: llviddspenc.c:38
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
SCALE_FUNCS
#define SCALE_FUNCS(filter_n, opt)
Definition: swscale.c:234
data
const char data[16]
Definition: mxf.c:149
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
INPUT_Y_FUNC
#define INPUT_Y_FUNC(fmt, opt)
Definition: swscale.c:294
INPUT_FUNC
#define INPUT_FUNC(fmt, opt)
Definition: swscale.c:304
to
const char * to
Definition: webvttdec.c:35
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
SCALE_FUNC
#define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt)
Definition: swscale.c:227
isSemiPlanarYUV
static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:755
VSCALEX_FUNC
#define VSCALEX_FUNC(size, opt)
Definition: swscale.c:266
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
isBE
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:730
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
X
@ X
Definition: vf_addroi.c:27
isAnyRGB
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:838
size
int size
Definition: twinvq_data.h:10344
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
src2
const pixel * src2
Definition: h264pred_template.c:422
ASSIGN_SCALE_FUNC2
#define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2)
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:84
SwsInternal
Definition: swscale_internal.h:317
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
_
#define _
VSCALE_FUNC
#define VSCALE_FUNC(size, opt)
Definition: swscale.c:281
int32_t
int32_t
Definition: audioconvert.c:56
width
#define width
Definition: dsp.h:85
src
#define src
Definition: vp8dsp.c:248
dither
static const uint8_t dither[8][8]
Definition: vf_fspp.c:62