aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2019-10-30 10:14:23 +0100
committerPaul B Mahol <onemda@gmail.com>2019-10-31 10:32:43 +0100
commitb414cff6304071d5ef1e2b0a1b407e4fe3f58092 (patch)
treeb2f50e9c78ec257a5086053b5915e95799a6786d
parent86a42e954e8e75175a65ef93d05fece8e001e36b (diff)
downloadffmpeg-b414cff6304071d5ef1e2b0a1b407e4fe3f58092.tar.gz
avfilter/vf_median: add radiusV option
-rw-r--r--doc/filters.texi7
-rw-r--r--libavfilter/median.h1
-rw-r--r--libavfilter/median_template.c15
-rw-r--r--libavfilter/vf_median.c10
4 files changed, 21 insertions, 12 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index 9d387be1f5..7e9d50782a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -12919,11 +12919,16 @@ This filter accepts the following options:
@table @option
@item radius
-Set horizontal and vertical radius size. Default value is @code{1}.
+Set horizontal radius size. Default value is @code{1}.
Allowed range is integer from 1 to 127.
@item planes
Set which planes to process. Default is @code{15}, which is all available planes.
+
+@item radiusV
+Set vertical radius size. Default value is @code{0}.
+Allowed range is integer from 0 to 127.
+If it is 0, value will be picked from horizontal @code{radius} option.
@end table
@section mergeplanes
diff --git a/libavfilter/median.h b/libavfilter/median.h
index bb07fddd5d..89ae0472b0 100644
--- a/libavfilter/median.h
+++ b/libavfilter/median.h
@@ -30,6 +30,7 @@ typedef struct MedianContext {
int planes;
int radius;
+ int radiusV;
int planewidth[4];
int planeheight[4];
diff --git a/libavfilter/median_template.c b/libavfilter/median_template.c
index 6953a23a5b..bb7646e0eb 100644
--- a/libavfilter/median_template.c
+++ b/libavfilter/median_template.c
@@ -57,6 +57,7 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_
htype *ccoarse = s->coarse[jobnr];
htype *cfine = s->fine[jobnr];
const int radius = s->radius;
+ const int radiusV = s->radiusV;
const int t = s->t;
const pixel *src = (const pixel *)ssrc;
pixel *dst = (pixel *)ddst;
@@ -69,16 +70,16 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_
memset(cfine, 0, s->fine_size * sizeof(*cfine));
memset(ccoarse, 0, s->coarse_size * sizeof(*ccoarse));
- srcp = src + FFMAX(0, slice_h_start - radius) * src_linesize;
+ srcp = src + FFMAX(0, slice_h_start - radiusV) * src_linesize;
if (jobnr == 0) {
for (int i = 0; i < width; i++) {
- cfine[PICK_FINE_BIN(width, srcp[i], i)] += radius + 1;
- ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radius + 1;
+ cfine[PICK_FINE_BIN(width, srcp[i], i)] += radiusV + 1;
+ ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radiusV + 1;
}
}
- srcp = src + FFMAX(0, slice_h_start - radius - (jobnr != 0)) * src_linesize;
- for (int i = 0; i < radius + (jobnr != 0) * (1 + radius); i++) {
+ srcp = src + FFMAX(0, slice_h_start - radiusV - (jobnr != 0)) * src_linesize;
+ for (int i = 0; i < radiusV + (jobnr != 0) * (1 + radiusV); i++) {
for (int j = 0; j < width; j++) {
cfine[PICK_FINE_BIN(width, srcp[j], j)]++;
ccoarse[PICK_COARSE_BIN(j, srcp[j])]++;
@@ -93,13 +94,13 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_
htype fine[BINS][BINS] = { { 0 } };
htype luc[BINS] = { 0 };
- p = srcp + src_linesize * FFMAX(0, i - radius - 1);
+ p = srcp + src_linesize * FFMAX(0, i - radiusV - 1);
for (int j = 0; j < width; j++) {
cfine[PICK_FINE_BIN(width, p[j], j)]--;
ccoarse[PICK_COARSE_BIN(j, p[j])]--;
}
- p = srcp + src_linesize * FFMIN(height - 1, i + radius);
+ p = srcp + src_linesize * FFMIN(height - 1, i + radiusV);
for (int j = 0; j < width; j++) {
cfine[PICK_FINE_BIN(width, p[j], j)]++;
ccoarse[PICK_COARSE_BIN(j, p[j])]++;
diff --git a/libavfilter/vf_median.c b/libavfilter/vf_median.c
index 98296bcc2b..49f2351518 100644
--- a/libavfilter/vf_median.c
+++ b/libavfilter/vf_median.c
@@ -59,6 +59,7 @@
static const AVOption median_options[] = {
{ "radius", "set median radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=1}, 1, 127, FLAGS },
{ "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS },
+ { "radiusV", "set median vertical radius", OFFSET(radiusV), AV_OPT_TYPE_INT, {.i64=0},0, 127, FLAGS },
{ NULL }
};
@@ -119,8 +120,9 @@ static int config_input(AVFilterLink *inlink)
s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
s->planeheight[0] = s->planeheight[3] = inlink->h;
+ s->radiusV = !s->radiusV ? s->radius : s->radiusV;
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
- s->t = 2 * s->radius * s->radius + 2 * s->radius;
+ s->t = 2 * s->radius * s->radiusV + 2 * s->radius;
for (int i = 0; i < s->nb_planes; i++) {
if (!(s->planes & (1 << i)))
@@ -131,13 +133,13 @@ static int config_input(AVFilterLink *inlink)
return AVERROR(EINVAL);
}
- if (s->planeheight[i] < s->radius * 2 + 1) {
- av_log(inlink->dst, AV_LOG_ERROR, "The %d plane height %d must be not less than %d\n", i, s->planeheight[i], s->radius * 2 + 1);
+ if (s->planeheight[i] < s->radiusV * 2 + 1) {
+ av_log(inlink->dst, AV_LOG_ERROR, "The %d plane height %d must be not less than %d\n", i, s->planeheight[i], s->radiusV * 2 + 1);
return AVERROR(EINVAL);
}
}
- s->nb_threads = FFMAX(1, FFMIN(s->planeheight[1] / (s->radius + 1), ff_filter_get_nb_threads(inlink->dst)));
+ s->nb_threads = FFMAX(1, FFMIN(s->planeheight[1] / (s->radiusV + 1), ff_filter_get_nb_threads(inlink->dst)));
s->bins = 1 << ((s->depth + 1) / 2);
s->fine_size = s->bins * s->bins * inlink->w;
s->coarse_size = s->bins * inlink->w;