History

avfilter/vf_estdif: export distance cost as filter option

Paul B Mahol committed 5 years ago

Commit dcf83fd1 parent 45dc6682 files · +16 −10Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_estdif.c +12 −10
doc/filters.texi+4−0
@@ -11711,6 +11711,10 @@ Allowed range is from 1 to 15. · 11710 unmodified lines
1171111711 Specify the search radius for best edge matching. Default value is 2.
1171211712 Allowed range is from 0 to 15.
1171311713
11714+@item dcost
11715+Specify the distance cost for edge matching. Default value is 0.5.
11716+Allowed range is from 0 to 1.
11717+
1171411718 @item interp
1171511719 Specify the interpolation used. Default is 4-point interpolation. It accepts one
1171611720 of the following values:
libavfilter/vf_estdif.c+12−10
@@ -35,6 +35,7 @@ typedef struct ESTDIFContext { · 34 unmodified lines
3535 int deint; ///< which frames to deinterlace
3636 int rslope; ///< best edge slope search radius
3737 int redge; ///< best edge match search radius
38+ float dcost; ///< distance cost for edge matching
3839 int interp; ///< type of interpolation
3940 int linesize[4]; ///< bytes of pixel data per line for each plane
4041 int planewidth[4]; ///< width of each plane
@@ -42,7 +43,7 @@ typedef struct ESTDIFContext { · 1 unmodified line
4243 int field; ///< which field are we on, 0 or 1
4344 int eof;
4445 int depth;
45− int half;
46+ int max;
4647 int nb_planes;
4748 int nb_threads;
4849 int64_t pts;
@@ -52,7 +53,7 @@ typedef struct ESTDIFContext { · 3 unmodified lines
5253 const uint8_t *prev_line, const uint8_t *next_line,
5354 const uint8_t *prev2_line, const uint8_t *next2_line,
5455 const uint8_t *prev3_line, const uint8_t *next3_line,
55− int x, int width, int rslope, int redge, unsigned half,
56+ int x, int width, int rslope, int redge,
5657 int depth, int *K);
5758
5859 unsigned (*mid_8[3])(const uint8_t *const prev,
@@ -92,6 +93,7 @@ static const AVOption estdif_options[] = { · 33 unmodified lines
9293 CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
9394 { "rslope", "specify the search radius for edge slope tracing", OFFSET(rslope), AV_OPT_TYPE_INT, {.i64=1}, 1, MAX_R, FLAGS, },
9495 { "redge", "specify the search radius for best edge matching", OFFSET(redge), AV_OPT_TYPE_INT, {.i64=2}, 0, MAX_R, FLAGS, },
96+ { "dcost", "specify the distance cost for edge matching", OFFSET(dcost), AV_OPT_TYPE_FLOAT,{.dbl=0.5}, 0, 1, FLAGS, },
9597 { "interp", "specify the type of interpolation", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, FLAGS, "interp" },
9698 CONST("2p", "two-point interpolation", 0, "interp"),
9799 CONST("4p", "four-point interpolation", 1, "interp"),
@@ -239,7 +241,7 @@ static unsigned cost_##ss(const type *const prev, \ · 141 unmodified lines
239241 COST(uint8_t, 8)
240242 COST(uint16_t, 16)
241243
242−#define INTERPOLATE(type, atype, max, ss) \
244+#define INTERPOLATE(type, atype, amax, ss) \
243245 static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \
244246 const uint8_t *const pprev_line, \
245247 const uint8_t *const nnext_line, \
@@ -248,7 +250,7 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ · 2 unmodified lines
248250 const uint8_t *const pprev3_line, \
249251 const uint8_t *const nnext3_line, \
250252 int x, int width, int rslope, \
251− int redge, unsigned h, int depth, \
253+ int redge, int depth, \
252254 int *K) \
253255 { \
254256 type *dst = (type *)ddst; \
@@ -259,10 +261,11 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ · 4 unmodified lines
259261 const type *const next2_line = (const type *const)nnext2_line; \
260262 const type *const next3_line = (const type *const)nnext3_line; \
261263 const int interp = s->interp; \
264+ const int dcost = s->dcost * s->max; \
262265 const int end = width - 1; \
263266 const atype f = redge + 2; \
264267 atype sd[S], sD[S], di = 0; \
265− atype dmin = max; \
268+ atype dmin = amax; \
266269 int k = *K; \
267270 \
268271 for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) { \
@@ -276,7 +279,7 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ · 7 unmodified lines
276279 \
277280 sD[i + rslope] = sum; \
278281 sD[i + rslope] += f * cost_##ss(prev_line, next_line, end, x, i); \
279− sD[i + rslope] += h * abs(i); \
282+ sD[i + rslope] += dcost * abs(i); \
280283 \
281284 dmin = FFMIN(sD[i + rslope], dmin); \
282285 } \
@@ -292,7 +295,7 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ · 9 unmodified lines
292295 \
293296 sd[i + rslope] = sum; \
294297 sd[i + rslope] += f * cost_##ss(prev_line, next_line, end, x, k + i); \
295− sd[i + rslope] += h * abs(k + i); \
298+ sd[i + rslope] += dcost * abs(k + i); \
296299 \
297300 dmin = FFMIN(sd[i + rslope], dmin); \
298301 } \
@@ -332,7 +335,6 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 33 unmodified lines
332335 AVFrame *in = td->in;
333336 const int rslope = s->rslope;
334337 const int redge = s->redge;
335− const int half = s->half;
336338 const int depth = s->depth;
337339 const int interlaced = in->interlaced_frame;
338340 const int tff = (s->field == (s->parity == -1 ? interlaced ? in->top_field_first : 1 :
@@ -411,7 +413,7 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 72 unmodified lines
411413 prev_line, next_line,
412414 prev2_line, next2_line,
413415 prev3_line, next3_line,
414− x, width, rslope, redge, half, depth, &k);
416+ x, width, rslope, redge, depth, &k);
415417 }
416418
417419 out_line += 2 * dst_linesize;
@@ -475,7 +477,7 @@ static int config_input(AVFilterLink *inlink) · 57 unmodified lines
475477 s->mid_16[0] = mid2_16;
476478 s->mid_16[1] = mid4_16;
477479 s->mid_16[2] = mid6_16;
478− s->half = 1 << (s->depth - 1);
480+ s->max = (1 << (s->depth)) - 1;
479481
480482 return 0;
481483 }

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