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 +
f->offset;
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;
164 const double step = 1e-2;
166 double radius =
bound;
167 double prev = 0.0, fprev = 1.0;
168 double integral = 0.0;
169 for (
double x = step; x <
bound + step; x += step) {
171 integral += (fprev + fx) * step;
173 if ((fprev > cutoff && fx <= cutoff) || (fprev < -cutoff && fx >= -cutoff)) {
176 double estimate = fx + (fx > fprev ? cutoff : -cutoff);
177 double root = x - estimate * (x - prev) / (fx - fprev);
197 double virtual_size =
params->virtual_size;
199 virtual_size =
params->dst_size;
201 const double ratio = virtual_size /
params->src_size;
202 double stretch = 1.0;
205 stretch = 1.0 / ratio;
251 int filter_size =
ceil(radius * 2.0);
252 filter_size =
FFMIN(filter_size,
params->src_size);
264 filter->virtual_size = virtual_size;
266 filter->filter_size = filter_size;
267 if (
filter->filter_size == 1)
292 const double ratio_inv = 1.0 / ratio, stretch_inv = 1.0 / stretch;
293 for (
int i = 0;
i <
params->dst_size;
i++)
337 return 0.5 + 0.5 * cos(
M_PI * x);
342 return 0.54 + 0.46 * cos(
M_PI * x);
353 double y = x * x / 4.0;
374 double a0 = (1 -
a) / 2.0,
a1 = 1 / 2.0,
a2 =
a / 2.0;
376 return a0 +
a1 * cos(x) +
a2 * cos(2 * x);
382 return (1.0 - x) * cos(
pix) + sin(
pix) /
M_PI;
393 return 1.0 - 4.0/3.0 * (x * x);
395 return 2.0 / 3.0 * (x - 1.5) * (x - 1.5);
412 return 2.0 * j1(x) / x;
420 return 3.0 * (sin(x) - x * cos(x)) / (x * x * x);
426 double p0 = 6.0 - 2.0 *
b,
427 p2 = -18.0 + 12.0 *
b + 6.0 *
c,
428 p3 = 12.0 - 9.0 *
b - 6.0 *
c,
429 q0 = 8.0 *
b + 24.0 *
c,
430 q1 = -12.0 *
b - 48.0 *
c,
431 q2 = 6.0 *
b + 30.0 *
c,
435 return (p0 + x * x * (p2 + x * p3)) / p0;
437 return (
q0 + x * (
q1 + x * (q2 + x * q3))) / p0;
444 return ((d * x +
c) * x +
b) * x +
a;
447 b + 2.0 *
c + 3.0 * d,
449 -
b - 3.0 *
c - 6.0 * d,
456 const double p = -2.196152422706632;
SwsAArch64OpImplParams params
static double bound(const double threshold, const double val)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
static __device__ float ceil(float a)
static __device__ float fabs(float a)
double fmin(double, double)
double fmax(double, double)
static av_unused double kaiser(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)
static av_unused double hamming(double x, const double *params)
static av_unused double blackman(double x, const double *params)
static av_unused double bessel_i0(double x)
static av_unused double bohman(double x, const double *params)
static double est_filter_radius(const SwsFilterFunction *fun)
Numerically estimate the last intersection between the function value and the cutoff domain [-SWS_MAX...
static const SwsFilterFunction filter_functions[SWS_SCALE_NB]
static bool validate_params(const SwsFilterFunction *fun, SwsScaler scaler)
static av_unused double hann(double x, const double *params)
static av_unused double gaussian(double x, const double *params)
static av_unused double sphinx(double x, const double *params)
static double spline_coeff(double a, double b, double c, double d, double x)
static double scaler_sample(const SwsFilterFunction *f, double x)
double(* SwsFilterKernel)(double x, const double *params)
static av_unused double cubic(double x, const double *params)
static av_unused double cosine(double x, const double *params)
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
static av_unused double sinc(double x, const double *params)
static av_unused double spline(double x, const double *params)
static av_unused double welch(double x, const double *params)
static av_unused double jinc(double x, const double *params)
static void sws_filter_free(AVRefStructOpaque opaque, void *obj)
static av_unused double box(double x, const double *params)
static av_unused double triangle(double x, const double *params)
static av_unused double quadratic(double x, const double *params)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define SWS_MAX_REDUCE_CUTOFF
Filter kernel cut-off value.
#define SWS_PARAM_DEFAULT
@ SWS_SCALE_SPLINE
unwindowned natural cubic spline
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
@ SWS_SCALE_NB
not part of the ABI
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
@ SWS_SCALE_BILINEAR
bilinear filtering
@ SWS_SCALE_GAUSSIAN
2-tap gaussian approximation
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
@ SWS_SCALE_AREA
area averaging
@ SWS_SCALE_SINC
unwindowed sinc
static const int16_t alpha[]
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Macro definitions for various function/variable attributes.
static av_always_inline av_const double round(double x)
@ SWS_FILTER_SCALE
14-bit coefficients are picked to fit comfortably within int16_t for efficient SIMD processing (e....
Memory handling functions.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
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.
double params[SWS_NUM_SCALER_PARAMS]
Represents a computed filter kernel.
#define SWS_NUM_SCALER_PARAMS
Extra parameters for fine-tuning certain scalers.
static void error(const char *err)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static const uint8_t q1[256]
static const uint8_t q0[256]
RefStruct is an API for creating reference-counted objects with minimal overhead.
static float gaussian(float sigma, float x)
static double a0(void *priv, double x, double y)
static double a2(void *priv, double x, double y)
static double a1(void *priv, double x, double y)