Bennu Game Development

English Forums => Suggestions => Topic started by: Grew on January 28, 2011, 12:52:25 PM

Title: 32bits blur
Post by: Grew on January 28, 2011, 12:52:25 PM
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).
Title: Re: 32bits blur
Post by: SplinterGU on January 28, 2011, 11:30:58 PM
what difference have with bennugd blur?
Title: Re: 32bits blur
Post by: handsource-dyko on January 29, 2011, 10:37:16 AM
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. 
Title: Re: 32bits blur
Post by: 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.
Title: Re: 32bits blur
Post by: SplinterGU on January 29, 2011, 01:50:22 PM
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.