History

avfilter/vf_geq: allow user to set interpolation method

Paul B Mahol committed 7 years ago

Commit 8a0d45a1 parent 996ff3f2 files · +35 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +8 −0
  2. libavfilter/vf_geq.c +27 −0
doc/filters.texi+8−0
@@ -11019,6 +11019,14 @@ red/green/blue component. Return 0 if there is no such component. · 11018 unmodified lines
1101911019 @item alpha(x, y)
1102011020 Return the value of the pixel at location (@var{x},@var{y}) of the alpha
1102111021 plane. Return 0 if there is no such plane.
11022+
11023+@item interpolation
11024+Set one of interpolation methods:
11025+@table @option
11026+@item nearest, n
11027+@item bilinear, b
11028+@end table
11029+Default is bilinear.
1102211030 @end table
1102311031
1102411032 For functions, if @var{x} and @var{y} are outside the area, the value will be
libavfilter/vf_geq.c+27−0
@@ -33,6 +33,12 @@ · 32 unmodified lines
3333 #include "libavutil/pixdesc.h"
3434 #include "internal.h"
3535
36+enum InterpolationMethods {
37+ INTERP_NEAREST,
38+ INTERP_BILINEAR,
39+ NB_INTERP
40+};
41+
3642 static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
3743 enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_SW, VAR_SH, VAR_T, VAR_VARS_NB };
3844
@@ -46,6 +52,7 @@ typedef struct GEQContext { · 7 unmodified lines
4652 double values[VAR_VARS_NB]; ///< expression values
4753 int hsub, vsub; ///< chroma subsampling
4854 int planes; ///< number of planes
55+ int interpolation;
4956 int is_rgb;
5057 int bps;
5158 } GEQContext;
@@ -70,6 +77,12 @@ static const AVOption geq_options[] = { · 18 unmodified lines
7077 { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
7178 { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
7279 { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
80+ { "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" },
81+ { "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" },
82+ { "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" },
83+ { "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" },
84+ { "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" },
85+ { "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" },
7386 {NULL},
7487 };
7588
@@ -88,6 +101,7 @@ static inline double getpix(void *priv, double x, double y, int plane) · 12 unmodified lines
88101 if (!src)
89102 return 0;
90103
104+ if (geq->interpolation == INTERP_BILINEAR) {
91105 xi = x = av_clipd(x, 0, w - 2);
92106 yi = y = av_clipd(y, 0, h - 2);
93107
@@ -104,6 +118,19 @@ static inline double getpix(void *priv, double x, double y, int plane) · 10 unmodified lines
104118 return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
105119 + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
106120 }
121+ } else {
122+ xi = av_clipd(x, 0, w - 1);
123+ yi = av_clipd(y, 0, h - 1);
124+
125+ if (geq->bps > 8) {
126+ const uint16_t *src16 = (const uint16_t*)src;
127+ linesize /= 2;
128+
129+ return src16[xi + yi * linesize];
130+ } else {
131+ return src[xi + yi * linesize];
132+ }
133+ }
107134 }
108135
109136 //TODO: cubic interpolate

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t