[FFmpeg-cvslog] avfilter/vf_unsharp: add support for alpha formats
Paul B Mahol
git at videolan.org
Tue Mar 1 13:35:20 EET 2022
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Mar 1 12:33:56 2022 +0100| [84f5583078699e96b040f4f41b39720b683326d0] | committer: Paul B Mahol
avfilter/vf_unsharp: add support for alpha formats
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=84f5583078699e96b040f4f41b39720b683326d0
---
doc/filters.texi | 17 +++++++++++++++++
libavfilter/unsharp.h | 5 ++++-
libavfilter/vf_unsharp.c | 28 ++++++++++++++++++++--------
3 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index c3623dee89..c5cba2aa2d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -21585,6 +21585,23 @@ sharpen it, a value of zero will disable the effect.
Default value is 0.0.
+ at 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.
+
+ at 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.
+
+ at 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
diff --git a/libavfilter/unsharp.h b/libavfilter/unsharp.h
index 253e32dd19..0da6f05036 100644
--- a/libavfilter/unsharp.h
+++ b/libavfilter/unsharp.h
@@ -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;
diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c
index 9a31045116..e88e732c9e 100644
--- a/libavfilter/vf_unsharp.c
+++ b/libavfilter/vf_unsharp.c
@@ -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 }
};
More information about the ffmpeg-cvslog
mailing list