FFmpeg
vsrc_mandelbrot.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Michael Niedermayer
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * The vsrc_color filter from Stefano Sabatini was used as template to create
21  * this
22  */
23 
24 /**
25  * @file
26  * Mandelbrot fractal renderer
27  */
28 
29 #include "avfilter.h"
30 #include "video.h"
31 #include "internal.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/opt.h"
34 #include <float.h>
35 #include <math.h>
36 
37 #define SQR(a) ((a)*(a))
38 
39 enum Outer{
44 };
45 
46 enum Inner{
51 };
52 
53 typedef struct Point {
54  double p[2];
55  uint32_t val;
56 } Point;
57 
58 typedef struct MBContext {
59  const AVClass *class;
60  int w, h;
62  uint64_t pts;
63  int maxiter;
64  double start_x;
65  double start_y;
66  double start_scale;
67  double end_scale;
68  double end_pts;
69  double bailout;
70  int outer;
71  int inner;
76  double (*zyklus)[2];
77  uint32_t dither;
78 
79  double morphxf;
80  double morphyf;
81  double morphamp;
82 } MBContext;
83 
84 #define OFFSET(x) offsetof(MBContext, x)
85 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
86 
87 static const AVOption mandelbrot_options[] = {
88  {"size", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="640x480"}, 0, 0, FLAGS },
89  {"s", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="640x480"}, 0, 0, FLAGS },
90  {"rate", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
91  {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
92  {"maxiter", "set max iterations number", OFFSET(maxiter), AV_OPT_TYPE_INT, {.i64=7189}, 1, INT_MAX, FLAGS },
93  {"start_x", "set the initial x position", OFFSET(start_x), AV_OPT_TYPE_DOUBLE, {.dbl=-0.743643887037158704752191506114774}, -100, 100, FLAGS },
94  {"start_y", "set the initial y position", OFFSET(start_y), AV_OPT_TYPE_DOUBLE, {.dbl=-0.131825904205311970493132056385139}, -100, 100, FLAGS },
95  {"start_scale", "set the initial scale value", OFFSET(start_scale), AV_OPT_TYPE_DOUBLE, {.dbl=3.0}, 0, FLT_MAX, FLAGS },
96  {"end_scale", "set the terminal scale value", OFFSET(end_scale), AV_OPT_TYPE_DOUBLE, {.dbl=0.3}, 0, FLT_MAX, FLAGS },
97  {"end_pts", "set the terminal pts value", OFFSET(end_pts), AV_OPT_TYPE_DOUBLE, {.dbl=400}, 0, INT64_MAX, FLAGS },
98  {"bailout", "set the bailout value", OFFSET(bailout), AV_OPT_TYPE_DOUBLE, {.dbl=10}, 0, FLT_MAX, FLAGS },
99  {"morphxf", "set morph x frequency", OFFSET(morphxf), AV_OPT_TYPE_DOUBLE, {.dbl=0.01}, -FLT_MAX, FLT_MAX, FLAGS },
100  {"morphyf", "set morph y frequency", OFFSET(morphyf), AV_OPT_TYPE_DOUBLE, {.dbl=0.0123}, -FLT_MAX, FLT_MAX, FLAGS },
101  {"morphamp", "set morph amplitude", OFFSET(morphamp), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -FLT_MAX, FLT_MAX, FLAGS },
102 
103  {"outer", "set outer coloring mode", OFFSET(outer), AV_OPT_TYPE_INT, {.i64=NORMALIZED_ITERATION_COUNT}, 0, INT_MAX, FLAGS, "outer" },
104  {"iteration_count", "set iteration count mode", 0, AV_OPT_TYPE_CONST, {.i64=ITERATION_COUNT}, INT_MIN, INT_MAX, FLAGS, "outer" },
105  {"normalized_iteration_count", "set normalized iteration count mode", 0, AV_OPT_TYPE_CONST, {.i64=NORMALIZED_ITERATION_COUNT}, INT_MIN, INT_MAX, FLAGS, "outer" },
106  {"white", "set white mode", 0, AV_OPT_TYPE_CONST, {.i64=WHITE}, INT_MIN, INT_MAX, FLAGS, "outer" },
107  {"outz", "set outz mode", 0, AV_OPT_TYPE_CONST, {.i64=OUTZ}, INT_MIN, INT_MAX, FLAGS, "outer" },
108 
109  {"inner", "set inner coloring mode", OFFSET(inner), AV_OPT_TYPE_INT, {.i64=MINCOL}, 0, INT_MAX, FLAGS, "inner" },
110  {"black", "set black mode", 0, AV_OPT_TYPE_CONST, {.i64=BLACK}, INT_MIN, INT_MAX, FLAGS, "inner"},
111  {"period", "set period mode", 0, AV_OPT_TYPE_CONST, {.i64=PERIOD}, INT_MIN, INT_MAX, FLAGS, "inner"},
112  {"convergence", "show time until convergence", 0, AV_OPT_TYPE_CONST, {.i64=CONVTIME}, INT_MIN, INT_MAX, FLAGS, "inner"},
113  {"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"},
114 
115  {NULL},
116 };
117 
118 AVFILTER_DEFINE_CLASS(mandelbrot);
119 
121 {
122  MBContext *s = ctx->priv;
123 
124  s->bailout *= s->bailout;
125 
126  s->start_scale /=s->h;
127  s->end_scale /=s->h;
128 
129  s->cache_allocated = s->w * s->h * 3;
130  s->cache_used = 0;
131  s->point_cache= av_malloc_array(s->cache_allocated, sizeof(*s->point_cache));
132  s-> next_cache= av_malloc_array(s->cache_allocated, sizeof(*s-> next_cache));
133  s-> zyklus = av_malloc_array(s->maxiter + 16, sizeof(*s->zyklus));
134 
135  if (!s->point_cache || !s->next_cache || !s->zyklus)
136  return AVERROR(ENOMEM);
137 
138  return 0;
139 }
140 
142 {
143  MBContext *s = ctx->priv;
144 
145  av_freep(&s->point_cache);
146  av_freep(&s-> next_cache);
147  av_freep(&s->zyklus);
148 }
149 
150 static int config_props(AVFilterLink *outlink)
151 {
152  AVFilterContext *ctx = outlink->src;
153  MBContext *s = ctx->priv;
154 
155  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
156  return AVERROR(EINVAL);
157 
158  outlink->w = s->w;
159  outlink->h = s->h;
160  outlink->time_base = av_inv_q(s->frame_rate);
161  outlink->frame_rate = s->frame_rate;
162 
163  return 0;
164 }
165 
166 static void fill_from_cache(AVFilterContext *ctx, uint32_t *color, int *in_cidx, int *out_cidx, double py, double scale){
167  MBContext *s = ctx->priv;
168  if(s->morphamp)
169  return;
170  for(; *in_cidx < s->cache_used; (*in_cidx)++){
171  Point *p= &s->point_cache[*in_cidx];
172  int x;
173  if(p->p[1] > py)
174  break;
175  x= lrint((p->p[0] - s->start_x) / scale + s->w/2);
176  if(x<0 || x >= s->w)
177  continue;
178  if(color) color[x] = p->val;
179  if(out_cidx && *out_cidx < s->cache_allocated)
180  s->next_cache[(*out_cidx)++]= *p;
181  }
182 }
183 
184 static int interpol(MBContext *s, uint32_t *color, int x, int y, int linesize)
185 {
186  uint32_t a,b,c,d, i;
187  uint32_t ipol=0xFF000000;
188  int dist;
189 
190  if(!x || !y || x+1==s->w || y+1==s->h)
191  return 0;
192 
193  dist= FFMAX(FFABS(x-(s->w>>1))*s->h, FFABS(y-(s->h>>1))*s->w);
194 
195  if(dist<(s->w*s->h>>3))
196  return 0;
197 
198  a=color[(x+1) + (y+0)*linesize];
199  b=color[(x-1) + (y+1)*linesize];
200  c=color[(x+0) + (y+1)*linesize];
201  d=color[(x+1) + (y+1)*linesize];
202 
203  if(a&&c){
204  b= color[(x-1) + (y+0)*linesize];
205  d= color[(x+0) + (y-1)*linesize];
206  }else if(b&&d){
207  a= color[(x+1) + (y-1)*linesize];
208  c= color[(x-1) + (y-1)*linesize];
209  }else if(c){
210  d= color[(x+0) + (y-1)*linesize];
211  a= color[(x-1) + (y+0)*linesize];
212  b= color[(x+1) + (y-1)*linesize];
213  }else if(d){
214  c= color[(x-1) + (y-1)*linesize];
215  a= color[(x-1) + (y+0)*linesize];
216  b= color[(x+1) + (y-1)*linesize];
217  }else
218  return 0;
219 
220  for(i=0; i<3; i++){
221  int s= 8*i;
222  uint8_t ac= a>>s;
223  uint8_t bc= b>>s;
224  uint8_t cc= c>>s;
225  uint8_t dc= d>>s;
226  int ipolab= (ac + bc);
227  int ipolcd= (cc + dc);
228  if(FFABS(ipolab - ipolcd) > 5)
229  return 0;
230  if(FFABS(ac-bc)+FFABS(cc-dc) > 20)
231  return 0;
232  ipol |= ((ipolab + ipolcd + 2)/4)<<s;
233  }
234  color[x + y*linesize]= ipol;
235  return 1;
236 }
237 
238 static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
239 {
240  MBContext *s = ctx->priv;
241  int x,y,i, in_cidx=0, next_cidx=0, tmp_cidx;
242  double scale= s->start_scale*pow(s->end_scale/s->start_scale, pts/s->end_pts);
243  int use_zyklus=0;
244  fill_from_cache(ctx, NULL, &in_cidx, NULL, s->start_y+scale*(-s->h/2-0.5), scale);
245  tmp_cidx= in_cidx;
246  memset(color, 0, sizeof(*color)*s->w);
247  for(y=0; y<s->h; y++){
248  int y1= y+1;
249  const double ci=s->start_y+scale*(y-s->h/2);
250  fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci, scale);
251  if(y1<s->h){
252  memset(color+linesize*y1, 0, sizeof(*color)*s->w);
253  fill_from_cache(ctx, color+linesize*y1, &tmp_cidx, NULL, ci + 3*scale/2, scale);
254  }
255 
256  for(x=0; x<s->w; x++){
257  float av_uninit(epsilon);
258  const double cr=s->start_x+scale*(x-s->w/2);
259  double zr=cr;
260  double zi=ci;
261  uint32_t c=0;
262  double dv= s->dither / (double)(1LL<<32);
263  s->dither= s->dither*1664525+1013904223;
264 
265  if(color[x + y*linesize] & 0xFF000000)
266  continue;
267  if(!s->morphamp){
268  if(interpol(s, color, x, y, linesize)){
269  if(next_cidx < s->cache_allocated){
270  s->next_cache[next_cidx ].p[0]= cr;
271  s->next_cache[next_cidx ].p[1]= ci;
272  s->next_cache[next_cidx++].val = color[x + y*linesize];
273  }
274  continue;
275  }
276  }else{
277  zr += cos(pts * s->morphxf) * s->morphamp;
278  zi += sin(pts * s->morphyf) * s->morphamp;
279  }
280 
281  use_zyklus= (x==0 || s->inner!=BLACK ||color[x-1 + y*linesize] == 0xFF000000);
282  if(use_zyklus)
283  epsilon= scale*(abs(x-s->w/2) + abs(y-s->h/2))/s->w;
284 
285 #define Z_Z2_C(outr,outi,inr,ini)\
286  outr= inr*inr - ini*ini + cr;\
287  outi= 2*inr*ini + ci;
288 
289 #define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\
290  Z_Z2_C(outr,outi,inr,ini)\
291  if(use_zyklus){\
292  if(Z && fabs(s->zyklus[i>>1][0]-outr)+fabs(s->zyklus[i>>1][1]-outi) <= epsilon)\
293  break;\
294  }\
295  s->zyklus[i][0]= outr;\
296  s->zyklus[i][1]= outi;\
297 
298 
299 
300  for(i=0; i<s->maxiter-8; i++){
301  double t;
302  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
303  i++;
304  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
305  i++;
306  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
307  i++;
308  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
309  i++;
310  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
311  i++;
312  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
313  i++;
314  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
315  i++;
316  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
317  if(zr*zr + zi*zi > s->bailout){
318  i-= FFMIN(7, i);
319  for(; i<s->maxiter; i++){
320  zr= s->zyklus[i][0];
321  zi= s->zyklus[i][1];
322  if(zr*zr + zi*zi > s->bailout){
323  switch(s->outer){
324  case ITERATION_COUNT:
325  zr = i;
326  c = lrintf((sinf(zr)+1)*127) + lrintf((sinf(zr/1.234)+1)*127)*256*256 + lrintf((sinf(zr/100)+1)*127)*256;
327  break;
329  zr = i + log2(log(s->bailout) / log(zr*zr + zi*zi));
330  c = lrintf((sinf(zr)+1)*127) + lrintf((sinf(zr/1.234)+1)*127)*256*256 + lrintf((sinf(zr/100)+1)*127)*256;
331  break;
332  case WHITE:
333  c = 0xFFFFFF;
334  break;
335  case OUTZ:
336  zr /= s->bailout;
337  zi /= s->bailout;
338  c = (((int)(zr*128+128))&0xFF)*256 + (((int)(zi*128+128))&0xFF);
339  }
340  break;
341  }
342  }
343  break;
344  }
345  }
346  if(!c){
347  if(s->inner==PERIOD){
348  int j;
349  for(j=i-1; j; j--)
350  if(SQR(s->zyklus[j][0]-zr) + SQR(s->zyklus[j][1]-zi) < epsilon*epsilon*10)
351  break;
352  if(j){
353  c= i-j;
354  c= ((c<<5)&0xE0) + ((c<<10)&0xE000) + ((c<<15)&0xE00000);
355  }
356  }else if(s->inner==CONVTIME){
357  c= floor(i*255.0/s->maxiter+dv)*0x010101;
358  } else if(s->inner==MINCOL){
359  int j;
360  double closest=9999;
361  int closest_index=0;
362  for(j=i-1; j>=0; j--)
363  if(SQR(s->zyklus[j][0]) + SQR(s->zyklus[j][1]) < closest){
364  closest= SQR(s->zyklus[j][0]) + SQR(s->zyklus[j][1]);
365  closest_index= j;
366  }
367  closest = sqrt(closest);
368  c= lrintf((s->zyklus[closest_index][0]/closest+1)*127+dv) + lrintf((s->zyklus[closest_index][1]/closest+1)*127+dv)*256;
369  }
370  }
371  c |= 0xFF000000;
372  color[x + y*linesize]= c;
373  if(next_cidx < s->cache_allocated){
374  s->next_cache[next_cidx ].p[0]= cr;
375  s->next_cache[next_cidx ].p[1]= ci;
376  s->next_cache[next_cidx++].val = c;
377  }
378  }
379  fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci + scale/2, scale);
380  }
381  FFSWAP(void*, s->next_cache, s->point_cache);
382  s->cache_used = next_cidx;
383  if(s->cache_used == s->cache_allocated)
384  av_log(ctx, AV_LOG_INFO, "Mandelbrot cache is too small!\n");
385 }
386 
388 {
389  MBContext *s = link->src->priv;
390  AVFrame *picref = ff_get_video_buffer(link, s->w, s->h);
391  if (!picref)
392  return AVERROR(ENOMEM);
393 
394  picref->sample_aspect_ratio = (AVRational) {1, 1};
395  picref->pts = s->pts++;
396  picref->duration = 1;
397 
398  draw_mandelbrot(link->src, (uint32_t*)picref->data[0], picref->linesize[0]/4, picref->pts);
399  return ff_filter_frame(link, picref);
400 }
401 
402 static const AVFilterPad mandelbrot_outputs[] = {
403  {
404  .name = "default",
405  .type = AVMEDIA_TYPE_VIDEO,
406  .request_frame = request_frame,
407  .config_props = config_props,
408  },
409 };
410 
412  .name = "mandelbrot",
413  .description = NULL_IF_CONFIG_SMALL("Render a Mandelbrot fractal."),
414  .priv_size = sizeof(MBContext),
415  .priv_class = &mandelbrot_class,
416  .init = init,
417  .uninit = uninit,
418  .inputs = NULL,
421 };
draw_mandelbrot
static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
Definition: vsrc_mandelbrot.c:238
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:108
MBContext::end_scale
double end_scale
Definition: vsrc_mandelbrot.c:67
interpol
static int interpol(MBContext *s, uint32_t *color, int x, int y, int linesize)
Definition: vsrc_mandelbrot.c:184
init
static av_cold int init(AVFilterContext *ctx)
Definition: vsrc_mandelbrot.c:120
NORMALIZED_ITERATION_COUNT
@ NORMALIZED_ITERATION_COUNT
Definition: vsrc_mandelbrot.c:41
Inner
Inner
Definition: vsrc_mandelbrot.c:46
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
color
Definition: vf_paletteuse.c:511
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:807
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:238
normalize.log
log
Definition: normalize.py:21
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
w
uint8_t w
Definition: llviddspenc.c:38
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(mandelbrot)
AVOption
AVOption.
Definition: opt.h:251
b
#define b
Definition: input.c:41
MBContext::point_cache
Point * point_cache
Definition: vsrc_mandelbrot.c:74
FLAGS
#define FLAGS
Definition: vsrc_mandelbrot.c:85
float.h
MBContext
Definition: vsrc_mandelbrot.c:58
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
MBContext::bailout
double bailout
Definition: vsrc_mandelbrot.c:69
PERIOD
@ PERIOD
Definition: vsrc_mandelbrot.c:48
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
MBContext::next_cache
Point * next_cache
Definition: vsrc_mandelbrot.c:75
video.h
MBContext::w
int w
Definition: vsrc_mandelbrot.c:60
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
SQR
#define SQR(a)
Definition: vsrc_mandelbrot.c:37
MBContext::start_scale
double start_scale
Definition: vsrc_mandelbrot.c:66
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
pts
static int64_t pts
Definition: transcode_aac.c:643
mandelbrot_outputs
static const AVFilterPad mandelbrot_outputs[]
Definition: vsrc_mandelbrot.c:402
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
MBContext::start_x
double start_x
Definition: vsrc_mandelbrot.c:64
ipol
static int ipol(uint8_t *src, int x, int y)
Definition: rotozoom.c:65
lrint
#define lrint
Definition: tablegen.h:53
av_cold
#define av_cold
Definition: attributes.h:90
Z_Z2_C
#define Z_Z2_C(outr, outi, inr, ini)
fill_from_cache
static void fill_from_cache(AVFilterContext *ctx, uint32_t *color, int *in_cidx, int *out_cidx, double py, double scale)
Definition: vsrc_mandelbrot.c:166
BLACK
@ BLACK
Definition: vsrc_mandelbrot.c:47
s
#define s(width, name)
Definition: cbs_vp9.c:198
MBContext::cache_allocated
int cache_allocated
Definition: vsrc_mandelbrot.c:72
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_0BGR32
Definition: pixfmt.h:446
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
MBContext::cache_used
int cache_used
Definition: vsrc_mandelbrot.c:73
CONVTIME
@ CONVTIME
Definition: vsrc_mandelbrot.c:49
ctx
AVFormatContext * ctx
Definition: movenc.c:48
request_frame
static int request_frame(AVFilterLink *link)
Definition: vsrc_mandelbrot.c:387
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
MBContext::frame_rate
AVRational frame_rate
Definition: vsrc_mandelbrot.c:61
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ITERATION_COUNT
@ ITERATION_COUNT
Definition: vsrc_mandelbrot.c:40
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
MBContext::outer
int outer
Definition: vsrc_mandelbrot.c:70
double
double
Definition: af_crystalizer.c:131
abs
#define abs(x)
Definition: cuda_runtime.h:35
MBContext::dither
uint32_t dither
Definition: vsrc_mandelbrot.c:77
sinf
#define sinf(x)
Definition: libm.h:419
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
MBContext::pts
uint64_t pts
Definition: vsrc_mandelbrot.c:62
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
Z_Z2_C_ZYKLUS
#define Z_Z2_C_ZYKLUS(outr, outi, inr, ini, Z)
Point
Definition: signature.h:54
Outer
Outer
Definition: vsrc_mandelbrot.c:39
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
Point::val
uint32_t val
Definition: vsrc_mandelbrot.c:55
MBContext::morphamp
double morphamp
Definition: vsrc_mandelbrot.c:81
ff_vsrc_mandelbrot
const AVFilter ff_vsrc_mandelbrot
Definition: vsrc_mandelbrot.c:411
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
MINCOL
@ MINCOL
Definition: vsrc_mandelbrot.c:50
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vsrc_mandelbrot.c:141
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
MBContext::maxiter
int maxiter
Definition: vsrc_mandelbrot.c:63
internal.h
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:182
MBContext::start_y
double start_y
Definition: vsrc_mandelbrot.c:65
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:53
log2
#define log2(x)
Definition: libm.h:404
AVFilter
Filter definition.
Definition: avfilter.h:166
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
MBContext::morphyf
double morphyf
Definition: vsrc_mandelbrot.c:80
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:447
MBContext::h
int h
Definition: vsrc_mandelbrot.c:60
mandelbrot_options
static const AVOption mandelbrot_options[]
Definition: vsrc_mandelbrot.c:87
OUTZ
@ OUTZ
Definition: vsrc_mandelbrot.c:43
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
MBContext::zyklus
double(* zyklus)[2]
Definition: vsrc_mandelbrot.c:76
Point::p
double p[2]
Definition: vsrc_mandelbrot.c:54
OFFSET
#define OFFSET(x)
Definition: vsrc_mandelbrot.c:84
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:242
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
config_props
static int config_props(AVFilterLink *outlink)
Definition: vsrc_mandelbrot.c:150
d
d
Definition: ffmpeg_filter.c:368
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MBContext::morphxf
double morphxf
Definition: vsrc_mandelbrot.c:79
h
h
Definition: vp9dsp_template.c:2038
MBContext::end_pts
double end_pts
Definition: vsrc_mandelbrot.c:68
av_image_check_size
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...
Definition: imgutils.c:318
int
int
Definition: ffmpeg_filter.c:368
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
WHITE
@ WHITE
Definition: vsrc_mandelbrot.c:42
MBContext::inner
int inner
Definition: vsrc_mandelbrot.c:71