| @@ -39,6 +39,7 @@ · 38 unmodified lines |
| 39 | 39 | typedef struct SierpinskiContext { |
| 40 | 40 | const AVClass *class; |
| 41 | 41 | int w, h; |
| 42 | + int type; |
| 42 | 43 | AVRational frame_rate; |
| 43 | 44 | uint64_t pts; |
| 44 | 45 | |
| @@ -49,6 +50,7 @@ typedef struct SierpinskiContext { · 4 unmodified lines |
| 49 | 50 | int dest_x, dest_y; |
| 50 | 51 | |
| 51 | 52 | AVLFG lfg; |
| 53 | + int (*draw_slice)(AVFilterContext *ctx, void *arg, int job, int nb_jobs); |
| 52 | 54 | } SierpinskiContext; |
| 53 | 55 | |
| 54 | 56 | #define OFFSET(x) offsetof(SierpinskiContext, x) |
| @@ -61,6 +63,9 @@ static const AVOption sierpinski_options[] = { · 6 unmodified lines |
| 61 | 63 | {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, 0, FLAGS }, |
| 62 | 64 | {"seed", "set the seed", OFFSET(seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, UINT32_MAX, FLAGS }, |
| 63 | 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 | 69 | {NULL}, |
| 65 | 70 | }; |
| 66 | 71 | |
| @@ -79,25 +84,6 @@ static int query_formats(AVFilterContext *ctx) · 12 unmodified lines |
| 79 | 84 | return ff_set_common_formats(ctx, fmts_list); |
| 80 | 85 | } |
| 81 | 86 | |
| 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 | | − |
| 101 | 87 | static int fill_sierpinski(SierpinskiContext *s, int x, int y) |
| 102 | 88 | { |
| 103 | 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 | 100 | return 0; |
| 115 | 101 | } |
| 116 | 102 | |
| 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) |
| 118 | 129 | { |
| 119 | 130 | SierpinskiContext *s = ctx->priv; |
| 120 | 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 | 150 | return 0; |
| 140 | 151 | } |
| 141 | 152 | |
| 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 | + |
| 142 | 174 | static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame) |
| 143 | 175 | { |
| 144 | 176 | SierpinskiContext *s = ctx->priv; |
| @@ -162,7 +194,7 @@ static void draw_sierpinski(AVFilterContext *ctx, AVFrame *frame) · 17 unmodified lines |
| 162 | 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 | |
| 168 | 200 | static int sierpinski_request_frame(AVFilterLink *link) |
| @@ -193,7 +225,7 @@ static const AVFilterPad sierpinski_outputs[] = { · 24 unmodified lines |
| 193 | 225 | |
| 194 | 226 | AVFilter ff_vsrc_sierpinski = { |
| 195 | 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 | 229 | .priv_size = sizeof(SierpinskiContext), |
| 198 | 230 | .priv_class = &sierpinski_class, |
| 199 | 231 | .query_formats = query_formats, |