Go to the documentation of this file.
35 #define RADIUS_MAX 10.0
56 double w =
f->kernel(x,
f->params);
58 w *=
f->window(x /
f->radius,
f->params);
63 double radius,
double ratio_inv,
double stretch_inv,
64 int dst_pos,
double *
tmp)
66 int *
out = &
f->weights[dst_pos *
f->filter_size];
67 int *
pos = &
f->offsets[dst_pos];
78 const double src_pos = (dst_pos + 0.5) * ratio_inv - 0.5;
79 if (
f->filter_size == 1) {
86 const double start_pos = src_pos - radius;
88 start_idx =
FFMAX(start_idx, 0);
89 start_idx =
FFMIN(start_idx,
f->src_size -
f->filter_size);
90 const double offset = start_idx - src_pos;
100 double wsum_pos = 0.0, wsum_neg = 0.0;
101 for (
int i = 0;
i <
f->filter_size;
i++) {
109 const double wsum = wsum_pos + wsum_neg;
114 int sum_pos = 0, sum_neg = 0;
115 for (
int i = 0;
i <
f->filter_size;
i++) {
116 if (
i ==
f->filter_size - 1) {
130 if (sum_pos >
f->sum_positive)
131 f->sum_positive = sum_pos;
132 if (sum_neg < f->sum_negative)
133 f->sum_negative = sum_neg;
147 return fun->
params[0] >= 0.0;
151 return fun->
params[0] < 3.0;
160 const double step = 1e-2;
162 double radius =
bound;
163 double prev = 0.0, fprev = 1.0;
164 double integral = 0.0;
167 integral += (fprev + fx) *
step;
169 if ((fprev > cutoff && fx <= cutoff) || (fprev < -cutoff && fx >= -cutoff)) {
172 double estimate = fx + (fx > fprev ? cutoff : -cutoff);
173 double root = x - estimate * (x - prev) / (fx - fprev);
194 double stretch = 1.0;
197 stretch = 1.0 / ratio;
229 int filter_size =
ceil(radius * 2.0);
242 filter->filter_size = filter_size;
243 if (
filter->filter_size == 1)
268 const double ratio_inv = 1.0 / ratio, stretch_inv = 1.0 / stretch;
313 return 0.5 + 0.5 * cos(
M_PI * x);
318 return 0.54 + 0.46 * cos(
M_PI * x);
329 double y = x * x / 4.0;
349 double a = params[0];
350 double a0 = (1 -
a) / 2.0,
a1 = 1 / 2.0,
a2 =
a / 2.0;
352 return a0 +
a1 * cos(x) +
a2 * cos(2 * x);
358 return (1.0 - x) * cos(
pix) + sin(
pix) /
M_PI;
363 return exp(-params[0] * x * x);
369 return 1.0 - 4.0/3.0 * (x * x);
371 return 2.0 / 3.0 * (x - 1.5) * (x - 1.5);
388 return 2.0 * j1(x) / x;
396 return 3.0 * (sin(x) - x * cos(x)) / (x * x * x);
401 const double b = params[0],
c = params[1];
402 double p0 = 6.0 - 2.0 *
b,
403 p2 = -18.0 + 12.0 *
b + 6.0 *
c,
404 p3 = 12.0 - 9.0 *
b - 6.0 *
c,
405 q0 = 8.0 *
b + 24.0 *
c,
406 q1 = -12.0 *
b - 48.0 *
c,
407 q2 = 6.0 *
b + 30.0 *
c,
411 return (p0 + x * x * (p2 + x * p3)) / p0;
413 return (
q0 + x * (
q1 + x * (q2 + x * q3))) / p0;
420 return ((d * x +
c) * x +
b) * x +
a;
423 b + 2.0 *
c + 3.0 * d,
425 -
b - 3.0 *
c - 6.0 * d,
432 const double p = -2.196152422706632;
static void error(const char *err)
static const uint8_t q1[256]
static av_unused double bohman(double x, const double *params)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int src_size
The relative sizes of the input and output images.
@ SWS_SCALE_BILINEAR
bilinear filtering
RefStruct is an API for creating reference-counted objects with minimal overhead.
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
Represents a computed filter kernel.
void(* filter)(uint8_t *src, int stride, int qscale)
double params[SWS_NUM_SCALER_PARAMS]
static av_unused double gaussian(double x, const double *params)
@ SWS_FILTER_SCALE
14-bit coefficients are picked to fit comfortably within int16_t for efficient SIMD processing (e....
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
static av_unused double welch(double x, const double *params)
static double a2(void *priv, double x, double y)
static const SwsFilterFunction filter_functions[SWS_SCALE_NB]
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
static __device__ float ceil(float a)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define SWS_MAX_REDUCE_CUTOFF
Filter kernel cut-off value.
static double scaler_sample(const SwsFilterFunction *f, double x)
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_unused double bessel_i0(double x)
static av_unused double hamming(double x, const double *params)
static av_unused double kaiser(double x, const double *params)
static const uint8_t q0[256]
static __device__ float fabs(float a)
static av_unused double triangle(double x, const double *params)
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
@ SWS_SCALE_SINC
unwindowed sinc
#define SWS_PARAM_DEFAULT
static av_unused double cosine(double x, const double *params)
static av_unused double hann(double x, const double *params)
static av_unused double jinc(double x, const double *params)
#define i(width, name, range_min, range_max)
double fmin(double, double)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static double a0(void *priv, double x, double y)
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
static av_unused double cubic(double x, const double *params)
static av_unused double quadratic(double x, const double *params)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
static void sws_filter_free(AVRefStructOpaque opaque, void *obj)
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
static av_unused double box(double x, const double *params)
static av_always_inline av_const double round(double x)
double scaler_params[SWS_NUM_SCALER_PARAMS]
@ SWS_SCALE_GAUSSIAN
2-tap gaussian approximation
static double bound(const double threshold, const double val)
static bool validate_params(const SwsFilterFunction *fun, SwsScaler scaler)
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_unused double blackman(double x, const double *params)
double fmax(double, double)
#define SWS_NUM_SCALER_PARAMS
Extra parameters for fine-tuning certain scalers.
@ SWS_SCALE_NB
not part of the ABI
@ SWS_SCALE_SPLINE
unwindowned natural cubic spline
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static double filter_radius(const SwsFilterFunction *fun)
static const int16_t alpha[]
static double spline_coeff(double a, double b, double c, double d, double x)
static av_unused double sinc(double x, const double *params)
@ SWS_SCALE_AREA
area averaging
static av_unused double sphinx(double x, const double *params)
double(* SwsFilterKernel)(double x, const double *params)
static double a1(void *priv, double x, double y)
SwsScaler scaler
The filter kernel and parameters to use.
static av_unused double spline(double x, const double *params)
static void compute_row(SwsFilterWeights *f, const SwsFilterFunction *fun, double radius, double ratio_inv, double stretch_inv, int dst_pos, double *tmp)