Everybody's heard about the blurred
#5
Nice Function, Terry.  The _MEM stuff sure makes a speed increase.  I think I will try to incorporate _MEM in mine to see how much faster it can get.  Well, here's what I came up with after studying sources in other languages.  This one let's you define the radius, higher values make it slower. 

- Dav

Code: (Select All)

Screen _NewImage(800, 600, 32)

For t = 1 To 1000
    size = Rnd * 255
    x = Rnd * _Width: y = Rnd * _Height
    Line (x, y)-(x + size, y + size), _RGB(Rnd * 255, Rnd * 255, Rnd * 255), BF
Next
For t = 1 To 50000
    PSet (Rnd * _Width, Rnd * _Height), _RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Next

GaussianBlur 8, 100, 100, _Width - 100, _Height - 100

Sub GaussianBlur (radius, startx, starty, endx, endy)

    tempimage& = _CopyImage(_Display)
    origsource& = _Source
    origdest& = _Dest

    Dim pix As Long
    sigma = radius / 2
    cons = 1 / (2 * 3.14159 * sigma * sigma)

    _Source tempimage&

    'apply Gaussian Blur

    For y = starty To endy
        For x = startx To endx
            r = 0: g = 0: b = 0
            For i = -radius To radius
                For j = -radius To radius
                    If (y + j >= 0) And (x + i >= 0) And (y + j < _Height) And (x + i < _Width) Then
                        pix = Point(x + j, y + i)
                        k = cons * Exp(-((j * j + i * i) / (2 * sigma * sigma)))
                        r = r + k * _Red32(pix)
                        g = g + k * _Green32(pix)
                        b = b + k * _Blue32(pix)
                    End If
                Next
            Next
            PSet (x, y), _RGB32(r, g, b)
        Next
    Next

    _FreeImage tempimage&
    _Source origsource&
    _Dest origdest&

End Sub

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Everybody's heard about the blurred - by OldMoses - 07-26-2023, 01:32 AM
RE: Everybody's heard about the blurred - by Dav - 07-26-2023, 03:47 AM
RE: Everybody's heard about the blurred - by Dav - 07-26-2023, 06:24 PM
RE: Everybody's heard about the blurred - by Dav - 07-27-2023, 11:07 PM
RE: Everybody's heard about the blurred - by Dav - 07-28-2023, 10:19 PM



Users browsing this thread: 1 Guest(s)