Go to the documentation of this file.
37 #define RADIUS_MAX 10.0
58 double w =
f->kernel(x,
f->params);
60 w *=
f->window(x /
f->radius,
f->params);
65 double radius,
double ratio_inv,
double stretch_inv,
66 int dst_pos,
double *
tmp)
68 int *
out = &
f->weights[dst_pos *
f->filter_size];
69 int *
pos = &
f->offsets[dst_pos];
80 const double src_pos = (dst_pos + 0.5) * ratio_inv - 0.5 +
f->offset;
81 if (
f->filter_size == 1) {
88 const double start_pos = src_pos - radius;
90 start_idx =
FFMAX(start_idx, 0);
91 start_idx =
FFMIN(start_idx,
f->src_size -
f->filter_size);
92 const double offset = start_idx - src_pos;
102 double wsum_pos = 0.0, wsum_neg = 0.0;
103 for (
int i = 0;
i <
f->filter_size;
i++) {
111 const double wsum = wsum_pos + wsum_neg;
116 int sum_pos = 0, sum_neg = 0;
117 for (
int i = 0;
i <
f->filter_size;
i++) {
118 if (
i ==
f->filter_size - 1) {
132 if (sum_pos >
f->sum_positive)
133 f->sum_positive = sum_pos;
134 if (sum_neg < f->sum_negative)
135 f->sum_negative = sum_neg;
149 return fun->
params[0] >= 0.0;
153 return fun->
params[0] < 3.0;
162 const double step = 1e-2;
164 double radius =
bound;
165 double prev = 0.0, fprev = 1.0;
166 double integral = 0.0;
169 integral += (fprev + fx) *
step;
171 if ((fprev > cutoff && fx <= cutoff) || (fprev < -cutoff && fx >= -cutoff)) {
174 double estimate = fx + (fx > fprev ? cutoff : -cutoff);
175 double root = x - estimate * (x - prev) / (fx - fprev);
199 const double ratio = virtual_size / params->
src_size;
200 double stretch = 1.0;
203 stretch = 1.0 / ratio;
235 int filter_size =
ceil(radius * 2.0);
248 filter->virtual_size = virtual_size;
250 filter->filter_size = filter_size;
251 if (
filter->filter_size == 1)
276 const double ratio_inv = 1.0 / ratio, stretch_inv = 1.0 / stretch;
321 return 0.5 + 0.5 * cos(
M_PI * x);
326 return 0.54 + 0.46 * cos(
M_PI * x);
337 double y = x * x / 4.0;
357 double a = params[0];
358 double a0 = (1 -
a) / 2.0,
a1 = 1 / 2.0,
a2 =
a / 2.0;
360 return a0 +
a1 * cos(x) +
a2 * cos(2 * x);
366 return (1.0 - x) * cos(
pix) + sin(
pix) /
M_PI;
371 return exp(-params[0] * x * x);
377 return 1.0 - 4.0/3.0 * (x * x);
379 return 2.0 / 3.0 * (x - 1.5) * (x - 1.5);
396 return 2.0 * j1(x) / x;
404 return 3.0 * (sin(x) - x * cos(x)) / (x * x * x);
409 const double b = params[0],
c = params[1];
410 double p0 = 6.0 - 2.0 *
b,
411 p2 = -18.0 + 12.0 *
b + 6.0 *
c,
412 p3 = 12.0 - 9.0 *
b - 6.0 *
c,
413 q0 = 8.0 *
b + 24.0 *
c,
414 q1 = -12.0 *
b - 48.0 *
c,
415 q2 = 6.0 *
b + 30.0 *
c,
419 return (p0 + x * x * (p2 + x * p3)) / p0;
421 return (
q0 + x * (
q1 + x * (q2 + x * q3))) / p0;
428 return ((d * x +
c) * x +
b) * x +
a;
431 b + 2.0 *
c + 3.0 * d,
433 -
b - 3.0 *
c - 6.0 * d,
440 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.
#define SWS_MAX_REDUCE_CUTOFF
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.
@ SWS_SCALE_GAUSSIAN
2-tap gaussian approximation
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)
double virtual_size
The virtual output size.
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
@ SWS_FILTER_SCALE
14-bit coefficients are picked to fit comfortably within int16_t for efficient SIMD processing (e....
static av_unused double welch(double x, const double *params)
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
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)
static __device__ float ceil(float a)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double scaler_sample(const SwsFilterFunction *f, double x)
double offset
The sample offset, in units of input pixels.
#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.
@ SWS_SCALE_NB
not part of the ABI
static av_unused double bessel_i0(double x)
static av_unused double hamming(double x, const double *params)
@ SWS_SCALE_AREA
area averaging
#define SWS_PARAM_DEFAULT
static av_unused double kaiser(double x, const double *params)
static const uint8_t q0[256]
static __device__ float fabs(float a)
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
@ SWS_SCALE_BILINEAR
bilinear filtering
static av_unused double triangle(double x, const double *params)
@ SWS_SCALE_SPLINE
unwindowned natural cubic spline
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
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)
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
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)
static av_unused double box(double x, const double *params)
static av_always_inline av_const double round(double x)
#define SWS_NUM_SCALER_PARAMS
double scaler_params[SWS_NUM_SCALER_PARAMS]
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)
@ SWS_SCALE_SINC
unwindowed sinc
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)
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)