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
21120 21120
21121@section sierpinski21121@section sierpinski
21122 21122
21123Generate a Sierpinksi carpet fractal, and randomly pan around.21123Generate a Sierpinksi carpet/triangle fractal, and randomly pan around.
21124 21124
21125This source accepts the following options:21125This source accepts the following options:
21126 21126
@@ -21138,6 +21138,9 @@ Set seed which is used for random panning. · 11 unmodified lines
21138 21138
21139@item jump21139@item jump
21140Set max jump for single pan destination. Allowed range is from 1 to 10000.21140Set max jump for single pan destination. Allowed range is from 1 to 10000.
21141
21142@item type
21143Set fractal type, can be default @code{carpet} or @code{triangle}.
21141@end table21144@end table
21142 21145
21143@c man end VIDEO SOURCES21146@c man end VIDEO SOURCES
libavfilter/vsrc_sierpinski.c+54−22
@@ -39,6 +39,7 @@ · 38 unmodified lines
39typedef struct SierpinskiContext {39typedef struct SierpinskiContext {
40 const AVClass *class;40 const AVClass *class;
41 int w, h;41 int w, h;
42 int type;
42 AVRational frame_rate;43 AVRational frame_rate;
43 uint64_t pts;44 uint64_t pts;
44 45
@@ -49,6 +50,7 @@ typedef struct SierpinskiContext { · 4 unmodified lines
49 int dest_x, dest_y;50 int dest_x, dest_y;
50 51
51 AVLFG lfg;52 AVLFG lfg;
53 int (*draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs);
52} SierpinskiContext;54} SierpinskiContext;
53 55
54#define OFFSET(x) offsetof(SierpinskiContext, x)56#define OFFSET(x) offsetof(SierpinskiContext, x)
@@ -61,6 +63,9 @@ static const AVOption sierpinski_options[] = { · 6 unmodified lines
61 {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, 0, FLAGS },63 {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, 0, FLAGS },
62 {"seed", "set the seed", OFFSET(seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, UINT32_MAX, FLAGS },64 {"seed", "set the seed", OFFSET(seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, UINT32_MAX, FLAGS },
63 {"jump", "set the jump", OFFSET(jump), AV_OPT_TYPE_INT, {.i64=100}, 1, 10000, FLAGS },65 {"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" },
64 {NULL},69 {NULL},
65};70};
66 71
@@ -79,25 +84,6 @@ static int query_formats(AVFilterContext *ctx) · 12 unmodified lines
79 return ff_set_common_formats(ctx, fmts_list);84 return ff_set_common_formats(ctx, fmts_list);
80}85}
81 86
82static 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
101static int fill_sierpinski(SierpinskiContext *s, int x, int y)87static int fill_sierpinski(SierpinskiContext *s, int x, int y)
102{88{
103 int pos_x = x + s->pos_x;89 int pos_x = x + s->pos_x;
@@ -114,7 +100,32 @@ static int fill_sierpinski(SierpinskiContext *s, int x, int y) · 10 unmodified lines
114 return 0;100 return 0;
115}101}
116 102
117static int draw_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)103static 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
128static int draw_carpet_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
118{129{
119 SierpinskiContext *s = ctx->priv;130 SierpinskiContext *s = ctx->priv;
120 AVFrame *frame = arg;131 AVFrame *frame = arg;
@@ -139,6 +150,27 @@ static int draw_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) · 18 unmodified lines
139 return 0;150 return 0;
140}151}
141 152
153static 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
142static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame)174static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame)
143{175{
144 SierpinskiContext *s = ctx->priv;176 SierpinskiContext *s = ctx->priv;
@@ -162,7 +194,7 @@ static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame) · 17 unmodified lines
162 s->pos_y--;194 s->pos_y--;
163 }195 }
164 196
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)));
166}198}
167 199
168static int sierpinski_request_frame(AVFilterLink *link)200static int sierpinski_request_frame(AVFilterLink *link)
@@ -193,7 +225,7 @@ static const AVFilterPad sierpinski_outputs[] = { · 24 unmodified lines
193 225
194AVFilter ff_vsrc_sierpinski = {226AVFilter ff_vsrc_sierpinski = {
195 .name = "sierpinski",227 .name = "sierpinski",
196 .description = NULL_IF_CONFIG_SMALL("Render a Sierpinski carpet fractal."),228 .description = NULL_IF_CONFIG_SMALL("Render a Sierpinski fractal."),
197 .priv_size = sizeof(SierpinskiContext),229 .priv_size = sizeof(SierpinskiContext),
198 .priv_class = &sierpinski_class,230 .priv_class = &sierpinski_class,
199 .query_formats = query_formats,231 .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