07-17-2023, 02:12 AM
Ok, thanks to the replies I received I realized a bloom is what I need, more specifically Gaussian blurring. Instead of recreating code for Gaussian blurs I've been using @RhoSigma 's excellent Image Processing Library which includes a few methods for Gaussian blurring. His blurring routines also preserve the alpha channel which is a HUGE plus! The code below is a proof of concept I came up with. You'll need the image and library .BM file below to execute the code.
Code: (Select All)
' Bloom test 1
' Uses RhoSigma's Image Processing Library (imageprocess.bm)
DIM TestImage AS LONG
DIM NoAlphaImage AS LONG
DIM AlphaImage AS LONG
DIM FirstPass AS LONG
DIM SecondPass AS LONG
DIM Alpha AS INTEGER
DIM Red AS INTEGER
DIM Green AS INTEGER
DIM Blue AS INTEGER
DIM x AS INTEGER
DIM y AS INTEGER
DIM i AS INTEGER
TestImage = _LOADIMAGE("test.png", 32) ' 27 x 53 original image
AlphaImage = _NEWIMAGE(_WIDTH(TestImage), _HEIGHT(TestImage), 32) ' empty image same size as original
RANDOMIZE TIMER
SCREEN _NEWIMAGE(640, 480, 32)
'+-----------------------------------+
'| Create quick and dirty background |
'+-----------------------------------+
FOR i = 1 TO 200
LINE (RND * 640, RND * 480)-(RND * 640, RND * 480), _RGB32(RND * 256, RND * 256, RND * 256)
NEXT i
'+-------------------------------------------------------------------------+
'| Copy TestImage to AlphaImage at the same time applying the alpha levels |
'+-------------------------------------------------------------------------+
_DEST AlphaImage
_SOURCE TestImage
FOR y = 0 TO _HEIGHT(TestImage) - 1
'+------------------------------------------+
'| Draw center vertical strip with no alpha |
'+------------------------------------------+
Alpha = 255
Red = _RED(POINT(13, y))
Green = _GREEN(POINT(13, y))
Blue = _BLUE(POINT(13, y))
IF Red OR Green OR Blue THEN ' don't copy pixel if value is (0,0,0)
PSET (13, y), _RGB32(Red, Green, Blue, Alpha)
END IF
FOR x = 12 TO 0 STEP -1
'+------------------------------------------------------------------------+
'| Draw vertical strips to right and left of center with decreasing alpha |
'+------------------------------------------------------------------------+
Alpha = Alpha - 10
Red = _RED(POINT(x, y))
Green = _GREEN(POINT(x, y))
Blue = _BLUE(POINT(x, y))
IF Red OR Green OR Blue THEN ' don't copy pixel if value is (0,0,0)
PSET (x, y), _RGB32(Red, Green, Blue, Alpha)
PSET (26 - x, y), _RGB32(Red, Green, Blue, Alpha)
END IF
NEXT x
NEXT y
_DEST 0
_SOURCE 0
NoAlphaImage = ApplyFilter&(TestImage, "gauss8", 0, 0, -1, -1, -1, -1, -1)
FirstPass = ApplyFilter&(AlphaImage, "gauss8", 0, 0, -1, -1, -1, -1, -1)
SecondPass = ApplyFilter&(FirstPass, "gauss8", 0, 0, -1, -1, -1, -1, -1)
_PUTIMAGE (100, 100), TestImage ' original untouched image
_PUTIMAGE (125, 100), NoAlphaImage ' TestImage blurred once with no alpha applied
_PUTIMAGE (150, 100), AlphaImage ' TestImage with alpha applied (no blurring)
_PUTIMAGE (175, 100), FirstPass ' AlphaImage blurred once
_PUTIMAGE (200, 100), SecondPass ' AlphaImage blurred a second time
'$INCLUDE:'imageprocess.bm'