Code updated for 5.20+, including all filters posted here before 2013
I just thought I start a group topic where individuals can post useful CustomFilters() that they've come up with. It seemed like a good way to do it instead of having many different threads. Take your pick.
Postings would need a short description and the myCallback() procedure that would be used with CustomFilterCallback(@myCallback()).
;Transfer the Alpha layer into the visible layer.
Procedure MakeAlphaVisibleFilterCallback(x, y, SourceColor, TargetColor)
ProcedureReturn RGBA(Alpha(SourceColor), Alpha(SourceColor),Alpha(SourceColor),00)
EndProcedure
@Edit: updated thread title to [v4.40b5]
Last edited by Demivec on Mon Oct 26, 2009 8:14 pm, edited 1 time in total.
I think this thread is a great idea and will in future contribute any filters that I make to it.
However, for the sake of consistency I've added my Photoshop modes to the original thread. They are updated to work as Custom Filter callbacks.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Procedure SetBlurRadius(radius)
Global BlurRadius=radius
Global BlurFactor.f=1 / ((radius * 2 + 1) * (radius * 2 + 1))
Global Dim BlurLayer.l(OutputWidth() - 1, OutputHeight() - 1)
EndProcedure
Procedure BlurFilter(x, y, SourceColor, TargetColor)
Global BlurRadius
Global BlurFactor.f
Shared BlurLayer()
Protected.w r, g, b
For yn=y - BlurRadius To y + BlurRadius
For xn=x - BlurRadius To x + BlurRadius
If xn<0 Or xn>=OutputWidth() Or yn<0 Or yn>=OutputHeight() ;Or (xn=x And yn=y)
Continue
EndIf
If Not BlurLayer(xn, yn)
BlurLayer(xn, yn)=Point(xn, yn)
EndIf
cn=BlurLayer(xn, yn)
;d=Sqr((xn-x)*(xn-x)+(yn-y)*(yn-y))
;k.f=BlurFactor;Cos((d/(1+BlurRadius))*0.5*#PI)
ak.f=Alpha(cn) / 255
r + Red(cn) * BlurFactor * ak
g + Green(cn) * BlurFactor * ak
b + Blue(cn) * BlurFactor * ak
Next
Next
res=RGBA(r, g, b, Alpha(TargetColor))
ProcedureReturn res
EndProcedure
; SetBlurRadius(2) ; blur level = 1(normal) 2 (slow) 3 (very slow)
Eddy, any chance of you coding an antialias filter?!
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."