Re: [FFmpeg-devel] [PATCH] avfilter: add premultiply filter

2016-12-01 Thread wm4
On Mon, 28 Nov 2016 19:19:48 +0100
Paul B Mahol  wrote:

> Hi,
> 
> patch attached.

This could have documented what operation it actually performs.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter: add premultiply filter

2016-11-28 Thread Paul B Mahol
Hi,

patch attached.
From a5f6dad7abb279ba1d57c1b7ee68c61b7381199c Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Mon, 28 Nov 2016 17:28:59 +0100
Subject: [PATCH] avfilter: add premultiply filter

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |   5 +
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/vf_premultiply.c | 403 +++
 4 files changed, 410 insertions(+)
 create mode 100644 libavfilter/vf_premultiply.c

diff --git a/doc/filters.texi b/doc/filters.texi
index b3899b2..4a826a1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10982,6 +10982,11 @@ Set medium thresholding (good results, default).
 @end table
 @end table
 
+@section premultiply
+Apply premultiply effect to input video stream using first plane of second stream.
+
+Both streams must have same dimensions and same pixel format.
+
 @section prewitt
 Apply prewitt operator to input video stream.
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index cdddb1b..cb614c9 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -240,6 +240,7 @@ OBJS-$(CONFIG_PHASE_FILTER)  += vf_phase.o
 OBJS-$(CONFIG_PIXDESCTEST_FILTER)+= vf_pixdesctest.o
 OBJS-$(CONFIG_PP_FILTER) += vf_pp.o
 OBJS-$(CONFIG_PP7_FILTER)+= vf_pp7.o
+OBJS-$(CONFIG_PREMULTIPLY_FILTER)+= vf_premultiply.o framesync.o
 OBJS-$(CONFIG_PREWITT_FILTER)+= vf_convolution.o
 OBJS-$(CONFIG_PSNR_FILTER)   += vf_psnr.o dualinput.o framesync.o
 OBJS-$(CONFIG_PULLUP_FILTER) += vf_pullup.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 82a65ee..2c37818 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -256,6 +256,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(PIXDESCTEST,pixdesctest,vf);
 REGISTER_FILTER(PP, pp, vf);
 REGISTER_FILTER(PP7,pp7,vf);
+REGISTER_FILTER(PREMULTIPLY,premultiply,vf);
 REGISTER_FILTER(PREWITT,prewitt,vf);
 REGISTER_FILTER(PSNR,   psnr,   vf);
 REGISTER_FILTER(PULLUP, pullup, vf);
diff --git a/libavfilter/vf_premultiply.c b/libavfilter/vf_premultiply.c
new file mode 100644
index 000..7b74f7d
--- /dev/null
+++ b/libavfilter/vf_premultiply.c
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2016 Paul B Mahol
+ *
+ * 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/imgutils.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "framesync.h"
+#include "internal.h"
+#include "video.h"
+
+typedef struct PreMultiplyContext {
+const AVClass *class;
+int width[4], height[4];
+int nb_planes;
+int planes;
+int half, depth, offset;
+FFFrameSync fs;
+
+void (*premultiply[4])(const uint8_t *msrc, const uint8_t *asrc,
+   uint8_t *dst,
+   ptrdiff_t mlinesize, ptrdiff_t alinesize,
+   ptrdiff_t dlinesize,
+   int w, int h,
+   int half, int shift, int offset);
+} PreMultiplyContext;
+
+#define OFFSET(x) offsetof(PreMultiplyContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption premultiply_options[] = {
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(premultiply);
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pix_fmts[] = {
+AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
+AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
+AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
+AV_PIX_FMT_YUV444P16,
+AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
+AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
+AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
+AV_PIX_FMT_NONE
+};
+
+return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+}
+
+static int process_frame(FFFrameSync *fs)
+{
+AVFilterContext *ctx = fs->parent;
+PreMultiplyContext *s =