Reading Image Buffers

BlitzPlus Forums/BlitzPlus Programming/Reading Image Buffers

PaulJG(Posted 2003) [#1]
Could someone please explain to me, why the below snippet of code fails ?

heightmap=LoadImage("testh.bmp")
offset#=256/225
		
	For y=1 To 255
		For x=1 To 255
			a=ReadPixel(xmap#,ymap#,heightmap)
			xmap#=xmap#+offset#
		Next
	ymap#=ymap#+offset#
	xmap#=0
	Next


I'm using this in B3D to load in a pic and read off the heightmap data - but its bringing up the error 'Buffer does not exist - a=ReadPixel(xmap#,ymap#,heightmap)'

Thanks Paul.


semar(Posted 2003) [#2]
ReadPixel (as well ReadPixelFast) need an image buffer to work with.

So you should first set the image buffer:
setbuffer imagebuffer(heightmap)

then lock the buffer with the command lockbuffer

At the end of the process, use UnlockBuffer.

Hope this helps,
Sergio.


PaulJG(Posted 2003) [#3]
Thanks Semar, tried the alterations.. still reporting that the buffer does not exist ?.

heightmap=LoadImage("testh.bmp")
offset#=256/225
SetBuffer ImageBuffer(heightmap)
LockBuffer heightmap

	For y=1 To 255
		For x=1 To 255
			a=ReadPixel(xmap#,ymap#,heightmap)
			xmap#=xmap#+offset#
		Next
	ymap#=ymap#+offset#
	xmap#=0
	Next
	UnlockBuffer heightmap


Now fails at the lockbuffer command. !?


Ross C(Posted 2003) [#4]
Only thing i can think of is the heightmap image doesn't exist.


PaulJG(Posted 2003) [#5]
If only that was the problem :( it does exist.

Although I'm using Blitz3d - this wouldnt/shouldnt effect these types of image commands should it ???


Ross C(Posted 2003) [#6]
another thing tho, might be unrelated

offset#=256/225


try

offset#=256.0/225.0


For some reason it gives back an integer unless you state the number as a float. I'm at college so can't test it.


Floyd(Posted 2003) [#7]
heightmap=LoadImage("testh.bmp")

hBuffer = ImageBuffer(heightmap)
LockBuffer hBuffer

For y=1 To 255  ; probably want 0 to 255.
	For x=1 To 255
		a=ReadPixel(x,y,hBuffer)
		; do something with returned value
	Next
	; likewise...
Next

UnlockBuffer hBuffer



PaulJG(Posted 2003) [#8]
Thanks Floyd :) .. and Robs just posted up a nice link to some RGB functions in the 3d forum.

I think I was somehow getting my image and texture banks mixed up.