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"},
129 s->bailout *=
s->bailout;
131 s->start_scale /=
s->h;
134 s->cache_allocated =
s->w *
s->h * 3;
140 if (!
s->point_cache || !
s->next_cache || !
s->zyklus)
173 for(; *in_cidx <
s->cache_used; (*in_cidx)++){
174 Point *p= &
s->point_cache[*in_cidx];
182 if(out_cidx && *out_cidx < s->cache_allocated)
183 s->next_cache[(*out_cidx)++]= *p;
190 uint32_t
ipol=0xFF000000;
193 if(!x || !y || x+1==
s->w || y+1==
s->h)
198 if(dist<(
s->w*
s->h>>3))
201 a=
color[(x+1) + (y+0)*linesize];
202 b=
color[(x-1) + (y+1)*linesize];
203 c=
color[(x+0) + (y+1)*linesize];
204 d=
color[(x+1) + (y+1)*linesize];
207 b=
color[(x-1) + (y+0)*linesize];
208 d=
color[(x+0) + (y-1)*linesize];
210 a=
color[(x+1) + (y-1)*linesize];
211 c=
color[(x-1) + (y-1)*linesize];
213 d=
color[(x+0) + (y-1)*linesize];
214 a=
color[(x-1) + (y+0)*linesize];
215 b=
color[(x+1) + (y-1)*linesize];
217 c=
color[(x-1) + (y-1)*linesize];
218 a=
color[(x-1) + (y+0)*linesize];
219 b=
color[(x+1) + (y-1)*linesize];
229 int ipolab= (ac + bc);
230 int ipolcd= (cc + dc);
231 if(
FFABS(ipolab - ipolcd) > 5)
235 ipol |= ((ipolab + ipolcd + 2)/4)<<
s;
244 int x,y,
i, in_cidx=0, next_cidx=0, tmp_cidx;
245 double scale=
s->start_scale*pow(
s->end_scale/
s->start_scale,
pts/
s->end_pts);
250 for(y=0; y<
s->h; y++){
252 const double ci=
s->start_y+
scale*(y-
s->h/2);
259 for(x=0; x<
s->w; x++){
261 const double cr=
s->start_x+
scale*(x-
s->w/2);
265 double dv=
s->dither / (
double)(1LL<<32);
266 s->dither=
s->dither*1664525+1013904223;
268 if(
color[x + y*linesize] & 0xFF000000)
272 if(next_cidx < s->cache_allocated){
273 s->next_cache[next_cidx ].p[0]=
cr;
274 s->next_cache[next_cidx ].p[1]= ci;
275 s->next_cache[next_cidx++].val =
color[x + y*linesize];
280 zr += cos(
pts *
s->morphxf) *
s->morphamp;
281 zi += sin(
pts *
s->morphyf) *
s->morphamp;
284 use_zyklus= (x==0 ||
s->inner!=
BLACK ||
color[x-1 + y*linesize] == 0xFF000000);
288#define Z_Z2_C(outr,outi,inr,ini)\
289 outr= inr*inr - ini*ini + cr;\
290 outi= 2*inr*ini + ci;
292#define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\
293 Z_Z2_C(outr,outi,inr,ini)\
295 if(Z && fabs(s->zyklus[i>>1][0]-outr)+fabs(s->zyklus[i>>1][1]-outi) <= epsilon)\
298 s->zyklus[i][0]= outr;\
299 s->zyklus[i][1]= outi;\
303 for(
i=0;
i<
s->maxiter-8;
i++){
320 if(zr*zr + zi*zi >
s->bailout){
322 for(;
i<
s->maxiter;
i++){
325 if(zr*zr + zi*zi >
s->bailout){
329 c =
lrintf((sinf(zr)+1)*127) +
lrintf((sinf(zr/1.234)+1)*127)*256*256 +
lrintf((sinf(zr/100)+1)*127)*256;
332 zr =
i +
log2(log(
s->bailout) / log(zr*zr + zi*zi));
333 c =
lrintf((sinf(zr)+1)*127) +
lrintf((sinf(zr/1.234)+1)*127)*256*256 +
lrintf((sinf(zr/100)+1)*127)*256;
341 c = (((int)(zr*128+128))&0xFF)*256 + (((
int)(zi*128+128))&0xFF);
353 if(
SQR(
s->zyklus[j][0]-zr) +
SQR(
s->zyklus[j][1]-zi) < epsilon*epsilon*10)
357 c= ((
c<<5)&0xE0) + ((
c<<10)&0xE000) + ((
c<<15)&0xE00000);
360 c=
floor(
i*255.0/
s->maxiter+dv)*0x010101;
365 for(j=
i-1; j>=0; j--)
366 if(
SQR(
s->zyklus[j][0]) +
SQR(
s->zyklus[j][1]) < closest){
367 closest=
SQR(
s->zyklus[j][0]) +
SQR(
s->zyklus[j][1]);
370 closest = sqrt(closest);
371 c=
lrintf((
s->zyklus[closest_index][0]/closest+1)*127+dv) +
lrintf((
s->zyklus[closest_index][1]/closest+1)*127+dv)*256;
376 if(next_cidx < s->cache_allocated){
377 s->next_cache[next_cidx ].p[0]=
cr;
378 s->next_cache[next_cidx ].p[1]= ci;
379 s->next_cache[next_cidx++].val =
c;
384 FFSWAP(
void*,
s->next_cache,
s->point_cache);
385 s->cache_used = next_cidx;
386 if(
s->cache_used ==
s->cache_allocated)
398 picref->
pts =
s->pts++;
415 .p.name =
"mandelbrot",
417 .p.priv_class = &mandelbrot_class,
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vsrc_mandelbrot
static AVFormatContext * ctx
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 av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], 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 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)