Function Filter:Int(a:Int, b:Int, f:String = "Average")

	Local c:Int

	Select f

		Case "Add"			Return Min(255,(a+b))
		Case "Subtract"		If (a+b)<255 Then Return 0 Else Return (a+b)-255
		Case "Average"		Return (a+b) Shr 1
		Case "Multiply"		Return (a*b) Shr 8
		Case "Overlay"		If a<128 Then Return (a*b) Shr 7 Else Return 255-((255-a)*(255-b) Shr 7)
		Case "Exclusion"		Return a+b-(a*b Shr 7)
		Case "Negation"		Return 255-Abs(255-a-b)
		Case "Difference"		Return Abs(a-b)
		Case "Darken"		If a<b Then Return a Else Return b
		Case "Lighten"		If a>b Then Return a Else Return b
		Case "Screen"		Return 255-((255-a)*(255-b) Shr 8)
		Case "Hardlight"		If b<128  Then Return (a*b) Shr 7 Else Return 255-((255-b)*(255-a) Shr 7)
		Case "Lineardodge"	Return Min(a+b,255)
		Case "Linearburn"		Return (a+b)-192	
		Case "Phoenix"		Return Min(a,b)-Max(a,b)+255

		Case "Hardmix"		If Filter(a,b,"VividLight")<128 Then Return 0 Else Return 255
		Case "Vividlight"		If a<128 Then Return Filter(b,(2*a),"Colorburn") Else Return Filter(b,(2*(a-128)),"Colordodge")
		Case "Pinlight"		If a<128 Then Return Filter(b,(2*a),"Darken") Else Return Filter(b,(2*(a-128)),"Lighten")
		Case "Linearlight"	If a<128 Then Return Filter(b,(2*a),"Linearburn") Else Return Filter(b,(2*(a-128)),"Lineardodge")

		Case "Softlight1"		c=a*b Shr 8
						Return (c+a*(255-((255-a)*(255-b) Shr 8)-c) Shr 8)

		Case "Softlight2"		c=a*b Shr 8
						Return c+a*(255-((255-a)*(255-b) Shr 8)-c) Shr 8

		Case "Colordodge"		If b=255 Then
							Return 255
						Else
							c=Floor((a Shl 8)/(255-b))
							If c>255 Then Return 255 Else Return c
						EndIf

		Case "Colorburn"		If b=0 Then c=0 Else c=255-(((255-a) Shl 8)/b)
						If c<0 Then Return 0 Else Return c

		Case "Glow"			If a = 255 Then
							c=255
						Else
							c=b*b/(255-a)
							If c>255 Then Return 255
						EndIf

	
	Return c

	End Select

End Function