33 #include "libavutil/imgutils.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/parseutils.h"
39 #define SQR(a) ((a)*(a))
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"},
179 for(; *in_cidx < mb->
cache_used; (*in_cidx)++){
185 if(x<0 || x >= mb->
w)
187 if(color) color[x] = p->
val;
188 if(out_cidx && *out_cidx < mb->cache_allocated)
196 uint32_t
ipol=0xFF000000;
199 if(!x || !y || x+1==mb->
w || y+1==mb->
h)
204 if(dist<(mb->
w*mb->
h>>3))
207 a=color[(x+1) + (y+0)*linesize];
208 b=color[(x-1) + (y+1)*linesize];
209 c=color[(x+0) + (y+1)*linesize];
210 d=color[(x+1) + (y+1)*linesize];
213 b= color[(x-1) + (y+0)*linesize];
214 d= color[(x+0) + (y-1)*linesize];
216 a= color[(x+1) + (y-1)*linesize];
217 c= color[(x-1) + (y-1)*linesize];
219 d= color[(x+0) + (y-1)*linesize];
220 a= color[(x-1) + (y+0)*linesize];
221 b= color[(x+1) + (y-1)*linesize];
223 c= color[(x-1) + (y-1)*linesize];
224 a= color[(x-1) + (y+0)*linesize];
225 b= color[(x+1) + (y-1)*linesize];
235 int ipolab= (ac + bc);
236 int ipolcd= (cc +
dc);
237 if(
FFABS(ipolab - ipolcd) > 5)
241 ipol |= ((ipolab + ipolcd + 2)/4)<<
s;
243 color[x + y*linesize]=
ipol;
250 int x,
y,i, in_cidx=0, next_cidx=0, tmp_cidx;
255 memset(color, 0,
sizeof(*color)*mb->
w);
256 for(y=0; y<mb->
h; y++){
258 const double ci=mb->
start_y+scale*(y-mb->
h/2);
261 memset(color+linesize*y1, 0,
sizeof(*color)*mb->
w);
262 fill_from_cache(ctx, color+linesize*y1, &tmp_cidx, NULL, ci + 3*scale/2, scale);
265 for(x=0; x<mb->
w; x++){
267 const double cr=mb->
start_x+scale*(x-mb->
w/2);
271 double dv= mb->
dither / (double)(1LL<<32);
274 if(color[x + y*linesize] & 0xFF000000)
277 if(
interpol(mb, color, x, y, linesize)){
278 if(next_cidx < mb->cache_allocated){
290 use_zyklus= (x==0 || mb->
inner!=
BLACK ||color[x-1 + y*linesize] == 0xFF000000);
292 epsilon= scale*1*sqrt(
SQR(x-mb->
w/2) +
SQR(y-mb->
h/2))/mb->
w;
294 #define Z_Z2_C(outr,outi,inr,ini)\
295 outr= inr*inr - ini*ini + cr;\
296 outi= 2*inr*ini + ci;
298 #define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\
299 Z_Z2_C(outr,outi,inr,ini)\
301 if(Z && fabs(mb->zyklus[i>>1][0]-outr)+fabs(mb->zyklus[i>>1][1]-outi) <= epsilon)\
304 mb->zyklus[i][0]= outr;\
305 mb->zyklus[i][1]= outi;\
309 for(i=0; i<mb->
maxiter-8; i++){
326 if(zr*zr + zi*zi > mb->
bailout){
331 if(zr*zr + zi*zi > mb->
bailout){
335 c =
lrintf((sin(zr)+1)*127) +
lrintf((sin(zr/1.234)+1)*127)*256*256 +
lrintf((sin(zr/100)+1)*127)*256;
338 zr = i +
log2(log(mb->
bailout) / log(zr*zr + zi*zi));
339 c =
lrintf((sin(zr)+1)*127) +
lrintf((sin(zr/1.234)+1)*127)*256*256 +
lrintf((sin(zr/100)+1)*127)*256;
347 c = (((int)(zr*128+128))&0xFF)*256 + (((int)(zi*128+128))&0xFF);
363 c= ((c<<5)&0xE0) + ((c<<10)&0xE000) + ((c<<15)&0xE00000);
366 c= floor(i*255.0/mb->
maxiter+dv)*0x010101;
371 for(j=i-1; j>=0; j--)
376 closest = sqrt(closest);
377 c=
lrintf((mb->
zyklus[closest_index][0]/closest+1)*127+dv) +
lrintf((mb->
zyklus[closest_index][1]/closest+1)*127+dv)*256;
381 color[x + y*linesize]=
c;
382 if(next_cidx < mb->cache_allocated){
421 .
name =
"mandelbrot",
424 .priv_class = &mandelbrot_class,
This structure describes decoded (raw) audio or video data.
static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
int h
agreed upon image height
static int interpol(MBContext *mb, uint32_t *color, int x, int y, int linesize)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
AVFilter avfilter_vsrc_mandelbrot
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static const AVOption mandelbrot_options[]
static av_cold void uninit(AVFilterContext *ctx)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static const AVFilterPad mandelbrot_outputs[]
#define FFSWAP(type, a, b)
A filter pad used for either input or output.
A link between two filters.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;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);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
#define Z_Z2_C_ZYKLUS(outr, outi, inr, ini, Z)
static av_always_inline av_const double round(double x)
AVPixelFormat
Pixel format.
int w
agreed upon image width
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...
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void fill_from_cache(AVFilterContext *ctx, uint32_t *color, int *in_cidx, int *out_cidx, double py, double scale)
static int request_frame(AVFilterLink *link)
Main libavfilter public API header.
#define AV_LOG_INFO
Standard information.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
rational number numerator/denominator
offset must point to AVRational
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
offset must point to two consecutive integers
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static const uint16_t scale[4]
#define AVFILTER_DEFINE_CLASS(fname)
static int ipol(uint8_t *src, int x, int y)
static double cr(void *priv, double x, double y)
static int config_props(AVFilterLink *inlink)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.