Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: relsoft on February 01, 2008

Title: GlowLines!
Post by: relsoft on February 01, 2008
Code: [Select]
''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


Title: Re: GlowLines!
Post by: va!n on February 01, 2008
any exe version available?
Title: Re: GlowLines!
Post by: relsoft on February 01, 2008
There. Attachment. :*)|
Title: Re: GlowLines!
Post by: va!n on February 01, 2008
@relsoft:
thanks for adding the exe version. the blurring routine is amazing fast! *just great*
K++ for sharing the source  :goodpost:
Title: Re: GlowLines!
Post by: benny! on February 01, 2008
great. I really do like this fx, too. Somehow reminds
me on the eighties !!!
Title: Re: GlowLines!
Post by: Paul on February 01, 2008
cool, but if you want to make it a little faster, you could have both red and blue in one variable. A bit like this: http://dbfinteractive.com/index.php?topic=2287.0
Title: Re: GlowLines!
Post by: Shockwave on February 01, 2008
Another nice code snippet from Relsoft :)

I am so glad that you can post here again, we missed all these little gems when you weren't around!
Title: Re: GlowLines!
Post by: relsoft on February 02, 2008
Actually, I was here all along. I just wan't coding at that time. LOL