ffmpeg | branch: master | Paul B Mahol | Mon Feb 10 18:10:55
2020 +0100| [72b6c8c99f4b3bcdeb4f3fb594c0802ac3bf10f8] | committer: Paul B Mahol
avfilter: add Contrast Adaptive Sharpen video filter
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=72b6c8c99f4b3bcdeb4f3fb594c0802ac3bf10f8
---
Changelog| 1 +
doc/filters.texi | 15 +++
libavfilter/Makefile | 1 +
libavfilter/allfilters.c | 1 +
libavfilter/version.h| 2 +-
libavfilter/vf_cas.c | 299 +++
6 files changed, 318 insertions(+), 1 deletion(-)
diff --git a/Changelog b/Changelog
index e8ba02cb02..cb310a3abc 100644
--- a/Changelog
+++ b/Changelog
@@ -42,6 +42,7 @@ version :
- siren audio decoder
- Rayman 2 ADPCM decoder
- Rayman 2 APM demuxer
+- cas video filter
version 4.2:
diff --git a/doc/filters.texi b/doc/filters.texi
index 70fd7a4cc7..8300aac4a3 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6996,6 +6996,21 @@ Only deinterlace frames marked as interlaced.
The default value is @code{all}.
@end table
+@section cas
+
+Apply Contrast Adaptive Sharpen filter to video stream.
+
+The filter accepts the following options:
+
+@table @option
+@item strength
+Set the sharpening strength. Default value is 0.
+
+@item planes
+Set planes to filter. Default value is to filter all
+planes except alpha plane.
+@end table
+
@section chromahold
Remove all color information for all colors except for certain one.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 089880a39d..e6cfcd9487 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -177,6 +177,7 @@ OBJS-$(CONFIG_BOXBLUR_FILTER)+=
vf_boxblur.o boxblur.o
OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
opencl/avgblur.o boxblur.o
OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o yadif_common.o
+OBJS-$(CONFIG_CAS_FILTER)+= vf_cas.o
OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o
OBJS-$(CONFIG_CHROMAHOLD_FILTER) += vf_chromakey.o
OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 88ebd121ad..501e5d041b 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -168,6 +168,7 @@ extern AVFilter ff_vf_bm3d;
extern AVFilter ff_vf_boxblur;
extern AVFilter ff_vf_boxblur_opencl;
extern AVFilter ff_vf_bwdif;
+extern AVFilter ff_vf_cas;
extern AVFilter ff_vf_chromahold;
extern AVFilter ff_vf_chromakey;
extern AVFilter ff_vf_chromashift;
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 8916fb34f0..7b41018be7 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#include "libavutil/version.h"
#define LIBAVFILTER_VERSION_MAJOR 7
-#define LIBAVFILTER_VERSION_MINOR 76
+#define LIBAVFILTER_VERSION_MINOR 77
#define LIBAVFILTER_VERSION_MICRO 100
diff --git a/libavfilter/vf_cas.c b/libavfilter/vf_cas.c
new file mode 100644
index 00..a07d51a84e
--- /dev/null
+++ b/libavfilter/vf_cas.c
@@ -0,0 +1,299 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct CASContext {
+const AVClass *class;
+
+float strength;
+int planes;
+int nb_planes;
+
+int depth;
+int planeheight[4];
+int planewidth[4];
+
+AVFrame *in;
+
+int (*do_slice)(AVFilterContext *s, void *arg,
+int jobnr, int nb_jobs);
+} CASContext;
+
+static inline float lerpf(float v0, float v1, float f)
+{
+return v0 + (v1 - v0) * f;
+}
+
+static int cas_slice8(AVFilterContext *avctx, void *arg, int jobnr, int
nb_jobs)
+{
+CASContext *s = avctx->priv;
+const float strength = -lerpf(16.f, 4.01f, s->strength);
+AVFrame *out = arg;
+AVFrame *in = s->in;
+
+for (int p = 0; p < s->nb_planes; p++) {
+const int slice_start = (s->planeheight[p] * jobnr) / nb_jobs;
+const int slice_end = (s->planeheight[p] * (jobnr+1)) / nb_jobs;
+