diff options
author | Paul B Mahol <onemda@gmail.com> | 2021-11-09 08:58:38 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2021-11-09 09:49:39 +0100 |
commit | dcf83fd59d42b8ee6a601cdf9fc8946a1aa30520 (patch) | |
tree | 5760ef92d035cd171955ebaa7060f79a8d92edad /libavfilter/vf_estdif.c | |
parent | 45dc668aea0edac34969b5a1ff76cf9ad3a09be1 (diff) | |
download | ffmpeg-dcf83fd59d42b8ee6a601cdf9fc8946a1aa30520.tar.gz |
avfilter/vf_estdif: export distance cost as filter option
Diffstat (limited to 'libavfilter/vf_estdif.c')
-rw-r--r-- | libavfilter/vf_estdif.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/libavfilter/vf_estdif.c b/libavfilter/vf_estdif.c index a8ef93826c..4469cb11bf 100644 --- a/libavfilter/vf_estdif.c +++ b/libavfilter/vf_estdif.c @@ -35,6 +35,7 @@ typedef struct ESTDIFContext { int deint; ///< which frames to deinterlace int rslope; ///< best edge slope search radius int redge; ///< best edge match search radius + float dcost; ///< distance cost for edge matching int interp; ///< type of interpolation int linesize[4]; ///< bytes of pixel data per line for each plane int planewidth[4]; ///< width of each plane @@ -42,7 +43,7 @@ typedef struct ESTDIFContext { int field; ///< which field are we on, 0 or 1 int eof; int depth; - int half; + int max; int nb_planes; int nb_threads; int64_t pts; @@ -52,7 +53,7 @@ typedef struct ESTDIFContext { const uint8_t *prev_line, const uint8_t *next_line, const uint8_t *prev2_line, const uint8_t *next2_line, const uint8_t *prev3_line, const uint8_t *next3_line, - int x, int width, int rslope, int redge, unsigned half, + int x, int width, int rslope, int redge, int depth, int *K); unsigned (*mid_8[3])(const uint8_t *const prev, @@ -92,6 +93,7 @@ static const AVOption estdif_options[] = { CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"), { "rslope", "specify the search radius for edge slope tracing", OFFSET(rslope), AV_OPT_TYPE_INT, {.i64=1}, 1, MAX_R, FLAGS, }, { "redge", "specify the search radius for best edge matching", OFFSET(redge), AV_OPT_TYPE_INT, {.i64=2}, 0, MAX_R, FLAGS, }, + { "dcost", "specify the distance cost for edge matching", OFFSET(dcost), AV_OPT_TYPE_FLOAT,{.dbl=0.5}, 0, 1, FLAGS, }, { "interp", "specify the type of interpolation", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, FLAGS, "interp" }, CONST("2p", "two-point interpolation", 0, "interp"), CONST("4p", "four-point interpolation", 1, "interp"), @@ -239,7 +241,7 @@ static unsigned cost_##ss(const type *const prev, \ COST(uint8_t, 8) COST(uint16_t, 16) -#define INTERPOLATE(type, atype, max, ss) \ +#define INTERPOLATE(type, atype, amax, ss) \ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ const uint8_t *const pprev_line, \ const uint8_t *const nnext_line, \ @@ -248,7 +250,7 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ const uint8_t *const pprev3_line, \ const uint8_t *const nnext3_line, \ int x, int width, int rslope, \ - int redge, unsigned h, int depth, \ + int redge, int depth, \ int *K) \ { \ type *dst = (type *)ddst; \ @@ -259,10 +261,11 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ const type *const next2_line = (const type *const)nnext2_line; \ const type *const next3_line = (const type *const)nnext3_line; \ const int interp = s->interp; \ + const int dcost = s->dcost * s->max; \ const int end = width - 1; \ const atype f = redge + 2; \ atype sd[S], sD[S], di = 0; \ - atype dmin = max; \ + atype dmin = amax; \ int k = *K; \ \ for (int i = -rslope; i <= rslope && abs(k) > rslope; i++) { \ @@ -276,7 +279,7 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ \ sD[i + rslope] = sum; \ sD[i + rslope] += f * cost_##ss(prev_line, next_line, end, x, i); \ - sD[i + rslope] += h * abs(i); \ + sD[i + rslope] += dcost * abs(i); \ \ dmin = FFMIN(sD[i + rslope], dmin); \ } \ @@ -292,7 +295,7 @@ static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \ \ sd[i + rslope] = sum; \ sd[i + rslope] += f * cost_##ss(prev_line, next_line, end, x, k + i); \ - sd[i + rslope] += h * abs(k + i); \ + sd[i + rslope] += dcost * abs(k + i); \ \ dmin = FFMIN(sd[i + rslope], dmin); \ } \ @@ -332,7 +335,6 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, AVFrame *in = td->in; const int rslope = s->rslope; const int redge = s->redge; - const int half = s->half; const int depth = s->depth; const int interlaced = in->interlaced_frame; 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, prev_line, next_line, prev2_line, next2_line, prev3_line, next3_line, - x, width, rslope, redge, half, depth, &k); + x, width, rslope, redge, depth, &k); } out_line += 2 * dst_linesize; @@ -475,7 +477,7 @@ static int config_input(AVFilterLink *inlink) s->mid_16[0] = mid2_16; s->mid_16[1] = mid4_16; s->mid_16[2] = mid6_16; - s->half = 1 << (s->depth - 1); + s->max = (1 << (s->depth)) - 1; return 0; } |