Trouble with GrayScale Filter

BlitzPlus Forums/BlitzPlus Programming/Trouble with GrayScale Filter

OK, here is the corrected function, including a fader loop as an example:

Graphics 640,480,16,2
img%=LoadImage("x:\monkey6.jpg")
SetBuffer BackBuffer()
DrawImage img%,0,0
For t=0 To 100 Step 10
   DrawImage img%,0,0
   monochrome (t)
   Flip
Next 
Delay 2000
For t=100 To 0 Step -10
   DrawImage img%,0,0
   monochrome (t)
   Flip
Next 
WaitKey()
End

Function Monochrome(perct#)
   SetBuffer BackBuffer()
   LockBuffer
   For y=0 To 479 
      For x=0 To 639
         temp1=ReadPixel(x,y)
         orgb=(temp1 And $FF)
         orgg=(temp1 And $FF00) Shr 8
         orgr=(temp1 And $FF0000) Shr 16
         desb=((orgr*0.299)+(orgg*0.587)+(orgb*0.114)) 
         desr=orgr*(1-(perct#/100))+desb*(perct#/100) 
         desg=orgg*(1-(perct#/100))+desb*(perct#/100) 
         desb=orgb*(1-(perct#/100))+desb*(perct#/100) 
         WritePixel x,y,desb+(desg Shl 8)+(desr Shl 16)
      Next 
   Next 
   UnlockBuffer
End Function


Unfortunately it isn't quite fast enough to look great as a fade, I think the effect is better to switch from full color to B&W in a single step rather than using the fade example listed above -- but it does illustrate how the function works.

Does anyone here happen to have a *fast* cross-fader?
Generating a pure B&W image and doing a *crossfade* would have the exact same effect after all... But probably much smoother, if the crossfader is fast enough.