Hi, patch attached.
From 8429137e301ec15a8b1f3684ce2d9d6533ec95f2 Mon Sep 17 00:00:00 2001 From: Paul B Mahol <one...@gmail.com> Date: Fri, 25 Mar 2016 20:40:29 +0100 Subject: [PATCH] avfilter: add zoneplate video source filter
Signed-off-by: Paul B Mahol <one...@gmail.com> --- 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 = &zoneplate_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
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel