I wouldn't recommend using WritePixelFast unless your reading/writing a decent amount of pixel. The time it takes to lock a buffer and unlock it again (which you have to do with read/writepixelfast), outweighs the speed gained.
ReadPixel and WritePixel should be faster than plot and get colour though :o)
You will need 3 Globals in your code, in order to get the results for the readcolour operation:
Global Got_Red
Global Got_Green
Global Got_Blue
Just read these globals after you call the Get_Color_Fast() function
Function Get_Color_Fast(x,y)
RGB1=ReadPixel(x,y,FrontBuffer())
Got_Red=(RGB1 And $FF0000)Shr 16;separate out the red
Got_Green=(RGB1 And $FF00) Shr 8;green
Got_Blue=RGB1 And $FF;and blue parts of the color
;a=(RGB1 And $FF000000)Shr 24 <<< enable this is you want the alpha value to be read also.
End Function
Function Plot_Fast(x,y,r,g,b,a=0)
newrgb= (a Shl 24) Or (r Shl 16) Or (g Shl 8) Or b; combine the ARGB back into a number
WritePixel x,y,argb,BackBuffer() ; You will most likely want to write to the back buffer, to be
; Flipped. If not, change to appropriate buffer.
End Function
If you really want to use WritePixelFast, lock the frontbuffer() or backbuffer() (whatever one your accessing) at the start of your function, and unlock at the end, NOT after each read/write operation. And obviously function the commands in the functions i provided to WritePixelFast and WritePixelFast :o)
Hope that helps.
|