07-26-2023, 01:32 AM
Doing some reading up on gaussian blur this evening. Here's my go at the algorithm as I understand it.
Code: (Select All)
'OldMoses' first attempt at Gaussian Blur algorithm
SCREEN _NEWIMAGE(1024, 512, 32)
b& = _LOADIMAGE("bird sample.jpg", 32)
r& = _NEWIMAGE(_WIDTH(b&), _HEIGHT(b&), 32)
'seeding matrix (7:1) x (1:7)
DIM a%(-3 TO 3)
a%(-3) = 1: a%(-2) = 2: a%(-1) = 4: a%(0) = 8: a%(1) = 4: a%(2) = 2: a%(3) = 1
'alpha multiplier matrix kernel (7:7)
DIM kern%(LBOUND(a%) TO UBOUND(a%), LBOUND(a%) TO UBOUND(a%))
FOR x% = LBOUND(kern%, 1) TO UBOUND(kern%, 1) ' iterate kernel matrix columns
FOR y% = LBOUND(kern%, 2) TO UBOUND(kern%, 2) ' iterate kernel matrix rows
kern%(x%, y%) = a%(x%) * a%(y%) ' seed the gaussian kernel position
NEXT y%, x%
mult! = 255 / kern%(0, 0) ' set a multiplier to prevent alpha bleed through
'display clear image, create and display blurred image
_PUTIMAGE (1, 1), b& ' place clear bird image on left of mainscreen
FOR ox% = 0 TO _WIDTH(b&) - 1 '
FOR oy% = 0 TO _HEIGHT(b&) - 1 '
_SOURCE b& ' source: clear bird image
c~& = POINT(ox%, oy%) ' get source pixel color at (ox%, oy%)
_DEST r& ' destination: blurred receiving image
FOR x% = LBOUND(kern%, 1) TO UBOUND(kern%, 1) ' apply the alpha matrix around original point
FOR y% = LBOUND(kern%, 2) TO UBOUND(kern%, 2)
PSET (ox% + x%, oy% + y%), _RGBA32(_RED32(c~&), _GREEN32(c~&), _BLUE32(c~&), mult! * kern%(x%, y%))
NEXT y%, x%
NEXT oy%, ox%
_DEST 0 ' destination back to mainscreen
_PUTIMAGE (_WIDTH(0) - _WIDTH(r&) - 2, 1), r& ' place blurred receiving image on right of mainscreen
END
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: