''Realtime Glow
''Relsoft (http://rel.betterwebber.com)
''Jan 31, 2008
''Fast Blur code by Jim Scott (blackpawm.com)
#include "fbgfx.bi"
declare sub blur_h(byval source as uinteger ptr, byval dest as uinteger ptr,_
byval wid as integer, byval hei as integer, byval radius as uinteger)
declare sub blur_v(byval source as uinteger ptr, byval dest as uinteger ptr,_
byval wid as integer, byval hei as integer, byval radius as uinteger)
const SCR_W = 640
const SCR_H = 480
screenres SCR_W,SCR_H,32,
dim as FB.Image ptr image = imagecreate(SCR_W,SCR_H)
var image_ptr = cast(uinteger ptr, image+1)
dim as FB.Image ptr image2 = imagecreate(SCR_W,SCR_H)
var image_ptr2 = cast(uinteger ptr, image2+1)
randomize timer
cls
get(0,0)-(SCR_W-1,SCR_H-1), image2
dim as integer x, y, i, j
for i = 0 to 100
line(rnd*SCR_W, rnd*SCR_H)-(rnd*SCR_W, rnd*SCR_H), rgb(rnd*255,rnd*255,rnd*255)
next i
get(0,0)-(SCR_W-1,SCR_H-1), image
blur_h(image_ptr,image_ptr2,SCR_W, SCR_H, 2)
blur_v(image_ptr2,image_ptr,SCR_W, SCR_H, 2)
Print "Press any key to glow..."
sleep
put(0,0), image,add
put(0,0), image,add
sleep
sub blur_h(byval source as uinteger ptr, byval dest as uinteger ptr,_
byval wid as integer, byval hei as integer, byval radius as uinteger)
dim as uinteger x, y, pixel
dim as uinteger r, g, b, a
dim as uinteger divisor
dim as integer kx
divisor = (radius * 2 + 1)
for y = 0 to hei -1
for x = 0 to wid - 1
r = 0
g = 0
b = 0
a = source[y * wid + x] shr 24
for kx = -radius to radius
pixel = source[y * wid + x + kx]
r += (pixel shr 16 )
g += (pixel shr 8) and 255
b += (pixel and 255)
next kx
r \=divisor
g \=divisor
b \=divisor
dest[y * wid+x] = a shl 24 or r shl 16 or g shl 8 or b
next x
next y
end sub
sub blur_v(byval source as uinteger ptr, byval dest as uinteger ptr,_
byval wid as integer, byval hei as integer, byval radius as uinteger)
dim as uinteger x, y, pixel
dim as uinteger r, g, b, a
dim as uinteger divisor
dim as integer ky
divisor = (radius * 2 + 1)
for x = 0 to wid - 1
for y = radius to (hei - 1) - radius
r = 0
g = 0
b = 0
a = source[y * wid + x] shr 24
for ky = -radius to radius
pixel = source[x + (y + ky)*wid]
r += (pixel shr 16 )
g += (pixel shr 8) and 255
b += (pixel and 255)
next ky
r \=divisor
g \=divisor
b \=divisor
dest[x + y*wid] = a shl 24 or r shl 16 or g shl 8 or b
next y
next x
end sub