mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avfilter/vf_median: clip radius instead of erroring out
This commit is contained in:
parent
7ead0daa24
commit
8e2a832a55
@ -110,33 +110,30 @@ static int query_formats(AVFilterContext *ctx)
|
|||||||
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
|
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_params(MedianContext *s, AVFilterLink *inlink)
|
static void check_params(MedianContext *s, AVFilterLink *inlink)
|
||||||
{
|
{
|
||||||
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)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (s->planewidth[i] < s->radius * 2 + 1) {
|
if (s->planewidth[i] < s->radius * 2 + 1) {
|
||||||
av_log(inlink->dst, AV_LOG_ERROR, "The %d plane width %d must be not less than %d\n", i, s->planewidth[i], s->radius * 2 + 1);
|
av_log(inlink->dst, AV_LOG_WARNING, "The %d plane width %d must be not less than %d, clipping radius.\n", i, s->planewidth[i], s->radius * 2 + 1);
|
||||||
return AVERROR(EINVAL);
|
s->radius = (s->planewidth[i] - 1) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->planeheight[i] < s->radiusV * 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);
|
av_log(inlink->dst, AV_LOG_WARNING, "The %d plane height %d must be not less than %d, clipping radiusV.\n", i, s->planeheight[i], s->radiusV * 2 + 1);
|
||||||
return AVERROR(EINVAL);
|
s->radiusV = (s->planeheight[i] - 1) / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s->t = 2 * s->radius * s->radiusV + 2 * s->radius;
|
s->t = 2 * s->radius * s->radiusV + 2 * s->radius;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_input(AVFilterLink *inlink)
|
static int config_input(AVFilterLink *inlink)
|
||||||
{
|
{
|
||||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
|
||||||
MedianContext *s = inlink->dst->priv;
|
MedianContext *s = inlink->dst->priv;
|
||||||
int ret;
|
|
||||||
|
|
||||||
s->depth = desc->comp[0].depth;
|
s->depth = desc->comp[0].depth;
|
||||||
s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
|
s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
|
||||||
@ -147,9 +144,7 @@ static int config_input(AVFilterLink *inlink)
|
|||||||
s->radiusV = !s->radiusV ? s->radius : s->radiusV;
|
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);
|
||||||
|
|
||||||
ret = check_params(s, inlink);
|
check_params(s, inlink);
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
s->nb_threads = FFMAX(1, FFMIN(s->planeheight[1] / (s->radiusV + 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);
|
||||||
@ -258,19 +253,15 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar
|
|||||||
char *res, int res_len, int flags)
|
char *res, int res_len, int flags)
|
||||||
{
|
{
|
||||||
MedianContext *s = ctx->priv;
|
MedianContext *s = ctx->priv;
|
||||||
int radius = s->radius, radiusV = s->radiusV, planes = s->planes;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
|
ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = check_params(s, ctx->inputs[0]);
|
if (!s->radiusV)
|
||||||
if (ret != 0) {
|
s->radiusV = s->radius;
|
||||||
s->radius = radius;
|
check_params(s, ctx->inputs[0]);
|
||||||
s->radiusV = radiusV;
|
|
||||||
s->planes = planes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user