Images and Pixmaps

BlitzMax Forums/BlitzMax Beginners Area/Images and Pixmaps

JBR(Posted 2014) [#1]
Hi, I'm coming from B3D and trying to get to grips with images/pixmaps.

I need to know is there is a faster way to fill an image than this way.
Can I get direct access without using 'WritePixel'?

SetGraphicsDriver GLMax2DDriver()

Const ALPHABITS=$ff000000

Graphics( 1920,1080,32,60,GRAPHICS_BACKBUFFER )


image=CreateImage(512,256,1,0)


time=MilliSecs()

For i=1 To 100

	map=LockImage(image)
	For y = 0 To 256-1
		For x=0 To 512-1
			WritePixel(map,x,y,ALPHABITS|(x & 255))
		Next
	Next
	UnlockImage(image)

	DrawImageRect image,0,0,1920,1080
	Flip(0)

Next

time = MilliSecs()-time

DrawText "Time :"+time,0,20

Flip
WaitKey



GfK(Posted 2014) [#2]
Why are you using DrawImageRect and Flip() in your For/Next loop? You don't need to do that if all you're doing is plotting pixels into a pixmap, and they will be slowing the process down massively.


JBR(Posted 2014) [#3]
Purely down to speed testing. As I would be doing this in the main game loop anyway.


Jesse(Posted 2014) [#4]
yes, but I hope you know what you are getting into.
this is the lowest level and fastest you can get to:
SuperStrict

Graphics 640,480
Local image:TImage = CreateImage(64,64)			'create an image( pixmap area not 0'ed out) 
Local pixmap:TPixmap = LockImage(image)			'extract it's pixmap
Local pixels:Int Ptr = Int Ptr(pixmap.pixels)		'access pixmap memory area.
For Local i:Int = 0 Until 64*64
	pixels[i] = 0 ' blank out all of the pixels in the image
Next
pixels[0] = $FF00FF00 ' write directly to the pixmap the color green
pixels[1] = $FF00FF00 ' note this is the color green for little endian
pixels[64]= $FF00FF00 ' big endian might be different. as colors are stored
pixels[65]= $FF00FF00 ' different on big endian operating system.
DrawImage image,100,100 'draw the modified image.
Flip()
WaitKey()



JBR(Posted 2014) [#5]
Thanks Jesse, that's what I was hoping for.


JBR(Posted 2015) [#6]
In B3D you can do a setbuffer backbuffer() and read/write directly.

Is this possible in Bmax?

Any way to get the pixmap from the backbuffer?

Thanks
Jim


GfK(Posted 2015) [#7]
GrabPixmap()