Fast Colour Blend

BlitzPlus Forums/BlitzPlus Programming/Fast Colour Blend

Grey Alien(Posted 2005) [#1]
I have made this function to work out a blend between 2 colours when passed a starting colour, ending colour and a ratio between 0 and 1 (for fading in a loop):

Function ccBlendColours%(st%, en%, ratio#)
	;ratio# must be 0 to 1
	Rst = (st Shr 16) And 255 
	Gst = (st Shr 8 ) And 255
	Bst = st And 255		

	Ren = (en Shr 16) And 255 
	Gen = (en Shr 8 ) And 255
	Ben = en And 255		
			
	Rdiff=  Rst-Ren
	Gdiff=  Gst-Gen
	Bdiff=  Bst-Ben

	Rdiff = Rdiff * ratio#
	Gdiff = Gdiff * ratio#
	Bdiff = Bdiff * ratio#
			
	Return (((Rst-Rdiff) Shl 16) Or ((Gst-Gdiff) Shl 8) Or (Bst-Bdiff))				
End Function


I know I can speed it up by not using Rst and Ren and Rdiff etc and putting it all on one line, but I wanted to show the working for others to comment on. Basically can this be speeded up or made better? Any ideas?

btw I am already reading in my source image with ReadPixelFast into an array which I then manipulate and write back with WritePixelFast, so no major improvements there unless I use a 3rd party dll.


Thanks in advance