forked from FFmpeg/FFmpeg
avfilter/vf_median: add radiusV option
This commit is contained in:
parent
86a42e954e
commit
b414cff630
4 changed files with 21 additions and 12 deletions
|
@ -12919,11 +12919,16 @@ This filter accepts the following options:
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
@item radius
|
@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.
|
Allowed range is integer from 1 to 127.
|
||||||
|
|
||||||
@item planes
|
@item planes
|
||||||
Set which planes to process. Default is @code{15}, which is all available 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
|
@end table
|
||||||
|
|
||||||
@section mergeplanes
|
@section mergeplanes
|
||||||
|
|
|
@ -30,6 +30,7 @@ typedef struct MedianContext {
|
||||||
|
|
||||||
int planes;
|
int planes;
|
||||||
int radius;
|
int radius;
|
||||||
|
int radiusV;
|
||||||
|
|
||||||
int planewidth[4];
|
int planewidth[4];
|
||||||
int planeheight[4];
|
int planeheight[4];
|
||||||
|
|
|
@ -57,6 +57,7 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_
|
||||||
htype *ccoarse = s->coarse[jobnr];
|
htype *ccoarse = s->coarse[jobnr];
|
||||||
htype *cfine = s->fine[jobnr];
|
htype *cfine = s->fine[jobnr];
|
||||||
const int radius = s->radius;
|
const int radius = s->radius;
|
||||||
|
const int radiusV = s->radiusV;
|
||||||
const int t = s->t;
|
const int t = s->t;
|
||||||
const pixel *src = (const pixel *)ssrc;
|
const pixel *src = (const pixel *)ssrc;
|
||||||
pixel *dst = (pixel *)ddst;
|
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(cfine, 0, s->fine_size * sizeof(*cfine));
|
||||||
memset(ccoarse, 0, s->coarse_size * sizeof(*ccoarse));
|
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) {
|
if (jobnr == 0) {
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
cfine[PICK_FINE_BIN(width, srcp[i], i)] += radius + 1;
|
cfine[PICK_FINE_BIN(width, srcp[i], i)] += radiusV + 1;
|
||||||
ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radius + 1;
|
ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radiusV + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srcp = src + FFMAX(0, slice_h_start - radius - (jobnr != 0)) * src_linesize;
|
srcp = src + FFMAX(0, slice_h_start - radiusV - (jobnr != 0)) * src_linesize;
|
||||||
for (int i = 0; i < radius + (jobnr != 0) * (1 + radius); i++) {
|
for (int i = 0; i < radiusV + (jobnr != 0) * (1 + radiusV); i++) {
|
||||||
for (int j = 0; j < width; j++) {
|
for (int j = 0; j < width; j++) {
|
||||||
cfine[PICK_FINE_BIN(width, srcp[j], j)]++;
|
cfine[PICK_FINE_BIN(width, srcp[j], j)]++;
|
||||||
ccoarse[PICK_COARSE_BIN(j, srcp[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 fine[BINS][BINS] = { { 0 } };
|
||||||
htype luc[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++) {
|
for (int j = 0; j < width; j++) {
|
||||||
cfine[PICK_FINE_BIN(width, p[j], j)]--;
|
cfine[PICK_FINE_BIN(width, p[j], j)]--;
|
||||||
ccoarse[PICK_COARSE_BIN(j, p[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++) {
|
for (int j = 0; j < width; j++) {
|
||||||
cfine[PICK_FINE_BIN(width, p[j], j)]++;
|
cfine[PICK_FINE_BIN(width, p[j], j)]++;
|
||||||
ccoarse[PICK_COARSE_BIN(j, p[j])]++;
|
ccoarse[PICK_COARSE_BIN(j, p[j])]++;
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
static const AVOption median_options[] = {
|
static const AVOption median_options[] = {
|
||||||
{ "radius", "set median radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=1}, 1, 127, FLAGS },
|
{ "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 },
|
{ "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 }
|
{ 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[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
|
||||||
s->planeheight[0] = s->planeheight[3] = inlink->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->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++) {
|
for (int i = 0; i < s->nb_planes; i++) {
|
||||||
if (!(s->planes & (1 << i)))
|
if (!(s->planes & (1 << i)))
|
||||||
|
@ -131,13 +133,13 @@ static int config_input(AVFilterLink *inlink)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (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->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->radiusV * 2 + 1);
|
||||||
return AVERROR(EINVAL);
|
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->bins = 1 << ((s->depth + 1) / 2);
|
||||||
s->fine_size = s->bins * s->bins * inlink->w;
|
s->fine_size = s->bins * s->bins * inlink->w;
|
||||||
s->coarse_size = s->bins * inlink->w;
|
s->coarse_size = s->bins * inlink->w;
|
||||||
|
|
Loading…
Add table
Reference in a new issue