[FFmpeg-cvslog] avfilter/vsrc_mandelbrot: avoid sqrt for epsilon calculation

Ganesh Ajjanagadde git at videolan.org
Wed Nov 25 02:37:25 CET 2015


ffmpeg | branch: master | Ganesh Ajjanagadde <gajjanagadde at gmail.com> | Sun Nov 22 11:49:15 2015 -0500| [e9c7493f19a610f44690ef2f2f3737a3c6236fdf] | committer: Ganesh Ajjanagadde

avfilter/vsrc_mandelbrot: avoid sqrt for epsilon calculation

This rewrites into a similar expression avoiding sqrt. Similarity is
assured since sqrt(x^2 + y^2)/(x+y) lies in [1/sqrt(2), 1] for x, y > 0.

Tested on x86-64, Haswell, GNU/Linux.
Command:
ffmpeg -f lavfi -i mandelbrot -f null -

old (draw_mandelbrot):
277625266 decicycles in draw_mandelbrot,     256 runs,      0 skips
304527322 decicycles in draw_mandelbrot,     512 runs,      0 skips
377593582 decicycles in draw_mandelbrot,    1024 runs,      0 skips
338539499 decicycles in draw_mandelbrot,    2048 runs,      0 skips
583630357 decicycles in draw_mandelbrot,    4096 runs,      0 skips

new (draw_mandelbrot):
274635709 decicycles in draw_mandelbrot,     256 runs,      0 skips
300287046 decicycles in draw_mandelbrot,     512 runs,      0 skips
371819935 decicycles in draw_mandelbrot,    1024 runs,      0 skips
336663765 decicycles in draw_mandelbrot,    2048 runs,      0 skips
581851016 decicycles in draw_mandelbrot,    4096 runs,      0 skips

Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e9c7493f19a610f44690ef2f2f3737a3c6236fdf
---

 libavfilter/vsrc_mandelbrot.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vsrc_mandelbrot.c b/libavfilter/vsrc_mandelbrot.c
index c79ea2e..91bf63f 100644
--- a/libavfilter/vsrc_mandelbrot.c
+++ b/libavfilter/vsrc_mandelbrot.c
@@ -291,7 +291,7 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize,
 
             use_zyklus= (x==0 || s->inner!=BLACK ||color[x-1 + y*linesize] == 0xFF000000);
             if(use_zyklus)
-                epsilon= scale*1*sqrt(SQR(x-s->w/2) + SQR(y-s->h/2))/s->w;
+                epsilon= scale*(abs(x-s->w/2) + abs(y-s->h/2))/s->w;
 
 #define Z_Z2_C(outr,outi,inr,ini)\
             outr= inr*inr - ini*ini + cr;\



More information about the ffmpeg-cvslog mailing list