I just did some code to shift pixmaps as an example for someone on the blitzmax.com forum. Perhaps its of some use for those of you dabbling in bmax.
Graphics 800,600
Local pmap:TPixmap = LoadPixmap("img.png")
Local image:TImage = LoadImage("img.png",0)
Local time:Int = 0
Local utime:Int = 0
Local fps:Int = 0
Local fpstmp:Int = 0
Local update:Int = MilliSecs()
While Not KeyHit(KEY_ESCAPE)
Cls
DrawImage(image,0,0)
DrawText("Current FPS: "+fps,8,520)
DrawText("Last image update time in millisecs: "+utime,8,540)
Flip False
If KeyHit(KEY_LEFT) Then
time = MilliSecs()
image=shiftPmapLeft(pmap,32)
utime = MilliSecs()-time
End If
If KeyHit(KEY_RIGHT) Then
time = MilliSecs()
image=shiftPmapRight(pmap,32)
utime = MilliSecs()-time
End If
If KeyHit(KEY_UP) Then
time = MilliSecs()
image=shiftPmapUp(pmap,32)
utime = MilliSecs()-time
End If
If KeyHit(KEY_DOWN) Then
time = MilliSecs()
image=shiftPmapDown(pmap,32)
utime = MilliSecs()-time
End If
fpstmp :+ 1
If MilliSecs() > update+1000 Then
update = MilliSecs()
fps = fpstmp
fpstmp = 0
End If
Wend
End
Function shiftPmapLeft:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapWidth(pix)*4
Local moveSize:Int = (PixmapWidth(pix)-shift)*4
Local offset:Int = shift*4
For Local y:Int = 0 To PixmapHeight(pix)-1
MemCopy(pixPtr,pixPtr+offset,moveSize)
pixPtr :+ pitch
Next
Return LoadImage(pix,0)
End Function
Function shiftPmapRight:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapWidth(pix)*4
Local moveSize:Int = (PixmapWidth(pix)-shift)*4
Local offset:Int = shift*4
For Local y:Int = 0 To PixmapHeight(pix)-1
MemCopy(pixPtr+offset,pixPtr,moveSize)
pixPtr :+ pitch
Next
Return LoadImage(pix,0)
End Function
Function shiftPmapUp:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapWidth(pix)*4
For Local y:Int = 0 To PixmapHeight(pix)-1-shift
MemCopy(pixPtr,pixPtr+pitch*shift,pitch)
pixPtr :+ pitch
Next
Return LoadImage(pix,0)
End Function
Function shiftPmapDown:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
pixPtr :+ ((PixmapWidth(pix)*4)*(PixmapHeight(pix)-1))
Local pitch:Int = PixmapWidth(pix)*4
For Local y:Int = 0 To PixmapHeight(pix)-1-shift
MemCopy(pixPtr,pixPtr-(pitch*shift),pitch)
pixPtr :- pitch
Next
Return LoadImage(pix,0)
End Function
Sorry buddy But I just recently tried your code.
I have a properly named "img.png" file but upon pressing the buttons it exits the window. Left press is a special case that throws a message stating that there is an unhandled memory exception error. This looked interesting too.
For some unknown reason I must only have tested the code on 32bit images, and some of the code is hardcoded for the pixel data size of these, so it breaks on others like 24bit images. I have made a few changes and it should work on those as well now.
Graphics 800,600
Local pmap:TPixmap = LoadPixmap("img.png")
Local image:TImage = LoadImage("img.png",0)
Local time:Int = 0
Local utime:Int = 0
Local fps:Int = 0
Local fpstmp:Int = 0
Local update:Int = MilliSecs()
While Not KeyHit(KEY_ESCAPE)
Cls
DrawImage(image,0,0)
DrawText("Current FPS: "+fps,8,520)
DrawText("Last image update time in millisecs: "+utime,8,540)
Flip False
If KeyHit(KEY_LEFT) Then
time = MilliSecs()
image=shiftPmapLeft(pmap,32)
utime = MilliSecs()-time
End If
If KeyHit(KEY_RIGHT) Then
time = MilliSecs()
image=shiftPmapRight(pmap,32)
utime = MilliSecs()-time
End If
If KeyHit(KEY_UP) Then
time = MilliSecs()
image=shiftPmapUp(pmap,32)
utime = MilliSecs()-time
End If
If KeyHit(KEY_DOWN) Then
time = MilliSecs()
image=shiftPmapDown(pmap,32)
utime = MilliSecs()-time
End If
fpstmp :+ 1
If MilliSecs() > update+1000 Then
update = MilliSecs()
fps = fpstmp
fpstmp = 0
End If
Wend
End
Function shiftPmapLeft:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapPitch(pix)
Local pixSize:Int = pitch/PixmapWidth(pix)
Local moveSize:Int = (PixmapWidth(pix)-shift)*pixSize
Local offset:Int = shift*pixSize
For Local y:Int = 0 To PixmapHeight(pix)-1
MemCopy(pixPtr,pixPtr+offset,moveSize)
pixPtr :+ pitch
Next
Return LoadImage(pix,0)
End Function
Function shiftPmapRight:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapPitch(pix)
Local pixSize:Int = pitch/PixmapWidth(pix)
Local moveSize:Int = (PixmapWidth(pix)-shift)*pixSize
Local offset:Int = shift*pixSize
For Local y:Int = 0 To PixmapHeight(pix)-1
MemCopy(pixPtr+offset,pixPtr,moveSize)
pixPtr :+ pitch
Next
Return LoadImage(pix,0)
End Function
Function shiftPmapUp:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapPitch(pix)
Local pixSize:Int = pitch/PixmapWidth(pix)
For Local y:Int = 0 To PixmapHeight(pix)-1-shift
MemCopy(pixPtr,pixPtr+pitch*shift,pitch)
pixPtr :+ pitch
Next
Return LoadImage(pix,0)
End Function
Function shiftPmapDown:TImage(pix:TPixmap,shift:Int)
Local pixPtr:Byte Ptr = PixmapPixelPtr(pix)
Local pitch:Int = PixmapPitch(pix)
Local pixSize:Int = pitch/PixmapWidth(pix)
pixPtr :+ ((PixmapWidth(pix)*pixSize)*(PixmapHeight(pix)-1))
For Local y:Int = 0 To PixmapHeight(pix)-1-shift
MemCopy(pixPtr,pixPtr-(pitch*shift),pitch)
pixPtr :- pitch
Next
Return LoadImage(pix,0)
End Function
http://zac-interactive.dk/temp/shiftpixmap.zip (http://zac-interactive.dk/temp/shiftpixmap.zip)
[EDIT] added link to exe
Can u include an exe plz, cuz I dont have blitz.
Very nice, I finally got back from vacation and tried it.
Vacation, nice, unfortunately I have to wait until August before I have vacation time again :(
I assume something like this could be done for dynamic fake low res displays? Writing from pixmap sprites to a small pixmap back buffer then drawing a scaled result? I'm thinking that with some screen wrapping you could do a dynamic sine distortion effect. I may be off however but you know your pixmap pointer stuff. :kewl: