Stackblur – C++ multi-threaded version of fast blur algorithm

I found nice algorithm for blurring images – Stackblur by Mario Klingemann. It could do the job relatively fast and gives decent quality. You can check it here – web demonstration. As you can see it can be usable even in web projects.

stackblursample

As i wanted to include it to my cross-platform engine i found two c++ implementations: 

First is SSE friendly, second contains some division optimization via static tables. However, both are not using all cpu cores. I took second one as foundation for my implementation, as i expected my code to work on mobile devices with no SSE support. Single-core processing of 1920×1200 rgba image with 100 px radius took only 219 ms (Intel Q9550, Windows 7).

I improved stackblur code to multi-threaded version – on my quad-core cpu speed results as expected showed 4x improvement – 63ms for the same task. You can download the part my lib below and use it as a foundation to your needs.

Download multi-threaded 32bit-color (RGBA) version of StackBlur:  stackblur.cpp

I believe algorithm can be optimized even further – any suggestions are welcome.

  • Elam

    Hi! I’m doing it on Android, our demands has some differents. First, I must get a shot of screen, and then blur it, then show it immediately. I am write it with C program, and build with NDK. But I got some trouble, I must done with it lower than 200ms, but I did’t found a way to do it. So, can you give me some help or suggest? Thank you very much! Sorry for my english.

    • Do you have trouble to perform blur fast enough or to get/show image? Blur part speed should depend on device resolution in your case. May be its even good idea to use every second pixel in case of full hd device resolution. For normal case algorithm described here should work under 200ms – how fast are your results? May be slow part is on java side when you provide image data to blur.

  • Royi

    Hi,
    Is there a MATLAB implementation?
    Or maybe Pseudo Code / C Cdoe with no optimization just to understand the method?

    Thank You.

  • Dr-Emann

    I can’t seem to find MVThread. I’ve tried searching your blog, as well as the internet, but can’t seem to find it.

    • This is just simple thread class – contains virtual void run() function to do some job asynchronously. Has start(); and wait(); methods – one runs thread task and another waits until its finished. So you can use any thread implementation here (c++11 std::thread, boost::thread from boost lib, etc).