Pixel Manipulating ala SetBuffer()

BlitzMax Forums/BlitzMax Beginners Area/Pixel Manipulating ala SetBuffer()

These are the tests I ran...
'====================================================
' Copying and manipulating images
' Care Of Setbuffer Imagebuffer() and WritePixelFast
' attempt 4001
'====================================================
Strict
'
' Screen setup dimensions.
'
Const XRES=640
Const YRES=480

Graphics XRES,YRES

Global MainImage=CreateImage(640,480,dynamicimage)		' the main image to be used for manipulating.
' The mainimage needs to be created with dynamicimage if it's to be changed in any way.
'
' create a custom makeshift image.
'
For Local a=0 To 479
	SetColor Rand(255),Rand(255),Rand(255)
	DrawRect 0,a,640,1
Next
GrabImage MainImage,0,0
'need to set the color back as it affects subsequent drawing and text
SetColor 255,255,255
Cls
DrawImage mainimage,0,0
DrawText "Mainimage",0,40
Local time_start:Int = MilliSecs()
Global my_pixmap:TPIxmap=LockImage(MainImage)
' took out the arrays for a simple test and I'm happier with SHR and SHL
	For Local x=0 To 639
		For Local y=0 To 479
			Local RGB=ReadPixel(my_pixmap,x,y)
			Local alpha = RGB Shr 24 & 255
			Local Red = RGB Shr 16 & 255
			Local Green = RGB Shr 8 & 255
			Local blue = RGB Shr 0 & 255
			' used the same values as yourself.
             red= red * 0.222 ; green=green*0.555 ; blue=blue*0.125
             RGB = (alpha Shl 24) | (red Shl 16) | (green Shl 8) | (blue Shl 0)
             WritePixel (my_pixmap,x,y,rgb)
		Next
	Next
UnlockImage(mainimage)
' notice that once unlocked the changes made to the pixmap are reflected on the image.
DrawImage mainimage,0,0
DrawText "MainImage after pixelling",0,160
Local time_end:Int=MilliSecs()
Local total_time:Int = time_end - time_start
DrawText "Total_time " + total_time,0,170
Flip
FlushMem
WaitKey()

and in B2D...
Const XRES=640
Const YRES=480

Graphics XRES,YRES
SetBuffer BackBuffer()

Global MainImage=CreateImage(640,480)	
For a=0 To 480
	Color Rand(255),Rand(255),Rand(255)
	Rect 0,a,640,1,solid
Next
GrabImage MainImage,0,0
Color 255,255,255
Cls
DrawImage mainimage,0,0
Text 0,40,"Mainimage"
time_start = MilliSecs()
SetBuffer ImageBuffer(mainimage)
LockBuffer ImageBuffer(MainImage)
	For  x=0 To 640
		For  y=0 To 480
			 RGB=ReadPixelFast(x,y,ImageBuffer(mainimage))
			 alpha = RGB Shr 24 And 255
			 Red = RGB Shr 16 And 255
			 Green = RGB Shr 8 And 255
			 blue = RGB Shr 0 And 255
             red= red * 0.222 : green=green*0.555 : blue=blue*0.125
             RGB = (alpha Shl 24) Or (red Shl 16) Or (green Shl 8) Or (blue Shl 0)
             WritePixelFast x,y,rgb,ImageBuffer(mainimage)
		Next
	Next
UnlockBuffer ImageBuffer(mainimage)
SetBuffer BackBuffer()
DrawImage mainimage,0,0
Text 0,160,"MainImage after pixelling"
time_end=MilliSecs()
total_time = time_end - time_start
Text 0,170,"Total_time " + total_time
Flip
WaitKey()