# Blur Efect

Hi all, can somebody tell me how can i do a simple blur efect in a 2D
SDL_Surface?

thanks a lot !!–
±-----------------------------±-----------------------+
| Ricardo Markiewicz | El software es como el |
±-----------------------------+ sexo… Si es gratis |
| Linux Inside! - S.u.S.E. 6.4 | Mejor !!! |
±-----------------------------±-----------------------+

The simplest “blur” effect consists of taking the average of all nine
surrounding pixels (plus itself) of each pixel. In true-color, you probably
average out the R, G and B components seperately.

pseudo-code:

for y = 1 to height - 2
for x = 1 to width - 2
destSurface[y][x] = (surface[y-1][x-1] + … + surface[y][x] + … +
surface[y+1][x+1]) / 10
next
next

Of course, you can optimize by only taking the pixel above, below, to the
left and to the right (total of four pixels) and dividing by four (or
shifting right by 2, even faster) but it may not look as smooth. (depends if
you want an algorithm for quality or speed)

## Oh, and the pseudo-code assumed you could average the pixels as whole entities (which is the case in 8-bit grayscale), so you’ll probably have to do the calculation for every primary… I haven’t done much SDL code yet, (does it show?) sorry if I explained everything incorrectly.–

Olivier A. Dagenais - Software Architect and Developer

Hi all, can somebody tell me how can i do a simple blur efect in a 2D
SDL_Surface?

thanks a lot !!

±-----------------------------±-----------------------+
| Ricardo Markiewicz | El software es como el |
±-----------------------------+ sexo… Si es gratis |
| Linux Inside! - S.u.S.E. 6.4 | Mejor !!! |
±-----------------------------±-----------------------+

Hi all, can somebody tell me how can i do a simple blur efect in a 2D
SDL_Surface?

that’s two questions: how to blur, and how to do it on a SDL_Surface.
For the second question, learn and understand how pixels are stored in
surfaces - I won’t explain it here, there is plenty of code for you to
study.

For blurring a 2d image, there are heaps of literature around. Gamasutra
had a brief recent article about it (url below), and there is a lot of
info both on the net and (better) in books. Understanding 2d convolutions
is always a good start - real game programmers aren’t afraid of maths

## Cool, thanks for the resource! (it’s written by Alex Evans aka Statix!)–

Olivier A. Dagenais - Software Architect and Developer

“Mattias Engdeg?rd” wrote in message

Hi all, can somebody tell me how can i do a simple blur efect in a 2D
SDL_Surface?

that’s two questions: how to blur, and how to do it on a SDL_Surface.
For the second question, learn and understand how pixels are stored in
surfaces - I won’t explain it here, there is plenty of code for you to
study.

For blurring a 2d image, there are heaps of literature around. Gamasutra
had a brief recent article about it (url below), and there is a lot of
info both on the net and (better) in books. Understanding 2d convolutions
is always a good start - real game programmers aren’t afraid of maths

http://www.gamasutra.com/features/20010209/evans_01.htm