[FFmpeg-devel] [PATCH 2/3] avfilter/vf_edgedetect: add planes option
Clément Bœsch
u at pkh.me
Fri May 4 21:53:52 EEST 2018
On Thu, May 03, 2018 at 03:44:43PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
> doc/filters.texi | 4 +++-
> libavfilter/vf_edgedetect.c | 25 +++++++++++++++++++++++++
> 2 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 29b5a5b15f..245326154c 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -8272,8 +8272,10 @@ Mix the colors to create a paint/cartoon effect.
> @item canny
> Apply Canny edge detector on all selected planes.
> @end table
> -
> Default value is @var{wires}.
> +
> + at item planes
> +Select planes for filtering. By default all available planes are filtered.
> @end table
>
> @subsection Examples
> diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c
> index 534a302d90..6f86115d23 100644
> --- a/libavfilter/vf_edgedetect.c
> +++ b/libavfilter/vf_edgedetect.c
> @@ -26,12 +26,21 @@
> */
>
> #include "libavutil/avassert.h"
> +#include "libavutil/imgutils.h"
> #include "libavutil/opt.h"
> #include "avfilter.h"
> #include "formats.h"
> #include "internal.h"
> #include "video.h"
>
> +#define PLANE_R 0x4
> +#define PLANE_G 0x1
> +#define PLANE_B 0x2
> +#define PLANE_Y 0x1
> +#define PLANE_U 0x2
> +#define PLANE_V 0x4
> +#define PLANE_A 0x8
> +
> enum FilterMode {
> MODE_WIRES,
> MODE_COLORMIX,
> @@ -48,6 +57,7 @@ struct plane_info {
> typedef struct EdgeDetectContext {
> const AVClass *class;
> struct plane_info planes[3];
> + int filter_planes;
> int nb_planes;
> double low, high;
> uint8_t low_u8, high_u8;
> @@ -63,6 +73,13 @@ static const AVOption edgedetect_options[] = {
> { "wires", "white/gray wires on black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_WIRES}, INT_MIN, INT_MAX, FLAGS, "mode" },
> { "colormix", "mix colors", 0, AV_OPT_TYPE_CONST, {.i64=MODE_COLORMIX}, INT_MIN, INT_MAX, FLAGS, "mode" },
> { "canny", "detect edges on planes", 0, AV_OPT_TYPE_CONST, {.i64=MODE_CANNY}, INT_MIN, INT_MAX, FLAGS, "mode" },
> + { "planes", "set planes to filter", OFFSET(filter_planes), AV_OPT_TYPE_FLAGS, {.i64=7}, 1, 0x7, FLAGS, "flags" },
> + { "y", "filter luma plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_Y}, 0, 0, FLAGS, "flags"},
> + { "u", "filter u plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_U}, 0, 0, FLAGS, "flags"},
> + { "v", "filter v plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_V}, 0, 0, FLAGS, "flags"},
> + { "r", "filter red plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_R}, 0, 0, FLAGS, "flags"},
> + { "g", "filter green plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_G}, 0, 0, FLAGS, "flags"},
> + { "b", "filter blue plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_B}, 0, 0, FLAGS, "flags"},
please keep the style consistent with above (also beware of the trailing
space before "}")
> { NULL }
> };
>
> @@ -322,6 +339,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
> uint16_t *gradients = plane->gradients;
> int8_t *directions = plane->directions;
>
> + if (!((1 << p) & edgedetect->filter_planes)) {
> + if (!direct)
> + av_image_copy_plane(out->data[p], out->linesize[p],
> + in->data[p], in->linesize[p],
> + inlink->w, inlink->h);
> + continue;
> + }
> +
Should be fine. Though, I'd say the green (0) is unexpected for chroma
planes; I'd expect gray (128) instead. Not blocking but could be changed
in the future.
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180504/8272fb18/attachment.sig>
More information about the ffmpeg-devel
mailing list