bmax to blitz3d acces writepixel

BlitzMax Forums/BlitzMax Programming/bmax to blitz3d acces writepixel

blitz3d 20 millisecs()
bmax 60 millisecs()

bmax is slowwww




you use a yourimage


Graphics 800,600,0

Local image:timage
Local x,y
Local pixmap:TPixmap


image=LoadImage:TImage("yourimage.jpg")

te=MilliSecs()

pixmap=LockImage(image)
For y=0 Until image.height
For x=0 Until image.width

argb=-Rnd(160000)-1
WritePixel(pixmap,x,y,argb)

Next
Next


UnlockImage image

tempo=MilliSecs()-te

While Not KeyDown(key_escape)

DrawImage image,0,0


DrawText tempo,610,10


Flip

Wend
End



; example blitz3d
Graphics 800,600,0,2
SetBuffer BackBuffer()


image=LoadImage("yourimage.jpg")


te=MilliSecs()

SetBuffer ImageBuffer(image)
LockBuffer ImageBuffer(image)

For xx=0 To ImageWidth(image)-1
For yy=0 To ImageHeight(image)-1
WritePixelFast(xx,yy,Rnd(-65000)-5,ImageBuffer(image))
Next
Next

UnlockBuffer ImageBuffer(image)
SetBuffer BackBuffer()

tempo=MilliSecs()-te


While Not KeyDown(1)

DrawImage image,0,0


Text 610,10,tempo


Flip

Wend
End

Try getting the base pointer of the pixmap with PixmapPtr, convert it to an Int Pointer, then do MyIntPtr[Offset]=-Rnd(160000)-1 and see how that compares.

Local MyIntPtr:Int Ptr=Int Ptr(PixmapPtr(pixmap))
Local MyRowSize:Int=PixmapPitch(pixmap)/4
...

MyIntPtr[x+(y*MyRowSize)]=-Rnd(160000)-1


See if that's faster.

Isn't it the rnd command that's quicker? Bmax writepixel seems quicker than writepixelfast as far as I can see.
<edit> Probably messed something up on the B3D side of things as it's been a while :
SuperStrict
Graphics 800,600,0
Local image:TImage = LoadImage("max.png")
Local from_pixmap:tpixmap = LockImage(image)
Local to_pixmap:tpixmap = CreatePixmap(PixmapWidth(from_pixmap) , PixmapHeight(from_pixmap) , PF_RGBA8888)
ClearPixels(to_pixmap)
Local t1:Int=MilliSecs()
For Local x:Int = 0 To PixmapWidth(from_pixmap) - 1
	For Local y:Int = 0 To PixmapHeight(from_pixmap) - 1
		Local argb:Int = ReadPixel(from_pixmap , x , y) 
		WritePixel(to_pixmap , x , y , argb)
	Next
Next
Local t2:Int=MilliSecs()
DrawPixmap from_pixmap , 0 , 0
DrawPixmap to_pixmap , PixmapWidth(from_pixmap) , 0
DrawText (t2-t1),0,400
Flip
WaitKey()

Graphics 800,600,0,2
Local image = LoadImage("max.png")
Local image2=CreateImage(ImageWidth(image),ImageHeight(image))
Local t1=MilliSecs()
SetBuffer ImageBuffer(image2)
LockBuffer ImageBuffer(image)
LockBuffer ImageBuffer(image2)
t1=MilliSecs()
For x=0 To ImageWidth(image) - 1
	For y=0 To ImageHeight(image) - 1
		argb = ReadPixelFast(x,y,ImageBuffer(image)) 
		WritePixelFast(x,y,  argb,ImageBuffer(image2))
	Next
Next
t2=MilliSecs()
UnlockBuffer ImageBuffer(image) 
UnlockBuffer ImageBuffer(image2)
SetBuffer BackBuffer()
DrawImage image,0,0
DrawImage image2,ImageWidth(image),0
Text 0,400,(t2-t1)
Flip
WaitKey()


ok!
i tested without rnd

blitz3d it fast bmax!

11 millisecs()

You might want to post the code you tested with.
What was the result of running the code I posted above?