diff mbox

[FFmpeg-devel,1/3] avfilter/vf_edgedetect: add canny mode

Message ID 20180503134444.26738-1-onemda@gmail.com
State Accepted
Commit d122c8b1028bb713c6c0cdb45d477f43b62d2436
Headers show

Commit Message

Paul B Mahol May 3, 2018, 1:44 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 doc/filters.texi            | 3 +++
 libavfilter/vf_edgedetect.c | 5 +++++
 2 files changed, 8 insertions(+)

Comments

Clément Bœsch May 4, 2018, 6:51 p.m. UTC | #1
On Thu, May 03, 2018 at 03:44:42PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  doc/filters.texi            | 3 +++
>  libavfilter/vf_edgedetect.c | 5 +++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 218f30ef5f..29b5a5b15f 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -8268,6 +8268,9 @@ Draw white/gray wires on black background.
>  
>  @item colormix
>  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}.
> diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c
> index 173f9fe161..534a302d90 100644
> --- a/libavfilter/vf_edgedetect.c
> +++ b/libavfilter/vf_edgedetect.c
> @@ -35,6 +35,7 @@
>  enum FilterMode {
>      MODE_WIRES,
>      MODE_COLORMIX,
> +    MODE_CANNY,
>      NB_MODE
>  };
>  
> @@ -61,6 +62,7 @@ static const AVOption edgedetect_options[] = {
>      { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_WIRES}, 0, NB_MODE-1, FLAGS, "mode" },
>          { "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" },
>      { NULL }
>  };
>  
> @@ -79,6 +81,7 @@ static int query_formats(AVFilterContext *ctx)
>  {
>      const EdgeDetectContext *edgedetect = ctx->priv;
>      static const enum AVPixelFormat wires_pix_fmts[] = {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
> +    static const enum AVPixelFormat canny_pix_fmts[] = {AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
>      static const enum AVPixelFormat colormix_pix_fmts[] = {AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
>      AVFilterFormats *fmts_list;
>      const enum AVPixelFormat *pix_fmts = NULL;
> @@ -87,6 +90,8 @@ static int query_formats(AVFilterContext *ctx)
>          pix_fmts = wires_pix_fmts;
>      } else if (edgedetect->mode == MODE_COLORMIX) {
>          pix_fmts = colormix_pix_fmts;
> +    } else if (edgedetect->mode == MODE_CANNY) {
> +        pix_fmts = canny_pix_fmts;
>      } else {
>          av_assert0(0);
>      }

Sure, why not
diff mbox

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index 218f30ef5f..29b5a5b15f 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8268,6 +8268,9 @@  Draw white/gray wires on black background.
 
 @item colormix
 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}.
diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c
index 173f9fe161..534a302d90 100644
--- a/libavfilter/vf_edgedetect.c
+++ b/libavfilter/vf_edgedetect.c
@@ -35,6 +35,7 @@ 
 enum FilterMode {
     MODE_WIRES,
     MODE_COLORMIX,
+    MODE_CANNY,
     NB_MODE
 };
 
@@ -61,6 +62,7 @@  static const AVOption edgedetect_options[] = {
     { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_WIRES}, 0, NB_MODE-1, FLAGS, "mode" },
         { "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" },
     { NULL }
 };
 
@@ -79,6 +81,7 @@  static int query_formats(AVFilterContext *ctx)
 {
     const EdgeDetectContext *edgedetect = ctx->priv;
     static const enum AVPixelFormat wires_pix_fmts[] = {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
+    static const enum AVPixelFormat canny_pix_fmts[] = {AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
     static const enum AVPixelFormat colormix_pix_fmts[] = {AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
     AVFilterFormats *fmts_list;
     const enum AVPixelFormat *pix_fmts = NULL;
@@ -87,6 +90,8 @@  static int query_formats(AVFilterContext *ctx)
         pix_fmts = wires_pix_fmts;
     } else if (edgedetect->mode == MODE_COLORMIX) {
         pix_fmts = colormix_pix_fmts;
+    } else if (edgedetect->mode == MODE_CANNY) {
+        pix_fmts = canny_pix_fmts;
     } else {
         av_assert0(0);
     }