FFmpeg
Loading...
Searching...
No Matches
filters.c File Reference
#include <math.h>
#include <stdbool.h>
#include <libavutil/attributes.h>
#include <libavutil/avassert.h>
#include <libavutil/mem.h>
#include "filters.h"

Go to the source code of this file.

Data Structures

struct  SwsFilterFunction
 

Macros

#define RADIUS_MAX   10.0
 

Typedefs

typedef double(* SwsFilterKernel) (double x, const double *params)
 

Functions

static double scaler_sample (const SwsFilterFunction *f, double x)
 
static void compute_row (SwsFilterWeights *f, const SwsFilterFunction *fun, double radius, double ratio_inv, double stretch_inv, int dst_pos, double *tmp)
 
static void sws_filter_free (AVRefStructOpaque opaque, void *obj)
 
static bool validate_params (const SwsFilterFunction *fun, SwsScaler scaler)
 
static double est_filter_radius (const SwsFilterFunction *fun)
 Numerically estimate the last intersection between the function value and the cutoff domain [-SWS_MAX_REDUCE_CUTOFF, SWS_MAX_REDUCE_CUTOFF].
 
int ff_sws_filter_generate (void *log, const SwsFilterParams *params, SwsFilterWeights **out)
 Generate a filter kernel for the given parameters.
 
static av_unused double box (double x, const double *params)
 
static av_unused double triangle (double x, const double *params)
 
static av_unused double cosine (double x, const double *params)
 
static av_unused double hann (double x, const double *params)
 
static av_unused double hamming (double x, const double *params)
 
static av_unused double welch (double x, const double *params)
 
static av_unused double bessel_i0 (double x)
 
static av_unused double kaiser (double x, const double *params)
 
static av_unused double blackman (double x, const double *params)
 
static av_unused double bohman (double x, const double *params)
 
static av_unused double gaussian (double x, const double *params)
 
static av_unused double quadratic (double x, const double *params)
 
static av_unused double sinc (double x, const double *params)
 
static av_unused double jinc (double x, const double *params)
 
static av_unused double sphinx (double x, const double *params)
 
static av_unused double cubic (double x, const double *params)
 
static double spline_coeff (double a, double b, double c, double d, double x)
 
static av_unused double spline (double x, const double *params)
 

Variables

static const SwsFilterFunction filter_functions [SWS_SCALE_NB]
 

Macro Definition Documentation

◆ RADIUS_MAX

#define RADIUS_MAX   10.0

Definition at line 35 of file filters.c.

Typedef Documentation

◆ SwsFilterKernel

typedef double(* SwsFilterKernel) (double x, const double *params)

Definition at line 38 of file filters.c.

Function Documentation

◆ scaler_sample()

static double scaler_sample ( const SwsFilterFunction * f,
double x )
static

Definition at line 50 of file filters.c.

Referenced by compute_row(), and est_filter_radius().

◆ compute_row()

static void compute_row ( SwsFilterWeights * f,
const SwsFilterFunction * fun,
double radius,
double ratio_inv,
double stretch_inv,
int dst_pos,
double * tmp )
static

Explanation of the 0.5 offsets: Normally, pixel samples are assumed to be representative of the center of their containing area; e.g. for a 2x2 image, the samples are located at {0.5, 1.5}^2. However, with integer indexing, we round sample positions down (0-based indexing). So the (0, 0) sample is actually located at (0.5, 0.5) and represents the entire square from (0,0) to (1,1). When normalizing between different image sizes, we therefore need to add/subtract off these 0.5 offsets.

Generate raw filter weights with maximum precision. Sum the positive and negative weights separately to avoid catastrophic cancellation. This summation order should already give the best precision because abs(w) is monotonically decreasing

Definition at line 62 of file filters.c.

Referenced by ff_sws_filter_generate().

◆ sws_filter_free()

static void sws_filter_free ( AVRefStructOpaque opaque,
void * obj )
static

Definition at line 136 of file filters.c.

Referenced by ff_sws_filter_generate().

◆ validate_params()

static bool validate_params ( const SwsFilterFunction * fun,
SwsScaler scaler )
static

Definition at line 143 of file filters.c.

Referenced by ff_sws_filter_generate().

◆ est_filter_radius()

static double est_filter_radius ( const SwsFilterFunction * fun)
static

Numerically estimate the last intersection between the function value and the cutoff domain [-SWS_MAX_REDUCE_CUTOFF, SWS_MAX_REDUCE_CUTOFF].

Definition at line 161 of file filters.c.

Referenced by ff_sws_filter_generate().

◆ ff_sws_filter_generate()

int ff_sws_filter_generate ( void * log_ctx,
const SwsFilterParams * params,
SwsFilterWeights ** out )

Generate a filter kernel for the given parameters.

The generated filter is allocated as a refstruct and must be unref'd by the caller.

Returns 0 or a negative error code. In particular, this may return:

SWS_SCALE_AREA is a pseudo-filter that is equivalent to bilinear filtering for upscaling (since bilinear just evenly mixes samples according to the relative distance), and equivalent to (anti-aliased) point sampling for downscaling.

Definition at line 187 of file filters.c.

Referenced by check_filter(), and cudascale_filter_init().

◆ box()

◆ triangle()

static av_unused double triangle ( double x,
const double * params )
static

Definition at line 325 of file filters.c.

◆ cosine()

static av_unused double cosine ( double x,
const double * params )
static

Definition at line 330 of file filters.c.

Referenced by set_ap(), set_hp(), and set_lp().

◆ hann()

static av_unused double hann ( double x,
const double * params )
static

Definition at line 335 of file filters.c.

◆ hamming()

static av_unused double hamming ( double x,
const double * params )
static

Definition at line 340 of file filters.c.

◆ welch()

static av_unused double welch ( double x,
const double * params )
static

Definition at line 345 of file filters.c.

◆ bessel_i0()

static av_unused double bessel_i0 ( double x)
static

Definition at line 350 of file filters.c.

Referenced by kaiser().

◆ kaiser()

static av_unused double kaiser ( double x,
const double * params )
static

Definition at line 364 of file filters.c.

◆ blackman()

static av_unused double blackman ( double x,
const double * params )
static

Definition at line 371 of file filters.c.

◆ bohman()

static av_unused double bohman ( double x,
const double * params )
static

Definition at line 379 of file filters.c.

◆ gaussian()

static av_unused double gaussian ( double x,
const double * params )
static

Definition at line 385 of file filters.c.

◆ quadratic()

static av_unused double quadratic ( double x,
const double * params )
static

Definition at line 390 of file filters.c.

◆ sinc()

static av_unused double sinc ( double x,
const double * params )
static

Definition at line 399 of file filters.c.

Referenced by AVFILTER_DEFINE_CLASS().

◆ jinc()

static av_unused double jinc ( double x,
const double * params )
static

Definition at line 407 of file filters.c.

◆ sphinx()

static av_unused double sphinx ( double x,
const double * params )
static

Definition at line 415 of file filters.c.

◆ cubic()

static av_unused double cubic ( double x,
const double * params )
static

Definition at line 423 of file filters.c.

◆ spline_coeff()

static double spline_coeff ( double a,
double b,
double c,
double d,
double x )
static

Definition at line 441 of file filters.c.

Referenced by spline(), and spline_coeff().

◆ spline()

static av_unused double spline ( double x,
const double * params )
static

Definition at line 454 of file filters.c.

Variable Documentation

◆ filter_functions

static const SwsFilterFunction filter_functions
static
Initial value:
= {
[SWS_SCALE_BILINEAR] = { "bilinear", 1.0, triangle },
[SWS_SCALE_BICUBIC] = { "bicubic", 2.0, cubic, .params = { 0.0, 0.6 } },
[SWS_SCALE_POINT] = { "point", 0.5, box },
[SWS_SCALE_GAUSSIAN] = { "gaussian", 4.0, gaussian, .params = { 3.0 } },
[SWS_SCALE_SINC] = { "sinc", RADIUS_MAX, sinc },
[SWS_SCALE_LANCZOS] = { "lanczos", -1.0, sinc, sinc, .params = { 3.0 } },
[SWS_SCALE_SPLINE] = { "spline", RADIUS_MAX, spline },
}
static av_unused double cubic(double x, const double *params)
Definition filters.c:423
static av_unused double sinc(double x, const double *params)
Definition filters.c:399
static av_unused double spline(double x, const double *params)
Definition filters.c:454
static av_unused double box(double x, const double *params)
Definition filters.c:320
static av_unused double triangle(double x, const double *params)
Definition filters.c:325
@ SWS_SCALE_SPLINE
unwindowned natural cubic spline
Definition swscale.h:105
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
Definition swscale.h:100
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
Definition swscale.h:104
@ SWS_SCALE_BILINEAR
bilinear filtering
Definition swscale.h:98
@ SWS_SCALE_GAUSSIAN
2-tap gaussian approximation
Definition swscale.h:102
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
Definition swscale.h:99
@ SWS_SCALE_SINC
unwindowed sinc
Definition swscale.h:103
static float gaussian(float sigma, float x)
#define RADIUS_MAX
Definition vf_sab.c:69

Definition at line 48 of file filters.c.

Referenced by ff_sws_filter_generate().