P i
P i

Reputation: 30704

iOS: Optimised algorithm for blurring bitmap

Following from this question, iOS / GLES2: How to achieve Glow Effect, I'm investigating making my own blurring routine.

Maybe something along the lines of:

blur8bitGreyscaleBitmap(int resX, int resY, int passes, char* src, char* dest)
{
    ...
}

And then filling it in with something that takes each pixel in turn, diffusing it into its neighbours, would create a subtle blur. and iterating this process several times would let the blur diffuse outwards.

Is there a better method than this?

also, this looks like just the sort of task that could be made to run 20x faster with good ( maybe NEON ) optimisation.

I am looking for alternate techniques, code, links.

Upvotes: 3

Views: 1448

Answers (1)

P i
P i

Reputation: 30704

After doing a bit of research, I discovered the following,

  • it is okay to blur horizontal, then vertical. this means if you are blurring five pixels left right up down into your target pixel, that is 11+11 operations instead of 11*11

  • most basic is box blur, simply averaging all of the pixels in the box. this would be the choice for real-time blur on mobile devices. this can be optimised heavily eg if the first pixel requires A+B+C+D+E, then for the next one we can simply -A then +F. ie we don't have to do all of those additions twice.

  • http://en.wikipedia.org/wiki/Gaussian_blur gives better results

  • the common technique is to do the work on the graphics chip, using GLES2 shaders eg http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/

    I'm kind of curious whether a similar level of optimisation could be reached using accelerate framework.

    I'm still curious whether there is any existing NEON code to do this, my guess is even this would not improve upon doing the work on the graphics chip, so no one has bothered.

Upvotes: 4

Related Questions