avfilter/vf_unsharp: add support for alpha formats

This commit is contained in:
Paul B Mahol 2022-03-01 12:33:56 +01:00
parent e1974622e1
commit 84f5583078
3 changed files with 41 additions and 9 deletions

View File

@ -21585,6 +21585,23 @@ sharpen it, a value of zero will disable the effect.
Default value is 0.0.
@item alpha_msize_x, ax
Set the alpha matrix horizontal size. It must be an odd integer
between 3 and 23. The default value is 5.
@item alpha_msize_y, ay
Set the alpha matrix vertical size. It must be an odd integer
between 3 and 23. The default value is 5.
@item alpha_amount, aa
Set the alpha effect strength. It must be a floating point number, reasonable
values lay between -1.5 and 1.5.
Negative values will blur the input video, while positive values will
sharpen it, a value of zero will disable the effect.
Default value is 0.0.
@end table
All parameters are optional and default to the equivalent of the

View File

@ -44,14 +44,17 @@ typedef struct UnsharpFilterParam {
typedef struct UnsharpContext {
const AVClass *class;
int lmsize_x, lmsize_y, cmsize_x, cmsize_y;
int amsize_x, amsize_y;
float lamount, camount;
float aamount;
UnsharpFilterParam luma; ///< luma parameters (width, height, amount)
UnsharpFilterParam chroma; ///< chroma parameters (width, height, amount)
UnsharpFilterParam alpha; ///< alpha parameters (width, height, amount)
int hsub, vsub;
int nb_planes;
int bitdepth;
int bps;
int nb_threads;
int opencl;
int (* apply_unsharp)(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
int (* unsharp_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
} UnsharpContext;

View File

@ -146,17 +146,18 @@ static int apply_unsharp_c(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
{
AVFilterLink *inlink = ctx->inputs[0];
UnsharpContext *s = ctx->priv;
int i, plane_w[3], plane_h[3];
UnsharpFilterParam *fp[3];
int i, plane_w[4], plane_h[4];
UnsharpFilterParam *fp[4];
ThreadData td;
plane_w[0] = inlink->w;
plane_w[0] = plane_w[3] = inlink->w;
plane_w[1] = plane_w[2] = AV_CEIL_RSHIFT(inlink->w, s->hsub);
plane_h[0] = inlink->h;
plane_h[0] = plane_h[3] = inlink->h;
plane_h[1] = plane_h[2] = AV_CEIL_RSHIFT(inlink->h, s->vsub);
fp[0] = &s->luma;
fp[1] = fp[2] = &s->chroma;
for (i = 0; i < 3; i++) {
fp[3] = &s->alpha;
for (i = 0; i < s->nb_planes; i++) {
td.fp = fp[i];
td.dst = out->data[i];
td.src = in->data[i];
@ -188,9 +189,10 @@ static av_cold int init(AVFilterContext *ctx)
set_filter_param(&s->luma, s->lmsize_x, s->lmsize_y, s->lamount);
set_filter_param(&s->chroma, s->cmsize_x, s->cmsize_y, s->camount);
set_filter_param(&s->alpha, s->amsize_x, s->amsize_y, s->aamount);
if (s->luma.scalebits >= 26 || s->chroma.scalebits >= 26) {
av_log(ctx, AV_LOG_ERROR, "luma or chroma matrix size too big\n");
if (s->luma.scalebits >= 26 || s->chroma.scalebits >= 26 || s->alpha.scalebits >= 26) {
av_log(ctx, AV_LOG_ERROR, "luma or chroma or alpha matrix size too big\n");
return AVERROR(EINVAL);
}
s->apply_unsharp = apply_unsharp_c;
@ -198,6 +200,10 @@ static av_cold int init(AVFilterContext *ctx)
}
static const enum AVPixelFormat pix_fmts[] = {
AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA444P16,
AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA422P16,
AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV410P,
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
@ -242,6 +248,7 @@ static int config_input(AVFilterLink *inlink)
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
int ret;
s->nb_planes = desc->nb_components;
s->hsub = desc->log2_chroma_w;
s->vsub = desc->log2_chroma_h;
s->bitdepth = desc->comp[0].depth;
@ -325,7 +332,12 @@ static const AVOption unsharp_options[] = {
{ "cy", "set chroma matrix vertical size", OFFSET(cmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "chroma_amount", "set chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "ca", "set chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "opencl", "ignored", OFFSET(opencl), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "alpha_msize_x", "set alpha matrix horizontal size", OFFSET(amsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "ax", "set alpha matrix horizontal size", OFFSET(amsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "alpha_msize_y", "set alpha matrix vertical size", OFFSET(amsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "ay", "set alpha matrix vertical size", OFFSET(amsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "alpha_amount", "set alpha effect strength", OFFSET(aamount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "aa", "set alpha effect strength", OFFSET(aamount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ NULL }
};