Trouble with GrayScale Filter

BlitzPlus Forums/BlitzPlus Programming/Trouble with GrayScale Filter

Guess I should post the code too.

Graphics 1024, 768

XOffset = 20
YOffset = 20

ImageFile$ = "C:\Blitz Work\Small Picture 009.jpg"
SetBuffer BackBuffer()

Image = LoadImage(ImageFile)
DrawBlock Image,XOffset,YOffset
LockBuffer BackBuffer()
For XIndex = 1 To ImageWidth(Image)
For YIndex = 1 To ImageHeight(Image)
PixelColor = ReadPixelFast(XIndex,YIndex) And $FFFFFF
Red = PixelColor And $FF0000
Green = PixelColor And $00FF00
Blue = PixelColor And $0000FF
MaxColor = Maximum(Red,Green,Blue)
MaxColor = MaxColor + MaxColor Shl 8 + MaxColor Shl 16
WritePixelFast(XOffset,YOffset,MaxColor,BackBuffer())

Next

If KeyDown(1) Then End

Next
UnlockBuffer BackBuffer()
Flip

Function Maximum(Red,Green,Blue)
If Red > Green And blue
Return red
ElseIf Green > Red And Blue
Return Green
Else
Return Blue
EndIf
End Function

While Not KeyDown(1)

Wend