39 #define SQR(a) ((a)*(a))
55 typedef struct Point {
86 #define OFFSET(x) offsetof(MBContext, x)
87 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
95 {
"start_x",
"set the initial x position",
OFFSET(start_x),
AV_OPT_TYPE_DOUBLE, {.dbl=-0.743643887037158704752191506114774}, -100, 100,
FLAGS },
96 {
"start_y",
"set the initial y position",
OFFSET(start_y),
AV_OPT_TYPE_DOUBLE, {.dbl=-0.131825904205311970493132056385139}, -100, 100,
FLAGS },
115 {
"mincol",
"color based on point closest to the origin of the iterations", 0,
AV_OPT_TYPE_CONST, {.i64=
MINCOL}, INT_MIN, INT_MAX,
FLAGS,
"inner"},
126 s->bailout *=
s->bailout;
128 s->start_scale /=
s->h;
131 s->cache_allocated =
s->w *
s->h * 3;
181 for(; *in_cidx <
s->cache_used; (*in_cidx)++){
182 Point *p= &
s->point_cache[*in_cidx];
186 x=
lrint((p->
p[0] -
s->start_x) / scale +
s->w/2);
190 if(out_cidx && *out_cidx < s->cache_allocated)
191 s->next_cache[(*out_cidx)++]= *p;
198 uint32_t
ipol=0xFF000000;
201 if(!x || !y || x+1==
s->w || y+1==
s->h)
206 if(dist<(
s->w*
s->h>>3))
209 a=
color[(x+1) + (y+0)*linesize];
210 b=
color[(x-1) + (y+1)*linesize];
211 c=
color[(x+0) + (y+1)*linesize];
212 d=
color[(x+1) + (y+1)*linesize];
215 b=
color[(x-1) + (y+0)*linesize];
216 d=
color[(x+0) + (y-1)*linesize];
218 a=
color[(x+1) + (y-1)*linesize];
219 c=
color[(x-1) + (y-1)*linesize];
221 d=
color[(x+0) + (y-1)*linesize];
222 a=
color[(x-1) + (y+0)*linesize];
223 b=
color[(x+1) + (y-1)*linesize];
225 c=
color[(x-1) + (y-1)*linesize];
226 a=
color[(x-1) + (y+0)*linesize];
227 b=
color[(x+1) + (y-1)*linesize];
237 int ipolab= (ac + bc);
238 int ipolcd= (cc +
dc);
239 if(
FFABS(ipolab - ipolcd) > 5)
243 ipol |= ((ipolab + ipolcd + 2)/4)<<
s;
252 int x,y,
i, in_cidx=0, next_cidx=0, tmp_cidx;
253 double scale=
s->start_scale*pow(
s->end_scale/
s->start_scale,
pts/
s->end_pts);
258 for(y=0; y<
s->h; y++){
260 const double ci=
s->start_y+scale*(y-
s->h/2);
267 for(x=0; x<
s->w; x++){
269 const double cr=
s->start_x+scale*(x-
s->w/2);
273 double dv=
s->dither / (double)(1LL<<32);
274 s->dither=
s->dither*1664525+1013904223;
276 if(
color[x + y*linesize] & 0xFF000000)
280 if(next_cidx < s->cache_allocated){
281 s->next_cache[next_cidx ].p[0]=
cr;
282 s->next_cache[next_cidx ].p[1]= ci;
283 s->next_cache[next_cidx++].val =
color[x + y*linesize];
288 zr += cos(
pts *
s->morphxf) *
s->morphamp;
289 zi += sin(
pts *
s->morphyf) *
s->morphamp;
292 use_zyklus= (x==0 ||
s->inner!=
BLACK ||
color[x-1 + y*linesize] == 0xFF000000);
294 epsilon= scale*(
abs(x-
s->w/2) +
abs(y-
s->h/2))/
s->w;
296 #define
Z_Z2_C(outr,outi,inr,ini)\
297 outr= inr*inr - ini*ini +
cr;\
298 outi= 2*inr*ini + ci;
300 #define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\
301 Z_Z2_C(outr,outi,inr,ini)\
303 if(Z && fabs(s->zyklus[i>>1][0]-outr)+fabs(s->zyklus[i>>1][1]-outi) <= epsilon)\
306 s->zyklus[i][0]= outr;\
307 s->zyklus[i][1]= outi;\
311 for(
i=0;
i<
s->maxiter-8;
i++){
328 if(zr*zr + zi*zi >
s->bailout){
330 for(;
i<
s->maxiter;
i++){
333 if(zr*zr + zi*zi >
s->bailout){
340 zr =
i +
log2(log(
s->bailout) / log(zr*zr + zi*zi));
349 c = (((
int)(zr*128+128))&0xFF)*256 + (((
int)(zi*128+128))&0xFF);
361 if(
SQR(
s->zyklus[j][0]-zr) +
SQR(
s->zyklus[j][1]-zi) < epsilon*epsilon*10)
365 c= ((
c<<5)&0xE0) + ((
c<<10)&0xE000) + ((
c<<15)&0xE00000);
368 c=
floor(
i*255.0/
s->maxiter+dv)*0x010101;
373 for(j=
i-1; j>=0; j--)
374 if(
SQR(
s->zyklus[j][0]) +
SQR(
s->zyklus[j][1]) < closest){
375 closest=
SQR(
s->zyklus[j][0]) +
SQR(
s->zyklus[j][1]);
378 closest = sqrt(closest);
379 c=
lrintf((
s->zyklus[closest_index][0]/closest+1)*127+dv) +
lrintf((
s->zyklus[closest_index][1]/closest+1)*127+dv)*256;
384 if(next_cidx < s->cache_allocated){
385 s->next_cache[next_cidx ].p[0]=
cr;
386 s->next_cache[next_cidx ].p[1]= ci;
387 s->next_cache[next_cidx++].val =
c;
392 FFSWAP(
void*,
s->next_cache,
s->point_cache);
393 s->cache_used = next_cidx;
394 if(
s->cache_used ==
s->cache_allocated)
406 picref->
pts =
s->pts++;
423 .
name =
"mandelbrot",
426 .priv_class = &mandelbrot_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define FFSWAP(type, a, b)
#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)
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
#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...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_0BGR32
static int ipol(uint8_t *src, int x, int y)
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.
const char * name
Pad name.
const char * name
Filter name.
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, size in bytes of each picture line.
Rational number (pair of numerator and denominator).
#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[]
#define Z_Z2_C(outr, outi, inr, ini)
#define Z_Z2_C_ZYKLUS(outr, outi, inr, ini, Z)
AVFILTER_DEFINE_CLASS(mandelbrot)
static const AVOption mandelbrot_options[]
static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
static int query_formats(AVFilterContext *ctx)
static int request_frame(AVFilterLink *link)
AVFilter ff_vsrc_mandelbrot
static int config_props(AVFilterLink *inlink)
static av_cold int init(AVFilterContext *ctx)
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)