LockedPixels

BlitzPlus Forums/BlitzPlus Beginners Area/LockedPixels

JBR(Posted 2007) [#1]
Hi, loading in an image & then reading from it to put it in an array for faster processing later.

I'm using readpixelfast() & then i read about the LockedPixels() command & use Peek().

Tried both ways and they take pretty much the same time. Should they? And if so what is the point in using LockedPixels?

Thanks
Jim


Matty(Posted 2007) [#2]
Lockedpixels is faster for writing to by copying entire rows of banks. Rather than simply plotting 1 pixel at a time with either writepixelfast or pokeint into the lockedpixels bank you can do something like this:

(pseudocode only as I can't remember the exact syntax for copybank right now)

pixelbank = lockedpixels()
pitch=lockedpitch()

for row=0 to imageheight(image)-1
copybank  pixelbank,srcoff,yourbank,yourbankoffset,imagewidth(image)*4 ;for 32bit images
srcoff=srcoff+pitch
yourbankoffset=yourbankoffset+imagewidth(image)*4
next


Something like that should be faster, although probably not by a great deal as reading pixels is always going to be slow in blitz - for large numbers of pixels anyway.

A much faster way is to do the reading into an array or bank one time only, then writing the contents of the bank to disk so that next time on loading the game you simply 'readbytes' straight into the bank at load time, although I don't know if what you are doing is pre game or in game.