36#define RADIUS_MAX 10.0
56 double w =
f->kernel(x,
f->params);
58 w *=
f->window(x /
f->radius,
f->params);
73 return (dst_pos + 0.5) * ratio_inv - 0.5 +
offset;
77 double radius,
double ratio_inv,
double stretch_inv,
78 int dst_pos,
double *
tmp)
80 int *
out = &
f->weights[dst_pos *
f->filter_size];
81 int *
pos = &
f->offsets[dst_pos];
83 const double src_pos =
get_src_pos(dst_pos, ratio_inv,
f->offset);
84 if (
f->filter_size == 1) {
91 const int start =
floor(src_pos - radius) + 1;
92 const int stop =
ceil (src_pos + radius) - 1;
93 const int clamped =
av_clip(start, 0,
f->src_size -
f->filter_size);
102 const double base = stretch_inv * (clamped - src_pos);
103 double wsum_pos = 0.0, wsum_neg = 0.0;
104 for (
int i = 0;
i <
f->filter_size;
i++) {
109 i0 = start - clamped;
110 if (
i ==
f->filter_size - 1)
114 for (
int k = i0; k <= i1; k++)
124 const double wsum = wsum_pos + wsum_neg;
129 int sum_pos = 0, sum_neg = 0;
130 for (
int i = 0;
i <
f->filter_size;
i++) {
131 if (
i ==
f->filter_size - 1) {
145 if (sum_pos >
f->sum_positive)
146 f->sum_positive = sum_pos;
147 if (sum_neg < f->sum_negative)
148 f->sum_negative = sum_neg;
162 return fun->
params[0] >= 0.0;
166 return fun->
params[0] >= 0.0 && fun->
params[0] <= 1.0 &&
180 const double step = 1e-2;
182 double radius =
bound;
183 double prev = 0.0, fprev = 1.0;
184 double integral = 0.0;
185 for (
double x = step; x <
bound + step; x += step) {
187 integral += (fprev + fx) * step;
189 if ((fprev > cutoff && fx <= cutoff) || (fprev < -cutoff && fx >= -cutoff)) {
192 double estimate = fx + (fx > fprev ? cutoff : -cutoff);
193 double root = x - estimate * (x - prev) / (fx - fprev);
213 double virtual_size =
params->virtual_size;
215 virtual_size =
params->dst_size;
217 const double ratio = virtual_size /
params->src_size;
218 const double ratio_inv = 1.0 / ratio;
219 double stretch = 1.0, stretch_inv = 1.0;
222 stretch = 1.0 / ratio;
267 for (
int i = 0;
i <
params->dst_size;
i++) {
270 const int start =
floor(src_pos - radius) + 1;
271 const int stop =
ceil (src_pos + radius) - 1;
272 const int taps =
av_clip(stop - start + 1, 1,
params->src_size);
275 }
else if (taps > filter_size) {
277 if (taps ==
params->src_size)
289 filter->virtual_size = virtual_size;
291 filter->filter_size = filter_size;
292 if (
filter->filter_size == 1)
299 const size_t padded =
filter->num_weights +
319 for (
int i = 0;
i <
params->dst_size;
i++)
358 const double edge = 0.5 - 0.5 *
w;
361 return fmax(1.0 - (x - edge) /
w, 0.0);
376 return 0.5 + 0.5 * cos(
M_PI * x);
381 return 0.54 + 0.46 * cos(
M_PI * x);
392 double y = x * x / 4.0;
413 double a0 = (1 -
a) / 2.0,
a1 = 1 / 2.0,
a2 =
a / 2.0;
415 return a0 +
a1 * cos(x) +
a2 * cos(2 * x);
421 return (1.0 - x) * cos(
pix) + sin(
pix) /
M_PI;
432 return 1.0 - 4.0/3.0 * (x * x);
434 return 2.0 / 3.0 * (x - 1.5) * (x - 1.5);
451 return 2.0 * j1(x) / x;
459 return 3.0 * (sin(x) - x * cos(x)) / (x * x * x);
465 double p0 = 6.0 - 2.0 *
b,
466 p2 = -18.0 + 12.0 *
b + 6.0 *
c,
467 p3 = 12.0 - 9.0 *
b - 6.0 *
c,
468 q0 = 8.0 *
b + 24.0 *
c,
469 q1 = -12.0 *
b - 48.0 *
c,
470 q2 = 6.0 *
b + 30.0 *
c,
474 return (p0 + x * x * (p2 + x * p3)) / p0;
476 return (
q0 + x * (
q1 + x * (q2 + x * q3))) / p0;
483 return ((d * x +
c) * x +
b) * x +
a;
486 b + 2.0 *
c + 3.0 * d,
488 -
b - 3.0 *
c - 6.0 * d,
495 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)
static __device__ float floor(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]
const char * ff_sws_scaler_name(SwsScaler scaler)
Return the friendly name of a given scaler enum, or NULL if invalid.
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 double area(double x, const double *params)
Overlap between a destination pixel (unit box) and a source pixel of width params[0] <= 1,...
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 double get_src_pos(int dst_pos, double ratio_inv, double offset)
Explanation of the 0.5 offsets: Normally, pixel samples are assumed to be representative of the cente...
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 av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
static const int16_t alpha[]
Macro definitions for various function/variable attributes.
@ 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_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 * ff_refstruct_calloc(size_t n, size_t size)
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)