Faster ScrollImage

BlitzMax Forums/BlitzMax Programming/Faster ScrollImage

Hi guys!

I want to know what is the best way (fastest) to achieve a ScrollImage Function.

Here is my code:

Function ScrollImage(image:TImage, xamount:Int, yamount:Int = 0, frm:Int = 0) 
	Local pixmap:TPixmap, pixres:TPixmap
	Local p:Int
	Local w:Int, h:Int, i:Int, j:Int, x:Int, y:Int
	Local r:Int
	
	pixmap = LockImage(image, frm) 
	
	w = PixmapWidth(pixmap) 
	h = PixmapHeight(pixmap) 
	
	If Abs(xamount) > w Then
		r = xamount / w
		xamount:-(r * w) 
	End If
	If Abs(yamount) > h Then
		r = yamount / h
		yamount:-(r * h) 
	End If
	
	pixres = CopyPixmap(pixmap) 
	For j = 0 To h - 1
		For i = 0 To w - 1
			p = pixres.ReadPixel(i, j) 
			x = i
			If xamount <> 0 Then
				x:+xamount
				If x > w - 1 Then x:-(w - 1) 
				If x < 0 Then x:+w
			End If
			y = j
			If yamount <> 0 Then
				y:+yamount
				If y > h - 1 Then y:-(h - 1) 
				If y < 0 Then y:+h
			End If
			pixmap.WritePixel(x, y, p) 
		Next
	Next
End Function


Hope it will exits a quickest method...

I see pixmap. The moment you use it you have the worst possible performance achieved, point :)

The fast way is to simply shift the UV on the quad. This will do the same but in realtime.

check the max2d dx and opengl implementations on their respective (on dx its the xyzuv array, ogl has u0 v0 u1 v1 when I remember correctly. both on the respective TImageFrame extends for OGL and DX)

Thanks dreamora,

I know of this possibility but haven't found yet the way to access those variables.

You have to get the current TImageFrame from the Image (image.frames[frameNr]) and cast it to the DX or OpenGL image frame depending on if you are in OpenGL or DX

I ve tryed this:

ifr:TImageFrame = myimage.Frames[0]
TGLImageFrame(ifr).u0 = 0.5


But still no changes. What am I doing wrong?

Ok, it works now!

Changed:
ifr:TImageFrame = myimage.Frame(0)
TGLImageFrame(ifr).u0 = 0.5

Thanks...

dx wrap