Scrolling an Image

BlitzMax Forums/BlitzMax Programming/Scrolling an Image

How about something like this:

SuperStrict

Graphics 640,480
SetClsColor 100,100,100
Cls
Local img1:TImage = LoadImage("test.png")
Local time:Int = MilliSecs()
Local img2:TImage = offsetImage(img1,32,32)
Print "processtime was: "+(MilliSecs()-time)+"ms"
DrawImage(img1,0,0)
DrawImage(img2,256,0)
Flip
WaitKey()
End

Function offsetImage:TImage(source:TImage,xOffset:Int,yOffset:Int)
	Local scrPix:TPixmap = LockImage(source)
	Local tmpPix:TPixmap = CopyPixmap(scrPix)
	Local scrPtr:Byte Ptr = PixmapPixelPtr(scrPix,0,0)
	Local tmpPtr:Byte Ptr = PixmapPixelPtr(tmpPix,0,0)
	Local pitch:Int = scrPix.width
	Local w:Int = scrPix.width
	Local h:Int = scrPix.height
	Local x:Int,y:Int
	Local tx:Int,ty:Int
	For x = 0 To w-1
		For y = 0 To h-1
			tx = xOffset+x
			ty = yOffset+y
			If tx => w Then tx :- w
			If ty => h Then ty :- h
			If tx < 0 Then tx :+ w
			If ty < 0 Then ty :+ h
			tmpPtr[x*4+y*4*pitch] = scrPtr[tx*4+ty*4*pitch]
			tmpPtr[x*4+y*4*pitch+1] = scrPtr[tx*4+ty*4*pitch+1]
			tmpPtr[x*4+y*4*pitch+2] = scrPtr[tx*4+ty*4*pitch+2]
			tmpPtr[x*4+y*4*pitch+3] = scrPtr[tx*4+ty*4*pitch+3]
		Next
	Next

	Return LoadImage(tmpPix)
End Function