Create a grayscaled image on the fly?

BlitzMax Forums/BlitzMax Beginners Area/Create a grayscaled image on the fly?

Tested once, looked ok.
Didn't verify anything tho :P

SuperStrict

Local window:TGadget=CreateWindow("o_O",0,0,640,480)
Local canvas:TGadget=CreateCanvas(0,0,640,480,window)
Local img:TImage=LoadImage("Porn193882.JPG")

MakeGrey img

SetGraphics CanvasGraphics(canvas)
	Cls
	DrawImage img,0,0
Flip
Notify "o_O"
End


Function MakeGrey(img:TImage)
	If img=Null RuntimeError "no image!"
	Local c:Int
	Local x:Int
	Local y:Int
	Local pm:TPixmap=LockImage(img)
		For y=0 Until ImageHeight(img)
			For x=0 Until ImageWidth(img)
				c= ReadPixel(pm,x,y) & 255
				c:+(ReadPixel(pm,x,y) Shr 8) & 255
				c:+(ReadPixel(pm,x,y) Shr 16) & 255
				c:/3
				WritePixel pm,x,y,$ff000000|c+256*c+65536*c
			Next
		Next
	UnlockImage img
End Function