38#define SQR(a) ((a)*(a))
85#define OFFSET(x) offsetof(MBContext, x)
86#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
94 {
"start_x",
"set the initial x position",
OFFSET(start_x),
AV_OPT_TYPE_DOUBLE, {.dbl=-0.743643887037158704752191506114774}, -100, 100,
FLAGS },
95 {
"start_y",
"set the initial y position",
OFFSET(start_y),
AV_OPT_TYPE_DOUBLE, {.dbl=-0.131825904205311970493132056385139}, -100, 100,
FLAGS },
114 {
"mincol",
"color based on point closest to the origin of the iterations", 0,
AV_OPT_TYPE_CONST, {.i64=
MINCOL}, INT_MIN, INT_MAX,
FLAGS, .unit =
"inner"},
125 s->bailout *=
s->bailout;
127 s->start_scale /=
s->h;
130 s->cache_allocated =
s->w *
s->h * 3;
136 if (!
s->point_cache || !
s->next_cache || !
s->zyklus)
172 for(; *in_cidx <
s->cache_used; (*in_cidx)++){
173 Point *p= &
s->point_cache[*in_cidx];
181 if(out_cidx && *out_cidx < s->cache_allocated)
182 s->next_cache[(*out_cidx)++]= *p;
189 uint32_t
ipol=0xFF000000;
192 if(!x || !y || x+1==
s->w || y+1==
s->h)
197 if(dist<(
s->w*
s->h>>3))
200 a=
color[(x+1) + (y+0)*linesize];
201 b=
color[(x-1) + (y+1)*linesize];
202 c=
color[(x+0) + (y+1)*linesize];
203 d=
color[(x+1) + (y+1)*linesize];
206 b=
color[(x-1) + (y+0)*linesize];
207 d=
color[(x+0) + (y-1)*linesize];
209 a=
color[(x+1) + (y-1)*linesize];
210 c=
color[(x-1) + (y-1)*linesize];
212 d=
color[(x+0) + (y-1)*linesize];
213 a=
color[(x-1) + (y+0)*linesize];
214 b=
color[(x+1) + (y-1)*linesize];
216 c=
color[(x-1) + (y-1)*linesize];
217 a=
color[(x-1) + (y+0)*linesize];
218 b=
color[(x+1) + (y-1)*linesize];
228 int ipolab= (ac + bc);
229 int ipolcd= (cc + dc);
230 if(
FFABS(ipolab - ipolcd) > 5)
234 ipol |= ((ipolab + ipolcd + 2)/4)<<
s;
243 int x,y,
i, in_cidx=0, next_cidx=0, tmp_cidx;
244 double scale=
s->start_scale*pow(
s->end_scale/
s->start_scale,
pts/
s->end_pts);
249 for(y=0; y<
s->h; y++){
251 const double ci=
s->start_y+
scale*(y-
s->h/2);
258 for(x=0; x<
s->w; x++){
260 const double cr=
s->start_x+
scale*(x-
s->w/2);
264 double dv=
s->dither / (
double)(1LL<<32);
265 s->dither=
s->dither*1664525+1013904223;
267 if(
color[x + y*linesize] & 0xFF000000)
271 if(next_cidx < s->cache_allocated){
272 s->next_cache[next_cidx ].p[0]=
cr;
273 s->next_cache[next_cidx ].p[1]= ci;
274 s->next_cache[next_cidx++].val =
color[x + y*linesize];
279 zr += cos(
pts *
s->morphxf) *
s->morphamp;
280 zi += sin(
pts *
s->morphyf) *
s->morphamp;
283 use_zyklus= (x==0 ||
s->inner!=
BLACK ||
color[x-1 + y*linesize] == 0xFF000000);
287#define Z_Z2_C(outr,outi,inr,ini)\
288 outr= inr*inr - ini*ini + cr;\
289 outi= 2*inr*ini + ci;
291#define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\
292 Z_Z2_C(outr,outi,inr,ini)\
294 if(Z && fabs(s->zyklus[i>>1][0]-outr)+fabs(s->zyklus[i>>1][1]-outi) <= epsilon)\
297 s->zyklus[i][0]= outr;\
298 s->zyklus[i][1]= outi;\
302 for(
i=0;
i<
s->maxiter-8;
i++){
319 if(zr*zr + zi*zi >
s->bailout){
321 for(;
i<
s->maxiter;
i++){
324 if(zr*zr + zi*zi >
s->bailout){
331 zr =
i +
log2(log(
s->bailout) / log(zr*zr + zi*zi));
340 c = (((int)(zr*128+128))&0xFF)*256 + (((
int)(zi*128+128))&0xFF);
352 if(
SQR(
s->zyklus[j][0]-zr) +
SQR(
s->zyklus[j][1]-zi) < epsilon*epsilon*10)
356 c= ((
c<<5)&0xE0) + ((
c<<10)&0xE000) + ((
c<<15)&0xE00000);
359 c=
floor(
i*255.0/
s->maxiter+dv)*0x010101;
364 for(j=
i-1; j>=0; j--)
365 if(
SQR(
s->zyklus[j][0]) +
SQR(
s->zyklus[j][1]) < closest){
366 closest=
SQR(
s->zyklus[j][0]) +
SQR(
s->zyklus[j][1]);
369 closest = sqrt(closest);
370 c=
lrintf((
s->zyklus[closest_index][0]/closest+1)*127+dv) +
lrintf((
s->zyklus[closest_index][1]/closest+1)*127+dv)*256;
375 if(next_cidx < s->cache_allocated){
376 s->next_cache[next_cidx ].p[0]=
cr;
377 s->next_cache[next_cidx ].p[1]= ci;
378 s->next_cache[next_cidx++].val =
c;
383 FFSWAP(
void*,
s->next_cache,
s->point_cache);
384 s->cache_used = next_cidx;
385 if(
s->cache_used ==
s->cache_allocated)
397 picref->
pts =
s->pts++;
414 .p.name =
"mandelbrot",
416 .p.priv_class = &mandelbrot_class,
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vsrc_mandelbrot
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static __device__ float floor(float a)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
#define AV_LOG_INFO
Standard information.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_OUTPUTS(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FFSWAP(type, a, b)
Memory handling functions.
#define AV_PIX_FMT_0BGR32
static int ipol(uint8_t *src, int x, int y)
static int config_props(AVBitStreamFilterLink *link)
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int64_t duration
Duration of the frame, in the same units as pts.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
#define av_malloc_array(a, b)
static AVFormatContext * ctx
static double cr(void *priv, double x, double y)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
@ NORMALIZED_ITERATION_COUNT
static const AVFilterPad mandelbrot_outputs[]
static int config_props(AVFilterLink *outlink)
#define Z_Z2_C_ZYKLUS(outr, outi, inr, ini, Z)
static const AVOption mandelbrot_options[]
static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
static int request_frame(AVFilterLink *link)
static av_cold void uninit(AVFilterContext *ctx)
static int interpol(MBContext *s, uint32_t *color, int x, int y, int linesize)
static void fill_from_cache(AVFilterContext *ctx, uint32_t *color, int *in_cidx, int *out_cidx, double py, double scale)