Flip Image

Blitz3D Forums/Blitz3D Programming/Flip Image

Hello.

I have written a little routine to flip a image and save it to a new file. Everything works fine except one little bug, and I am not able to find it.

If I flip an image vertical the new image will have wrong pixels at the first line (y=0). If I flip an image horizontal I have wrong pixels at the first column (x=0).

I'm really going mad - hope someone could help me. Here is the code:

Function FlipImg(infile$,outfile$,horz, verz)
	Local img = LoadImage(infile$)
	
	Local w = ImageWidth(img)
	Local h = ImageHeight(img)
	
	Local newimage = CreateImage(w,h)
	
	LockBuffer ImageBuffer(img)
	LockBuffer ImageBuffer(newimage)
		
	For y=0 To h
		For x=0 To w
			pix = ReadPixelFast(x,y,ImageBuffer(img))					
			If horz=1 And verz=0 Then WritePixelFast(w-x,y,pix,ImageBuffer(newimage))
			If horz=0 And verz=1 Then WritePixelFast(x,h-y,pix,ImageBuffer(newimage))
			If horz=1 And verz=1 Then WritePixelFast(w-x,h-y,pix,ImageBuffer(newimage))
		Next		
	Next
	
	UnlockBuffer ImageBuffer(img)
	UnlockBuffer ImageBuffer(newimage)
	
	SaveBuffer (ImageBuffer(newimage),outfile$)
	
	FreeImage img
	FreeImage newimage
	
End Function