Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-10 Thread Paul B Mahol
On Wed, May 10, 2023 at 2:50 PM Michael Koch 
wrote:

> Well, I can't see how it looks now, but the sequence white - gray -
> white (which is impossible in a sine wave) should no longer be there,
> because cos(x) = cos(-x).
>

This is not caused by sin() but because video is full range yuv but
interpreted as limited.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-10 Thread Michael Koch
Well, I can't see how it looks now, but the sequence white - gray - 
white (which is impossible in a sine wave) should no longer be there, 
because cos(x) = cos(-x).

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-10 Thread Paul B Mahol
On Wed, May 10, 2023 at 2:32 PM Michael Koch 
wrote:

> ffmpeg -f lavfi -i zoneplate=kx2=320:ky2=240,format=gray -frames 1 -y
> out.png
>
> When you draw a line through the center, you have
> black - gray - white - gray - white - gray -black
> which means the sine wave changes its sign in the center.
> That's why zoneplates are normally calculated with cos() function.
> See also: https://en.wikipedia.org/wiki/Zone_plate#Continuous_zone_plates


I replaced sinf with cosf, and output is same, just different phase.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-10 Thread Michael Koch
ffmpeg -f lavfi -i zoneplate=kx2=320:ky2=240,format=gray -frames 1 -y 
out.png


When you draw a line through the center, you have
black - gray - white - gray - white - gray -black
which means the sine wave changes its sign in the center.
That's why zoneplates are normally calculated with cos() function.
See also: https://en.wikipedia.org/wiki/Zone_plate#Continuous_zone_plates

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-10 Thread Paul B Mahol
On Wed, May 10, 2023 at 1:58 PM Michael Koch 
wrote:

> Isn't it better to use cos() instead of sin()? With sin() there is a
> discontinuity in the center.
>

Where you see discontinuity in the filter output?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-10 Thread Michael Koch
Isn't it better to use cos() instead of sin()? With sin() there is a 
discontinuity in the center.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-08 Thread Stefano Sabatini
On date Monday 2023-05-08 01:30:34 +0200, Paul B Mahol wrote:
> New version, faster and with slice threading and docs.

> From 8b9ab6e3401d69f115b5d331fec73fd8c01ea1bd Mon Sep 17 00:00:00 2001
> From: Paul B Mahol 
> Date: Sat, 6 May 2023 22:52:47 +0200
> Subject: [PATCH] avfilter: add zoneplate video test source
> 
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi   |  96 +++
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vsrc_testsrc.c | 157 +
>  4 files changed, 255 insertions(+)

missing Changelog entry?

> diff --git a/doc/filters.texi b/doc/filters.texi
> index 8b443c24e9..d7c828d119 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -28080,6 +28080,102 @@ Set max jump for single pan destination. Allowed 
> range is from 1 to 1.
>  Set fractal type, can be default @code{carpet} or @code{triangle}.
>  @end table
>  
> +@section zoneplate
> +Generates a zoneplate test video pattern.

Nit: impersonal form (Generate) for the first sentence.

> +Numerous options for signal controls output phase in all three axis.

This source accepts ...

> +
> +This source accepts the following options:
> +
> +@table @option
> +@item size, s
> +Set frame size. For the syntax of this option, check the @ref{video size 
> syntax,,"Video
> +size" section in the ffmpeg-utils manual,ffmpeg-utils}. Default value is 
> "320x240".
> +
> +@item rate, r
> +Set frame rate, expressed as number of frames per second. Default
> +value is "25".
> +
> +@item duration, d
> +Set the duration of the sourced video. See
> +@ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) 
> manual,ffmpeg-utils}
> +for the accepted syntax.
> +
> +If not specified, or the expressed duration is negative, the video is
> +supposed to be generated forever.
> +
> +@item sar
> +Set the sample aspect ratio of the sourced video.
> +
> +@item precision
> +Set precision in bits for look-up table for sine calculations. Default value 
> is 10.
> +Allowed range is from 4 to 16.
> +
> +@item xo
> +Set horizontal axis offset for output signal. Default value is 0.
> +
> +@item yo
> +Set vertical axis offset for output signal. Default value is 0.
> +
> +@item k0
> +Set 0-order, constant added to signal phase. Default value is 0.
> +
> +@item kx
> +Set 1-order, phase factor multiplier for horizontal axis. Default value is 0.
> +
> +@item ky
> +Set 1-order, phase factor multiplier for vertical axis. Default value is 0.
> +
> +@item kt
> +Set 1-order, phase factor multiplier for time axis. Default value is 0.
> +
> +@item kxt, kyt, kxy
> +Set phase factor multipliers for combination of spatial and temporal axis.
> +Default value is 0.
> +
> +@item kx2
> +Set 2-order, phase factor multiplier for horizontal axis. Default value is 0.
> +
> +@item ky2
> +Set 2-order, phase factor multiplier for vertical axis. Default value is 0.
> +
> +@item kt2
> +Set 2-order, phase factor multiplier for time axis. Default value is 0.
> +
> +@item ku
> +Set the constant added to final phase to produce chroma-blue component of 
> signal.
> +Default value is 0.
> +
> +@item kv
> +Set the constant added to final phase to produce chroma-red component of 
> signal.
> +Default value is 0.
> +@end table
> +
> +@subsection Commands
> +

> +Filter supports the some above options as @ref{commands}.

Nit: This source supports the above options as ...

> +
> +@subsection Examples
> +
> +@itemize
> +@item
> +Generate horizontal color sine sweep:
> +@example
> +zoneplate=ku=512:kv=0:kt2=0:kx2=256:s=wvga:xo=-426:kt=11
> +@end example
> +
> +@item
> +Generate vertical color sine sweep:
> +@example
> +zoneplate=ku=512:kv=0:kt2=0:ky2=156:s=wvga:yo=-240:kt=11
> +@end example
> +
> +@item
> +Generate circular zone-plate:
> +@example
> +zoneplate=ku=512:kv=100:kt2=0:ky2=256:kx2=556:s=wvga:yo=0:kt=11
> +@end example
> +@end itemize
> +
>  @c man end VIDEO SOURCES
>  
>  @chapter Video Sinks
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 93c614eeb7..9fb9a1095f 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -598,6 +598,7 @@ OBJS-$(CONFIG_SMPTEHDBARS_FILTER)+= 
> vsrc_testsrc.o
>  OBJS-$(CONFIG_TESTSRC_FILTER)+= vsrc_testsrc.o
>  OBJS-$(CONFIG_TESTSRC2_FILTER)   += vsrc_testsrc.o
>  OBJS-$(CONFIG_YUVTESTSRC_FILTER) += vsrc_testsrc.o
> +OBJS-$(CONFIG_ZONEPLATE_FILTER)  += vsrc_testsrc.o
>  
>  OBJS-$(CONFIG_NULLSINK_FILTER)   += vsink_nullsink.o
>  
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 1c0bc12a92..025966dc45 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -563,6 +563,7 @@ extern const AVFilter ff_vsrc_smptehdbars;
>  extern const AVFilter ff_vsrc_testsrc;
>  extern const AVFilter ff_vsrc_testsrc2;
>  extern const AVFilter ff_vsrc_yuvtestsrc;
> +extern const AVFilter ff_vsrc_zoneplate;
>  

Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-07 Thread Paul B Mahol
New version, faster and with slice threading and docs.
From 8b9ab6e3401d69f115b5d331fec73fd8c01ea1bd Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Sat, 6 May 2023 22:52:47 +0200
Subject: [PATCH] avfilter: add zoneplate video test source

Signed-off-by: Paul B Mahol 
---
 doc/filters.texi   |  96 +++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vsrc_testsrc.c | 157 +
 4 files changed, 255 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 8b443c24e9..d7c828d119 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28080,6 +28080,102 @@ Set max jump for single pan destination. Allowed range is from 1 to 1.
 Set fractal type, can be default @code{carpet} or @code{triangle}.
 @end table
 
+@section zoneplate
+Generates a zoneplate test video pattern.
+Numerous options for signal controls output phase in all three axis.
+
+This source accepts the following options:
+
+@table @option
+@item size, s
+Set frame size. For the syntax of this option, check the @ref{video size syntax,,"Video
+size" section in the ffmpeg-utils manual,ffmpeg-utils}. Default value is "320x240".
+
+@item rate, r
+Set frame rate, expressed as number of frames per second. Default
+value is "25".
+
+@item duration, d
+Set the duration of the sourced video. See
+@ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}
+for the accepted syntax.
+
+If not specified, or the expressed duration is negative, the video is
+supposed to be generated forever.
+
+@item sar
+Set the sample aspect ratio of the sourced video.
+
+@item precision
+Set precision in bits for look-up table for sine calculations. Default value is 10.
+Allowed range is from 4 to 16.
+
+@item xo
+Set horizontal axis offset for output signal. Default value is 0.
+
+@item yo
+Set vertical axis offset for output signal. Default value is 0.
+
+@item k0
+Set 0-order, constant added to signal phase. Default value is 0.
+
+@item kx
+Set 1-order, phase factor multiplier for horizontal axis. Default value is 0.
+
+@item ky
+Set 1-order, phase factor multiplier for vertical axis. Default value is 0.
+
+@item kt
+Set 1-order, phase factor multiplier for time axis. Default value is 0.
+
+@item kxt, kyt, kxy
+Set phase factor multipliers for combination of spatial and temporal axis.
+Default value is 0.
+
+@item kx2
+Set 2-order, phase factor multiplier for horizontal axis. Default value is 0.
+
+@item ky2
+Set 2-order, phase factor multiplier for vertical axis. Default value is 0.
+
+@item kt2
+Set 2-order, phase factor multiplier for time axis. Default value is 0.
+
+@item ku
+Set the constant added to final phase to produce chroma-blue component of signal.
+Default value is 0.
+
+@item kv
+Set the constant added to final phase to produce chroma-red component of signal.
+Default value is 0.
+@end table
+
+@subsection Commands
+
+Filter supports the some above options as @ref{commands}.
+
+@subsection Examples
+
+@itemize
+@item
+Generate horizontal color sine sweep:
+@example
+zoneplate=ku=512:kv=0:kt2=0:kx2=256:s=wvga:xo=-426:kt=11
+@end example
+
+@item
+Generate vertical color sine sweep:
+@example
+zoneplate=ku=512:kv=0:kt2=0:ky2=156:s=wvga:yo=-240:kt=11
+@end example
+
+@item
+Generate circular zone-plate:
+@example
+zoneplate=ku=512:kv=100:kt2=0:ky2=256:kx2=556:s=wvga:yo=0:kt=11
+@end example
+@end itemize
+
 @c man end VIDEO SOURCES
 
 @chapter Video Sinks
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 93c614eeb7..9fb9a1095f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -598,6 +598,7 @@ OBJS-$(CONFIG_SMPTEHDBARS_FILTER)+= vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC_FILTER)+= vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC2_FILTER)   += vsrc_testsrc.o
 OBJS-$(CONFIG_YUVTESTSRC_FILTER) += vsrc_testsrc.o
+OBJS-$(CONFIG_ZONEPLATE_FILTER)  += vsrc_testsrc.o
 
 OBJS-$(CONFIG_NULLSINK_FILTER)   += vsink_nullsink.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 1c0bc12a92..025966dc45 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -563,6 +563,7 @@ extern const AVFilter ff_vsrc_smptehdbars;
 extern const AVFilter ff_vsrc_testsrc;
 extern const AVFilter ff_vsrc_testsrc2;
 extern const AVFilter ff_vsrc_yuvtestsrc;
+extern const AVFilter ff_vsrc_zoneplate;
 
 extern const AVFilter ff_vsink_nullsink;
 
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index f391ac02e0..1e74a0e42e 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -88,6 +88,14 @@ typedef struct TestSourceContext {
 
 /* only used by haldclut */
 int level;
+
+/* only used by zoneplate */
+int k0, kx, ky, kt;
+int kxt, kyt, kxy;
+int kx2, ky2, kt2;
+int xo, yo, kU, kV;
+int lut_precision;
+uint8_t *lut;
 } TestSourceContext;
 
 #define 

Re: [FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-07 Thread Stefano Sabatini
On date Sunday 2023-05-07 18:04:37 +0200, Paul B Mahol wrote:
> Attached.

> From 7b0a8586adc0a142f0b7afcdbdf36ce526f4cd34 Mon Sep 17 00:00:00 2001
> From: Paul B Mahol 
> Date: Sat, 6 May 2023 22:52:47 +0200
> Subject: [PATCH] avfilter: add zoneplate video test source
> 
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/Makefile   |   1 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vsrc_testsrc.c | 142 +
>  3 files changed, 144 insertions(+)

please add docs

[...]
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2023-05-07 Thread Paul B Mahol
Attached.
From 7b0a8586adc0a142f0b7afcdbdf36ce526f4cd34 Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Sat, 6 May 2023 22:52:47 +0200
Subject: [PATCH] avfilter: add zoneplate video test source

Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vsrc_testsrc.c | 142 +
 3 files changed, 144 insertions(+)

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 93c614eeb7..9fb9a1095f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -598,6 +598,7 @@ OBJS-$(CONFIG_SMPTEHDBARS_FILTER)+= vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC_FILTER)+= vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC2_FILTER)   += vsrc_testsrc.o
 OBJS-$(CONFIG_YUVTESTSRC_FILTER) += vsrc_testsrc.o
+OBJS-$(CONFIG_ZONEPLATE_FILTER)  += vsrc_testsrc.o
 
 OBJS-$(CONFIG_NULLSINK_FILTER)   += vsink_nullsink.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 1c0bc12a92..025966dc45 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -563,6 +563,7 @@ extern const AVFilter ff_vsrc_smptehdbars;
 extern const AVFilter ff_vsrc_testsrc;
 extern const AVFilter ff_vsrc_testsrc2;
 extern const AVFilter ff_vsrc_yuvtestsrc;
+extern const AVFilter ff_vsrc_zoneplate;
 
 extern const AVFilter ff_vsink_nullsink;
 
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index f391ac02e0..b1f7873a9c 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -88,6 +88,14 @@ typedef struct TestSourceContext {
 
 /* only used by haldclut */
 int level;
+
+/* only used by zoneplate */
+int k0, kx, ky, kt;
+int kxt, kyt, kxy;
+int kx2, ky2, kt2;
+int xo, yo, kU, kV;
+int lut_precision;
+uint8_t *lut;
 } TestSourceContext;
 
 #define OFFSET(x) offsetof(TestSourceContext, x)
@@ -135,6 +143,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 TestSourceContext *test = ctx->priv;
 
 av_frame_free(>picref);
+av_freep(>lut);
 }
 
 static int config_props(AVFilterLink *outlink)
@@ -2049,3 +2058,136 @@ const AVFilter ff_vsrc_colorchart = {
 };
 
 #endif /* CONFIG_COLORCHART_FILTER */
+
+#if CONFIG_COLORCHART_FILTER
+
+static const AVOption zoneplate_options[] = {
+COMMON_OPTIONS
+{ "precision", "set LUT precision", OFFSET(lut_precision), AV_OPT_TYPE_INT, {.i64=10}, 4, 16, FLAGS },
+{ "xo", "set x-axis offset", OFFSET(xo), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "yo", "set y-axis offset", OFFSET(yo), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "k0", "set zero order phase", OFFSET(k0), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kx", "set 1st order x-axis phase", OFFSET(kx), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "ky", "set 1st order y-axis phase", OFFSET(ky), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kt", "set 1st order t-axis phase", OFFSET(kt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kxt", "set x*t product phase", OFFSET(kxt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kyt", "set y*t product phase", OFFSET(kyt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kxy", "set x*y product phase", OFFSET(kxy), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kx2", "set 2nd order x-axis phase", OFFSET(kx2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "ky2", "set 2nd order y-axis phase", OFFSET(ky2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kt2", "set 2nd order t-axis phase", OFFSET(kt2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kU", "set zero order U-color phase", OFFSET(kU), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ "kV", "set zero order V-color phase", OFFSET(kV), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(zoneplate);
+
+static int zoneplate_config_props(AVFilterLink *inlink)
+{
+AVFilterContext *ctx = inlink->src;
+TestSourceContext *s = ctx->priv;
+
+if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
+return AVERROR(EINVAL);
+return config_props(inlink);
+}
+
+static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)
+{
+TestSourceContext *test = ctx->priv;
+const int w = frame->width;
+const int h = frame->height;
+const int kxt = test->kxt, kyt = test->kyt, kx2 = test->kx2;
+const int t = test->pts, k0 = test->k0;
+const int kt = test->kt, kt2 = test->kt2, ky2 = test->ky2;
+const int ky = test->ky, kx = test->kx, kxy = test->kxy;
+const int lut_mask = (1 << test->lut_precision) - 1;
+int akx, akxt, aky, akyt, akxy, nky2kt2;
+const int nkt2 = kt2 * t * t, nkt = kt * t;
+const int xreset = -(w / 2) - test->xo;
+const int yreset = -(h / 2) - test->yo;
+const int kU = 

[FFmpeg-devel] [PATCH] avfilter: add zoneplate video source filter

2016-03-25 Thread Paul B Mahol
Hi,

patch attached.
From 8429137e301ec15a8b1f3684ce2d9d6533ec95f2 Mon Sep 17 00:00:00 2001
From: Paul B Mahol 
Date: Fri, 25 Mar 2016 20:40:29 +0100
Subject: [PATCH] avfilter: add zoneplate video source filter

Signed-off-by: Paul B Mahol 
---
 libavfilter/Makefile   |  1 +
 libavfilter/allfilters.c   |  1 +
 libavfilter/vsrc_testsrc.c | 91 ++
 3 files changed, 93 insertions(+)

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index b6e1999..6ff1575 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -295,6 +295,7 @@ OBJS-$(CONFIG_SMPTEBARS_FILTER)  += vsrc_testsrc.o
 OBJS-$(CONFIG_SMPTEHDBARS_FILTER)+= vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC_FILTER)+= vsrc_testsrc.o
 OBJS-$(CONFIG_TESTSRC2_FILTER)   += vsrc_testsrc.o
+OBJS-$(CONFIG_ZONEPLATE_FILTER)  += vsrc_testsrc.o
 
 OBJS-$(CONFIG_NULLSINK_FILTER)   += vsink_nullsink.o
 
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 5c18fd1..597971f 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -315,6 +315,7 @@ void avfilter_register_all(void)
 REGISTER_FILTER(SMPTEHDBARS,smptehdbars,vsrc);
 REGISTER_FILTER(TESTSRC,testsrc,vsrc);
 REGISTER_FILTER(TESTSRC2,   testsrc2,   vsrc);
+REGISTER_FILTER(ZONEPLATE,  zoneplate,  vsrc);
 
 REGISTER_FILTER(NULLSINK,   nullsink,   vsink);
 
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c
index f0c0985..e5f419c 100644
--- a/libavfilter/vsrc_testsrc.c
+++ b/libavfilter/vsrc_testsrc.c
@@ -76,6 +76,11 @@ typedef struct TestSourceContext {
 
 /* only used by haldclut */
 int level;
+
+/* only used by zoneplate */
+float scale;
+float phase;
+float vmove, hmove;
 } TestSourceContext;
 
 #define OFFSET(x) offsetof(TestSourceContext, x)
@@ -1523,3 +1528,89 @@ AVFilter ff_vsrc_allrgb = {
 };
 
 #endif /* CONFIG_ALLRGB_FILTER */
+
+#if CONFIG_ZONEPLATE_FILTER
+
+static const AVOption zoneplate_options[] = {
+{ "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, INT_MAX, FLAGS },
+{ "phase", "set phase speed",   OFFSET(phase), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 512, FLAGS },
+{ "vmove", "set vertical move speed",   OFFSET(vmove), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 512, FLAGS },
+{ "hmove", "set horizontal move speed", OFFSET(hmove), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 512, FLAGS },
+COMMON_OPTIONS
+{ NULL }
+};
+
+AVFILTER_DEFINE_CLASS(zoneplate);
+
+static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)
+{
+TestSourceContext *test = ctx->priv;
+const float scale = test->scale;
+uint8_t *lum = frame->data[0];
+uint8_t *cb = frame->data[1];
+uint8_t *cr = frame->data[2];
+const int cy = frame->height / 2;
+const int cx = frame->width / 2;
+const int nb = test->nb_frame;
+const float phase = test->phase;
+const float vmove = test->vmove;
+const float hmove = test->hmove;
+int x, y, h, w;
+
+for (y = -cy + nb * vmove, h = 0; h < frame->height; y++, h++) {
+for (x = -cx + nb * hmove, w = 0; w < frame->width; x++, w++) {
+lum[w] = 127.5 * cos(M_PI * ((int)((x * x + y * y) * scale) & 0xFF) / 127.5 + nb * phase) + 127.5;
+cb[w] = cr[w] = 128;
+}
+lum += frame->linesize[0];
+cb  += frame->linesize[1];
+cr  += frame->linesize[2];
+}
+}
+
+static av_cold int zoneplate_init(AVFilterContext *ctx)
+{
+TestSourceContext *test = ctx->priv;
+
+if (test->phase == 0 && test->vmove == 0 && test->hmove == 0)
+test->draw_once = 1;
+test->fill_picture_fn = zoneplate_fill_picture;
+return init(ctx);
+}
+
+static int zoneplate_query_formats(AVFilterContext *ctx)
+{
+static const enum AVPixelFormat pix_fmts[] = {
+AV_PIX_FMT_YUV444P,
+AV_PIX_FMT_NONE
+};
+
+AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
+if (!fmts_list)
+return AVERROR(ENOMEM);
+return ff_set_common_formats(ctx, fmts_list);
+}
+
+static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = {
+{
+.name  = "default",
+.type  = AVMEDIA_TYPE_VIDEO,
+.request_frame = request_frame,
+.config_props  = config_props,
+},
+{ NULL }
+};
+
+AVFilter ff_vsrc_zoneplate = {
+.name  = "zoneplate",
+.description   = NULL_IF_CONFIG_SMALL("Generate zone plate test pattern."),
+.priv_size = sizeof(TestSourceContext),
+.priv_class= _class,
+.init  = zoneplate_init,
+.uninit= uninit,
+.query_formats = zoneplate_query_formats,
+.inputs= NULL,
+.outputs   = avfilter_vsrc_zoneplate_outputs,
+};
+
+#endif /* CONFIG_ZONEPLATE_FILTER */
-- 
1.9.1