Author Topic: GlowLines!  (Read 3469 times)

0 Members and 1 Guest are viewing this topic.

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
GlowLines!
« 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


« Last Edit: February 01, 2008 by relsoft »
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: GlowLines!
« Reply #1 on: February 01, 2008 »
any exe version available?
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: GlowLines!
« Reply #2 on: February 01, 2008 »
There. Attachment. :*)|
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: GlowLines!
« Reply #3 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:
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: GlowLines!
« Reply #4 on: February 01, 2008 »
great. I really do like this fx, too. Somehow reminds
me on the eighties !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: GlowLines!
« Reply #5 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
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: GlowLines!
« Reply #6 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!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: GlowLines!
« Reply #7 on: February 02, 2008 »
Actually, I was here all along. I just wan't coding at that time. LOL
Challenge Trophies Won: