Pixel Manipulating ala SetBuffer()

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

Think this is it Thumbz...
'====================================================
' 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(32,32,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 31
	SetColor Rand(255),Rand(255),Rand(255)
	DrawRect 0,a,32,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
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 31
		For Local y=0 To 31
			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
DrawPixmap my_pixmap,0,60
DrawText "Pixmap after pixelling",0,100
UnlockImage(mainimage)
' notice that once unlocked the changes made to the pixmap are reflected on the image.
DrawImage mainimage,0,120
DrawText "MainImage after pixelling",0,160
DrawPixmap my_pixmap,0,180
DrawText "..and the pixmap is still there",0,230
FlushMem
DrawPixmap my_pixmap,0,250
DrawText "even after flushmem",0,310
Flip
WaitKey()

This all seems OK. The only thing missing from the old Imagebuffers is being able to draw 2 images to the same pixmap (unless somebody else knows how to do it). Obvious answer, as before, is to write them both to backbuffer and grab them. Small images aren't a problem but larger images, which took 1 ms in B2D, take about 226ms due to the grabimage.
Anyway, hope it helps.