History

avfilter/vsrc_sierpinski: add triangle type

Paul B Mahol committed 7 years ago

Commit d0189f81 parent 22f3b622 files · +58 −23Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −1
  2. libavfilter/vsrc_sierpinski.c +54 −22
doc/filters.texi+4−1
@@ -21120,7 +21120,7 @@ __kernel void sierpinski_carpet(__write_only image2d_t dst, · 21119 unmodified lines
2112021120
2112121121 @section sierpinski
2112221122
21123−Generate a Sierpinksi carpet fractal, and randomly pan around.
21123+Generate a Sierpinksi carpet/triangle fractal, and randomly pan around.
2112421124
2112521125 This source accepts the following options:
2112621126
@@ -21138,6 +21138,9 @@ Set seed which is used for random panning. · 11 unmodified lines
2113821138
2113921139 @item jump
2114021140 Set max jump for single pan destination. Allowed range is from 1 to 10000.
21141+
21142+@item type
21143+Set fractal type, can be default @code{carpet} or @code{triangle}.
2114121144 @end table
2114221145
2114321146 @c man end VIDEO SOURCES
libavfilter/vsrc_sierpinski.c+54−22
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939 typedef struct SierpinskiContext {
4040 const AVClass *class;
4141 int w, h;
42+ int type;
4243 AVRational frame_rate;
4344 uint64_t pts;
4445
@@ -49,6 +50,7 @@ typedef struct SierpinskiContext { · 4 unmodified lines
4950 int dest_x, dest_y;
5051
5152 AVLFG lfg;
53+ int (*draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs);
5254 } SierpinskiContext;
5355
5456 #define OFFSET(x) offsetof(SierpinskiContext, x)
@@ -61,6 +63,9 @@ static const AVOption sierpinski_options[] = { · 6 unmodified lines
6163 {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, 0, FLAGS },
6264 {"seed", "set the seed", OFFSET(seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, UINT32_MAX, FLAGS },
6365 {"jump", "set the jump", OFFSET(jump), AV_OPT_TYPE_INT, {.i64=100}, 1, 10000, FLAGS },
66+ {"type","set fractal type",OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "type" },
67+ {"carpet", "sierpinksi carpet", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" },
68+ {"triangle", "sierpinksi triangle", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" },
6469 {NULL},
6570 };
6671
@@ -79,25 +84,6 @@ static int query_formats(AVFilterContext *ctx) · 12 unmodified lines
7984 return ff_set_common_formats(ctx, fmts_list);
8085 }
8186
82−static int config_output(AVFilterLink *inlink)
83−{
84− AVFilterContext *ctx = inlink->src;
85− SierpinskiContext *s = ctx->priv;
86−
87− if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
88− return AVERROR(EINVAL);
89−
90− inlink->w = s->w;
91− inlink->h = s->h;
92− inlink->time_base = av_inv_q(s->frame_rate);
93− inlink->sample_aspect_ratio = (AVRational) {1, 1};
94− if (s->seed == -1)
95− s->seed = av_get_random_seed();
96− av_lfg_init(&s->lfg, s->seed);
97−
98− return 0;
99−}
100−
10187 static int fill_sierpinski(SierpinskiContext *s, int x, int y)
10288 {
10389 int pos_x = x + s->pos_x;
@@ -114,7 +100,32 @@ static int fill_sierpinski(SierpinskiContext *s, int x, int y) · 10 unmodified lines
114100 return 0;
115101 }
116102
117−static int draw_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
103+static int draw_triangle_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
104+{
105+ SierpinskiContext *s = ctx->priv;
106+ AVFrame *frame = arg;
107+ const int width = frame->width;
108+ const int height = frame->height;
109+ const int start = (height * job ) / nb_jobs;
110+ const int end = (height * (job+1)) / nb_jobs;
111+ uint8_t *dst = frame->data[0] + start * frame->linesize[0];
112+
113+ for (int y = start; y < end; y++) {
114+ for (int x = 0; x < width; x++) {
115+ if ((s->pos_x + x) & (s->pos_y + y)) {
116+ AV_WL32(&dst[x*4], 0x00000000);
117+ } else {
118+ AV_WL32(&dst[x*4], 0xFFFFFFFF);
119+ }
120+ }
121+
122+ dst += frame->linesize[0];
123+ }
124+
125+ return 0;
126+}
127+
128+static int draw_carpet_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
118129 {
119130 SierpinskiContext *s = ctx->priv;
120131 AVFrame *frame = arg;
@@ -139,6 +150,27 @@ static int draw_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) · 18 unmodified lines
139150 return 0;
140151 }
141152
153+static int config_output(AVFilterLink *inlink)
154+{
155+ AVFilterContext *ctx = inlink->src;
156+ SierpinskiContext *s = ctx->priv;
157+
158+ if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
159+ return AVERROR(EINVAL);
160+
161+ inlink->w = s->w;
162+ inlink->h = s->h;
163+ inlink->time_base = av_inv_q(s->frame_rate);
164+ inlink->sample_aspect_ratio = (AVRational) {1, 1};
165+ if (s->seed == -1)
166+ s->seed = av_get_random_seed();
167+ av_lfg_init(&s->lfg, s->seed);
168+
169+ s->draw_slice = s->type ? draw_triangle_slice : draw_carpet_slice;
170+
171+ return 0;
172+}
173+
142174 static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame)
143175 {
144176 SierpinskiContext *s = ctx->priv;
@@ -162,7 +194,7 @@ static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame) · 17 unmodified lines
162194 s->pos_y--;
163195 }
164196
165− ctx->internal->execute(ctx, draw_slice, frame, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
197+ ctx->internal->execute(ctx, s->draw_slice, frame, NULL, FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
166198 }
167199
168200 static int sierpinski_request_frame(AVFilterLink *link)
@@ -193,7 +225,7 @@ static const AVFilterPad sierpinski_outputs[] = { · 24 unmodified lines
193225
194226 AVFilter ff_vsrc_sierpinski = {
195227 .name = "sierpinski",
196− .description = NULL_IF_CONFIG_SMALL("Render a Sierpinski carpet fractal."),
228+ .description = NULL_IF_CONFIG_SMALL("Render a Sierpinski fractal."),
197229 .priv_size = sizeof(SierpinskiContext),
198230 .priv_class = &sierpinski_class,
199231 .query_formats = query_formats,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t