How To Use LockedPixels() ?

BlitzPlus Forums/BlitzPlus Beginners Area/How To Use LockedPixels() ?

_PJ_(Posted 2012) [#1]
From the limited information given, LockedPixels returns a 'bank' - I assumed this to be a BankHandle as used by the other Bank commands within B+, however, the compiler crashes (as in actually exits with a windows error, not a standard compilation/Blitz error message) when it reaches the CopyBank function here:

	Local Buffer=GraphicsBuffer()
	
	Local Image=LoadImage(Path)
	If (Not (Image))
		Return
	End If
	
	Local IB=ImageBuffer(Image)
	
	Local W=ImageWidth(Image)
	Local H=ImageHeight(Image)
	Local Pixels=W*H
	Local Size=Pixels Shl 2
	
	Local White
	Local Black
		
	Local Bank=CreateBank(Size)
	
	LockBuffer(IB)
	Local Temp=LockedPixels(IB)

;Next Line Causes Crash!
	CopyBank Temp,0,Bank,0,Size


Clearly this is the wrong usage, but aside from manually POKEing each pixel (as one would with Blitz3D), how can LockedPixels be put to effective use?


Floyd(Posted 2012) [#2]
Here's something I posted three years ago. I don't remember when I actually wrote the code.

LockedPixels quick intro

Note the buffer is 200 pixels wide, and my graphics card at that time used 832 bytes. It was padding the image buffer so the number of pixels was a multiple of 16, so number of bytes is a multiple of 64.

I just ran the code again and the pitch ( width in bytes ) is 896. At 4 bytes per pixel that is 224 pixels. So my current card/driver is padding each row with an extra 24 pixels. I don't know why it needs all that extra space, but it shows you can't make any assumptions about the true width of the buffer. You have to rely on LockedPitch().

Last edited 2013


Floyd(Posted 2012) [#3]
Here's a nice plasma demo, which I changed slightly to match my 1920x1080 monitor.




_PJ_(Posted 2012) [#4]
Thanks, Floyd -

I need to look into what's going on a bit more closely since I'm not completely understanding what's going on, but I should be able to figure it out from both examples you've provided.