32bits blur

Started by Grew, January 28, 2011, 12:52:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Grew

I juste wanted to share this little code which make a blur effect with 32bits graph mode. (With alpha)

function int blur32bits(int file, int graph, int dist)
private
map;
px,py;
dx,dy;
r,g,b,a;
nbDist;
finalA,finalR,finalG,finalB;

begin

if(dist == 0)
return map_clone(file, graph);
end

dx = graphic_info(file, graph, G_WIDTH);
dy = graphic_info(file, graph, G_HEIGHT);
map = map_new(dx, dy, 32);

for(y = 0; y < dy; y++)
for(x = 0; x < dx; x++)
finalR = finalG = finalB = finalA = 0;
nbDist = 0;
for(py = y-dist/2; py < y+dist/2; py++)
for(px = x-dist/2; px < x+dist/2; px++)
if(px =>0 and py=>0 and px<dx and py<dy)
get_rgba(map_get_pixel(file, graph, px, py), &r, &g, &b, &a);
finalR+=r;
finalG+=g;
finalB+=b;
finalA+=a;
nbDist++;
end
end
end
if(nbDist > 0)
map_put_pixel(0 ,map , x, y, rgba(finalR/nbDist, finalG/nbDist ,finalB/nbDist ,finalA/nbDist)) ;
end

end
end

return map;

end


Exemple of how to use:

graph=blur32bits(file FPG, origine graph, blur intensity);

It can be improved.

Info: this is a uniform blur (not gauss).
My game developer instagram :
https://www.instagram.com/ben_dev_game/

SplinterGU

what difference have with bennugd blur?
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

handsource-dyko

One suggestion, could you perhaps add some comments in the code explaining what each line/block of code does.
That makes it a bit easier to understand. 

Grew

Quote from: SplinterGUwhat difference have with bennugd blur?

The Bennu blur fonction don't support 32bits mode:

Quote from: WikiBennuOnly 16bit graphics are supported on 16bit video mode.
http://wiki.bennugd.org/index.php?title=Blur

After tries, there is no alpha whith the bennu blur fonction.
My game developer instagram :
https://www.instagram.com/ben_dev_game/

SplinterGU

Quote from: Grew on January 29, 2011, 11:37:19 AM
Quote from: SplinterGUwhat difference have with bennugd blur?

The Bennu blur fonction don't support 32bits mode:

Quote from: WikiBennuOnly 16bit graphics are supported on 16bit video mode.
http://wiki.bennugd.org/index.php?title=Blur

After tries, there is no alpha whith the bennu blur fonction.

it's must be work with 32bits...

yes, not alpha, but it can be fixed easy.

anyway, thanks for it.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2