FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 fraktal renderer
27  */
28 
29 #include "avfilter.h"
30 #include "formats.h"
31 #include "video.h"
32 #include "internal.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/parseutils.h"
36 #include <float.h>
37 #include <math.h>
38 
39 #define SQR(a) ((a)*(a))
40 
41 enum Outer{
46 };
47 
48 enum Inner{
53 };
54 
55 typedef struct Point {
56  double p[2];
57  uint32_t val;
58 } Point;
59 
60 typedef struct {
61  const AVClass *class;
62  int w, h;
64  uint64_t pts;
65  int maxiter;
66  double start_x;
67  double start_y;
68  double start_scale;
69  double end_scale;
70  double end_pts;
71  double bailout;
72  int outer;
73  int inner;
78  double (*zyklus)[2];
79  uint32_t dither;
80 
81  double morphxf;
82  double morphyf;
83  double morphamp;
84 } MBContext;
85 
86 #define OFFSET(x) offsetof(MBContext, x)
87 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
88 
89 static const AVOption mandelbrot_options[] = {
90  {"size", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="640x480"}, CHAR_MIN, CHAR_MAX, FLAGS },
91  {"s", "set frame size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="640x480"}, CHAR_MIN, CHAR_MAX, FLAGS },
92  {"rate", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, CHAR_MIN, CHAR_MAX, FLAGS },
93  {"r", "set frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, CHAR_MIN, CHAR_MAX, FLAGS },
94  {"maxiter", "set max iterations number", OFFSET(maxiter), AV_OPT_TYPE_INT, {.i64=7189}, 1, INT_MAX, FLAGS },
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 },
97  {"start_scale", "set the initial scale value", OFFSET(start_scale), AV_OPT_TYPE_DOUBLE, {.dbl=3.0}, 0, FLT_MAX, FLAGS },
98  {"end_scale", "set the terminal scale value", OFFSET(end_scale), AV_OPT_TYPE_DOUBLE, {.dbl=0.3}, 0, FLT_MAX, FLAGS },
99  {"end_pts", "set the terminal pts value", OFFSET(end_pts), AV_OPT_TYPE_DOUBLE, {.dbl=400}, 0, INT64_MAX, FLAGS },
100  {"bailout", "set the bailout value", OFFSET(bailout), AV_OPT_TYPE_DOUBLE, {.dbl=10}, 0, FLT_MAX, FLAGS },
101  {"morphxf", "set morph x frequency", OFFSET(morphxf), AV_OPT_TYPE_DOUBLE, {.dbl=0.01}, -FLT_MAX, FLT_MAX, FLAGS },
102  {"morphyf", "set morph y frequency", OFFSET(morphyf), AV_OPT_TYPE_DOUBLE, {.dbl=0.0123}, -FLT_MAX, FLT_MAX, FLAGS },
103  {"morphamp", "set morph amplitude", OFFSET(morphamp), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -FLT_MAX, FLT_MAX, FLAGS },
104 
105  {"outer", "set outer coloring mode", OFFSET(outer), AV_OPT_TYPE_INT, {.i64=NORMALIZED_ITERATION_COUNT}, 0, INT_MAX, FLAGS, "outer" },
106  {"iteration_count", "set iteration count mode", 0, AV_OPT_TYPE_CONST, {.i64=ITERATION_COUNT}, INT_MIN, INT_MAX, FLAGS, "outer" },
107  {"normalized_iteration_count", "set normalized iteration count mode", 0, AV_OPT_TYPE_CONST, {.i64=NORMALIZED_ITERATION_COUNT}, INT_MIN, INT_MAX, FLAGS, "outer" },
108  {"white", "set white mode", 0, AV_OPT_TYPE_CONST, {.i64=WHITE}, INT_MIN, INT_MAX, FLAGS, "outer" },
109  {"outz", "set outz mode", 0, AV_OPT_TYPE_CONST, {.i64=OUTZ}, INT_MIN, INT_MAX, FLAGS, "outer" },
110 
111  {"inner", "set inner coloring mode", OFFSET(inner), AV_OPT_TYPE_INT, {.i64=MINCOL}, 0, INT_MAX, FLAGS, "inner" },
112  {"black", "set black mode", 0, AV_OPT_TYPE_CONST, {.i64=BLACK}, INT_MIN, INT_MAX, FLAGS, "inner"},
113  {"period", "set period mode", 0, AV_OPT_TYPE_CONST, {.i64=PERIOD}, INT_MIN, INT_MAX, FLAGS, "inner"},
114  {"convergence", "show time until convergence", 0, AV_OPT_TYPE_CONST, {.i64=CONVTIME}, INT_MIN, INT_MAX, FLAGS, "inner"},
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"},
116 
117  {NULL},
118 };
119 
120 AVFILTER_DEFINE_CLASS(mandelbrot);
121 
122 static av_cold int init(AVFilterContext *ctx)
123 {
124  MBContext *mb = ctx->priv;
125 
126  mb->bailout *= mb->bailout;
127 
128  mb->start_scale /=mb->h;
129  mb->end_scale /=mb->h;
130 
131  mb->cache_allocated = mb->w * mb->h * 3;
132  mb->cache_used = 0;
133  mb->point_cache= av_malloc_array(mb->cache_allocated, sizeof(*mb->point_cache));
134  mb-> next_cache= av_malloc_array(mb->cache_allocated, sizeof(*mb-> next_cache));
135  mb-> zyklus = av_malloc_array(mb->maxiter + 16, sizeof(*mb->zyklus));
136 
137  return 0;
138 }
139 
140 static av_cold void uninit(AVFilterContext *ctx)
141 {
142  MBContext *mb = ctx->priv;
143 
144  av_freep(&mb->point_cache);
145  av_freep(&mb-> next_cache);
146  av_freep(&mb->zyklus);
147 }
148 
150 {
151  static const enum AVPixelFormat pix_fmts[] = {
154  };
155 
156  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
157  if (!fmts_list)
158  return AVERROR(ENOMEM);
159  return ff_set_common_formats(ctx, fmts_list);
160 }
161 
162 static int config_props(AVFilterLink *inlink)
163 {
164  AVFilterContext *ctx = inlink->src;
165  MBContext *mb = ctx->priv;
166 
167  if (av_image_check_size(mb->w, mb->h, 0, ctx) < 0)
168  return AVERROR(EINVAL);
169 
170  inlink->w = mb->w;
171  inlink->h = mb->h;
172  inlink->time_base = av_inv_q(mb->frame_rate);
173 
174  return 0;
175 }
176 
177 static void fill_from_cache(AVFilterContext *ctx, uint32_t *color, int *in_cidx, int *out_cidx, double py, double scale){
178  MBContext *mb = ctx->priv;
179  if(mb->morphamp)
180  return;
181  for(; *in_cidx < mb->cache_used; (*in_cidx)++){
182  Point *p= &mb->point_cache[*in_cidx];
183  int x;
184  if(p->p[1] > py)
185  break;
186  x= round((p->p[0] - mb->start_x) / scale + mb->w/2);
187  if(x<0 || x >= mb->w)
188  continue;
189  if(color) color[x] = p->val;
190  if(out_cidx && *out_cidx < mb->cache_allocated)
191  mb->next_cache[(*out_cidx)++]= *p;
192  }
193 }
194 
195 static int interpol(MBContext *mb, uint32_t *color, int x, int y, int linesize)
196 {
197  uint32_t a,b,c,d, i;
198  uint32_t ipol=0xFF000000;
199  int dist;
200 
201  if(!x || !y || x+1==mb->w || y+1==mb->h)
202  return 0;
203 
204  dist= FFMAX(FFABS(x-(mb->w>>1))*mb->h, FFABS(y-(mb->h>>1))*mb->w);
205 
206  if(dist<(mb->w*mb->h>>3))
207  return 0;
208 
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];
213 
214  if(a&&c){
215  b= color[(x-1) + (y+0)*linesize];
216  d= color[(x+0) + (y-1)*linesize];
217  }else if(b&&d){
218  a= color[(x+1) + (y-1)*linesize];
219  c= color[(x-1) + (y-1)*linesize];
220  }else if(c){
221  d= color[(x+0) + (y-1)*linesize];
222  a= color[(x-1) + (y+0)*linesize];
223  b= color[(x+1) + (y-1)*linesize];
224  }else if(d){
225  c= color[(x-1) + (y-1)*linesize];
226  a= color[(x-1) + (y+0)*linesize];
227  b= color[(x+1) + (y-1)*linesize];
228  }else
229  return 0;
230 
231  for(i=0; i<3; i++){
232  int s= 8*i;
233  uint8_t ac= a>>s;
234  uint8_t bc= b>>s;
235  uint8_t cc= c>>s;
236  uint8_t dc= d>>s;
237  int ipolab= (ac + bc);
238  int ipolcd= (cc + dc);
239  if(FFABS(ipolab - ipolcd) > 5)
240  return 0;
241  if(FFABS(ac-bc)+FFABS(cc-dc) > 20)
242  return 0;
243  ipol |= ((ipolab + ipolcd + 2)/4)<<s;
244  }
245  color[x + y*linesize]= ipol;
246  return 1;
247 }
248 
249 static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
250 {
251  MBContext *mb = ctx->priv;
252  int x,y,i, in_cidx=0, next_cidx=0, tmp_cidx;
253  double scale= mb->start_scale*pow(mb->end_scale/mb->start_scale, pts/mb->end_pts);
254  int use_zyklus=0;
255  fill_from_cache(ctx, NULL, &in_cidx, NULL, mb->start_y+scale*(-mb->h/2-0.5), scale);
256  tmp_cidx= in_cidx;
257  memset(color, 0, sizeof(*color)*mb->w);
258  for(y=0; y<mb->h; y++){
259  int y1= y+1;
260  const double ci=mb->start_y+scale*(y-mb->h/2);
261  fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci, scale);
262  if(y1<mb->h){
263  memset(color+linesize*y1, 0, sizeof(*color)*mb->w);
264  fill_from_cache(ctx, color+linesize*y1, &tmp_cidx, NULL, ci + 3*scale/2, scale);
265  }
266 
267  for(x=0; x<mb->w; x++){
268  float av_uninit(epsilon);
269  const double cr=mb->start_x+scale*(x-mb->w/2);
270  double zr=cr;
271  double zi=ci;
272  uint32_t c=0;
273  double dv= mb->dither / (double)(1LL<<32);
274  mb->dither= mb->dither*1664525+1013904223;
275 
276  if(color[x + y*linesize] & 0xFF000000)
277  continue;
278  if(!mb->morphamp){
279  if(interpol(mb, color, x, y, linesize)){
280  if(next_cidx < mb->cache_allocated){
281  mb->next_cache[next_cidx ].p[0]= cr;
282  mb->next_cache[next_cidx ].p[1]= ci;
283  mb->next_cache[next_cidx++].val = color[x + y*linesize];
284  }
285  continue;
286  }
287  }else{
288  zr += cos(pts * mb->morphxf) * mb->morphamp;
289  zi += sin(pts * mb->morphyf) * mb->morphamp;
290  }
291 
292  use_zyklus= (x==0 || mb->inner!=BLACK ||color[x-1 + y*linesize] == 0xFF000000);
293  if(use_zyklus)
294  epsilon= scale*1*sqrt(SQR(x-mb->w/2) + SQR(y-mb->h/2))/mb->w;
295 
296 #define Z_Z2_C(outr,outi,inr,ini)\
297  outr= inr*inr - ini*ini + cr;\
298  outi= 2*inr*ini + ci;
299 
300 #define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\
301  Z_Z2_C(outr,outi,inr,ini)\
302  if(use_zyklus){\
303  if(Z && fabs(mb->zyklus[i>>1][0]-outr)+fabs(mb->zyklus[i>>1][1]-outi) <= epsilon)\
304  break;\
305  }\
306  mb->zyklus[i][0]= outr;\
307  mb->zyklus[i][1]= outi;\
308 
309 
310 
311  for(i=0; i<mb->maxiter-8; i++){
312  double t;
313  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
314  i++;
315  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
316  i++;
317  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
318  i++;
319  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
320  i++;
321  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
322  i++;
323  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
324  i++;
325  Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0)
326  i++;
327  Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1)
328  if(zr*zr + zi*zi > mb->bailout){
329  i-= FFMIN(7, i);
330  for(; i<mb->maxiter; i++){
331  zr= mb->zyklus[i][0];
332  zi= mb->zyklus[i][1];
333  if(zr*zr + zi*zi > mb->bailout){
334  switch(mb->outer){
335  case ITERATION_COUNT:
336  zr = i;
337  c = lrintf((sin(zr)+1)*127) + lrintf((sin(zr/1.234)+1)*127)*256*256 + lrintf((sin(zr/100)+1)*127)*256;
338  break;
340  zr = i + log2(log(mb->bailout) / log(zr*zr + zi*zi));
341  c = lrintf((sin(zr)+1)*127) + lrintf((sin(zr/1.234)+1)*127)*256*256 + lrintf((sin(zr/100)+1)*127)*256;
342  break;
343  case WHITE:
344  c = 0xFFFFFF;
345  break;
346  case OUTZ:
347  zr /= mb->bailout;
348  zi /= mb->bailout;
349  c = (((int)(zr*128+128))&0xFF)*256 + (((int)(zi*128+128))&0xFF);
350  }
351  break;
352  }
353  }
354  break;
355  }
356  }
357  if(!c){
358  if(mb->inner==PERIOD){
359  int j;
360  for(j=i-1; j; j--)
361  if(SQR(mb->zyklus[j][0]-zr) + SQR(mb->zyklus[j][1]-zi) < epsilon*epsilon*10)
362  break;
363  if(j){
364  c= i-j;
365  c= ((c<<5)&0xE0) + ((c<<10)&0xE000) + ((c<<15)&0xE00000);
366  }
367  }else if(mb->inner==CONVTIME){
368  c= floor(i*255.0/mb->maxiter+dv)*0x010101;
369  } else if(mb->inner==MINCOL){
370  int j;
371  double closest=9999;
372  int closest_index=0;
373  for(j=i-1; j>=0; j--)
374  if(SQR(mb->zyklus[j][0]) + SQR(mb->zyklus[j][1]) < closest){
375  closest= SQR(mb->zyklus[j][0]) + SQR(mb->zyklus[j][1]);
376  closest_index= j;
377  }
378  closest = sqrt(closest);
379  c= lrintf((mb->zyklus[closest_index][0]/closest+1)*127+dv) + lrintf((mb->zyklus[closest_index][1]/closest+1)*127+dv)*256;
380  }
381  }
382  c |= 0xFF000000;
383  color[x + y*linesize]= c;
384  if(next_cidx < mb->cache_allocated){
385  mb->next_cache[next_cidx ].p[0]= cr;
386  mb->next_cache[next_cidx ].p[1]= ci;
387  mb->next_cache[next_cidx++].val = c;
388  }
389  }
390  fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci + scale/2, scale);
391  }
392  FFSWAP(void*, mb->next_cache, mb->point_cache);
393  mb->cache_used = next_cidx;
394  if(mb->cache_used == mb->cache_allocated)
395  av_log(ctx, AV_LOG_INFO, "Mandelbrot cache is too small!\n");
396 }
397 
398 static int request_frame(AVFilterLink *link)
399 {
400  MBContext *mb = link->src->priv;
401  AVFrame *picref = ff_get_video_buffer(link, mb->w, mb->h);
402  if (!picref)
403  return AVERROR(ENOMEM);
404 
405  picref->sample_aspect_ratio = (AVRational) {1, 1};
406  picref->pts = mb->pts++;
407 
408  draw_mandelbrot(link->src, (uint32_t*)picref->data[0], picref->linesize[0]/4, picref->pts);
409  return ff_filter_frame(link, picref);
410 }
411 
412 static const AVFilterPad mandelbrot_outputs[] = {
413  {
414  .name = "default",
415  .type = AVMEDIA_TYPE_VIDEO,
416  .request_frame = request_frame,
417  .config_props = config_props,
418  },
419  { NULL }
420 };
421 
423  .name = "mandelbrot",
424  .description = NULL_IF_CONFIG_SMALL("Render a Mandelbrot fractal."),
425  .priv_size = sizeof(MBContext),
426  .priv_class = &mandelbrot_class,
427  .init = init,
428  .uninit = uninit,
430  .inputs = NULL,
431  .outputs = mandelbrot_outputs,
432 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
static int query_formats(AVFilterContext *ctx)
AVFilter ff_vsrc_mandelbrot
static av_cold int init(AVFilterContext *ctx)
double p[2]
uint64_t pts
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
double start_y
const char * b
Definition: vf_curves.c:109
static int interpol(MBContext *mb, uint32_t *color, int x, int y, int linesize)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
static const AVOption mandelbrot_options[]
static av_cold void uninit(AVFilterContext *ctx)
#define FLAGS
#define log2(x)
Definition: libm.h:122
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
double(* zyklus)[2]
const char * name
Pad name.
Definition: internal.h:69
double morphamp
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
uint8_t
static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts)
#define av_cold
Definition: attributes.h:74
#define mb
AVOptions.
Inner
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
double end_pts
#define lrintf(x)
Definition: libm_mips.h:70
static const AVFilterPad mandelbrot_outputs[]
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:63
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:542
#define OFFSET(x)
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
double morphyf
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define Z_Z2_C_ZYKLUS(outr, outi, inr, ini, Z)
static av_always_inline av_const double round(double x)
Definition: libm.h:162
#define FFMAX(a, b)
Definition: common.h:79
Outer
Point * point_cache
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:241
#define FFMIN(a, b)
Definition: common.h:81
float y
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:68
double morphxf
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)
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:359
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
double start_scale
double end_scale
double start_x
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:252
#define SQR(a)
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
rational number numerator/denominator
Definition: rational.h:43
offset must point to AVRational
Definition: opt.h:235
const char * name
Filter name.
Definition: avfilter.h:474
double bailout
offset must point to two consecutive integers
Definition: opt.h:232
misc parsing utilities
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
static int64_t pts
Global timestamp for the audio frames.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:133
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
AVRational frame_rate
Point * next_cache
static double c[64]
uint32_t val
AVFILTER_DEFINE_CLASS(mandelbrot)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:633
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){if(!*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));if(!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=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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%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 av_uninit(x)
Definition: attributes.h:141
static int ipol(uint8_t *src, int x, int y)
Definition: rotozoom.c:65
#define av_freep(p)
#define av_malloc_array(a, b)
#define FFSWAP(type, a, b)
Definition: common.h:84
internal API functions
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:98
uint32_t dither
static int config_props(AVFilterLink *inlink)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int cache_allocated