Signed-off-by: Paul B Mahol
---
libavfilter/Makefile | 1 +
libavfilter/allfilters.c | 1 +
libavfilter/vf_deflash.c | 199 +++
3 files changed, 201 insertions(+)
create mode 100644 libavfilter/vf_deflash.c
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1f4abeb..f801566 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -122,6 +122,7 @@ OBJS-$(CONFIG_CURVES_FILTER) += vf_curves.o
OBJS-$(CONFIG_DCTDNOIZ_FILTER) += vf_dctdnoiz.o
OBJS-$(CONFIG_DEBAND_FILTER) += vf_deband.o
OBJS-$(CONFIG_DECIMATE_FILTER) += vf_decimate.o
+OBJS-$(CONFIG_DEFLASH_FILTER)+= vf_deflash.o
OBJS-$(CONFIG_DEFLATE_FILTER)+= vf_neighbor.o
OBJS-$(CONFIG_DEJUDDER_FILTER) += vf_dejudder.o
OBJS-$(CONFIG_DELOGO_FILTER) += vf_delogo.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 63b8fdb..daacbc3 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -144,6 +144,7 @@ void avfilter_register_all(void)
REGISTER_FILTER(DCTDNOIZ, dctdnoiz, vf);
REGISTER_FILTER(DEBAND, deband, vf);
REGISTER_FILTER(DECIMATE, decimate, vf);
+REGISTER_FILTER(DEFLASH,deflash,vf);
REGISTER_FILTER(DEFLATE,deflate,vf);
REGISTER_FILTER(DEJUDDER, dejudder, vf);
REGISTER_FILTER(DELOGO, delogo, vf);
diff --git a/libavfilter/vf_deflash.c b/libavfilter/vf_deflash.c
new file mode 100644
index 000..3167989
--- /dev/null
+++ b/libavfilter/vf_deflash.c
@@ -0,0 +1,199 @@
+/*
+ * 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/pixdesc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/internal.h"
+#include "avfilter.h"
+
+#define FF_BUFQUEUE_SIZE 13
+#include "bufferqueue.h"
+
+#include "internal.h"
+#include "video.h"
+
+typedef struct DeFlashContext {
+const AVClass *class;
+
+AVFrame *frame;
+float fthrd[4];
+int thrd[4];
+float fthrr[4];
+int thrr[4];
+
+struct FFBufQueue q;
+
+int planeheight[4];
+int planewidth[4];
+} DeFlashContext;
+
+#define OFFSET(x) offsetof(DeFlashContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption deflash_options[] = {
+{ "0fd", "set flash threshold detection for 1st color component",
OFFSET(fthrd[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
+{ "0fr", "set ammount of flash reduction for 1st color component",
OFFSET(fthrr[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
+{ "1fd", "set flash threshold detection for 2nd color component",
OFFSET(fthrd[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
+{ "1fr", "set ammount of flash reduction for 2nd color component",
OFFSET(fthrr[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
+{ "2fd", "set flash threshold detection for 3rd color component",
OFFSET(fthrd[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.2}, 0, 5, FLAGS },
+{ "2fr", "set ammount of flash reduction for 3rd color component",
OFFSET(fthrr[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.05}, 0, 1, FLAGS },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(deflash);
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pixel_fmts[] = {
+AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
+AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
+AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
+AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
+AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
+AV_PIX_FMT_YUVJ411P,
+AV_PIX_FMT_NONE
+};
+AVFilterFormats *formats = ff_make_format_list(pixel_fmts);
+if (!formats)
+return AVERROR(ENOMEM);
+return ff_set_common_formats(ctx, formats);
+}
+
+static int config_input(AVFilterLink *inlink)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+AVFilterContext *ctx = inlink->dst;
+DeFlashContext *s = ctx->priv;
+
+s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h,
desc->log2_chroma_h);
+s->planeheight[0] = s->planeheight[3] = inlink->h;
+s->p