Three thoughts on your dilemna.
First:
When you use the following line:
WritePixelFast x,y,c1+c2,bm
you have to remember that the red, green, and blue values each are limited to values of 0 to 255. If you do a straight across the board c1+c2, where if the sum of any red, green, or blue values could add together to more than 255, there could be unpredictable results. Try this to illustrate what I am saying:
Graphics 800,600
c1=$ffaabbcc ;using red, green, blue values that will
c2=$ffaabbcc ;overflow, that is, go greater than 255 each
c3=c1+c2
Print Hex$(c3) ;this operation effectively halves the color
Color $aa,$bb,$cc ;ie the original color
Rect 100,100,200,200
Color (c3 And $ff0000) Shr 16,(c3 And $ff00) Shr 8,(c3 And $ff) ;ie the colors added togther
Rect 400,100,200,200
MouseWait()
End
Second:
I don't know what the effects are of using the lockbuffer command three times sequentially. Maybe some other voices can address this point.
Third (to go faster):
You could try reading the color values of the images into arrays, then instead of doing ReadPixelFast on-the-fly, the values could just be read back in from the array. It's a little more memory intensive, but is faster. In other words, put the following OUTSIDE the function:
dim c1(Screen_Width-1,Screen_Height-1);arrays are global
dim c2(Screen_Width-1,Screen_Height-1)
For y=0 To Screen_Height
For x=0 To Screen_Width
c1(x,y)=ReadPixelFast(x,y,b1)
c2(x,y)=ReadPixelFast(x,y,b2)
Next
Next
Then you can access that info inside your Function:
For y=0 To Screen_Height
For x=0 To Screen_Width
WritePixelFast x,y,c1(x,y)+c2(x,y),bm
Next
Next
Of course, this latter bit of code still doesn't address the issue of summing RGB color values together when they can overflow past 255 within their 0-255 range. Depending on what you want to do, you might read in the red, green and blue values separately into intergers, add the integers together and divide by two (if an average is what you're looking for), or just let the color info max out at 255. Generally, these two concepts are illustrated thus:
my_red = (c1_red+c2_red)/2 ;if averaging is what you want
(OR)
my_red = (c1_red+c2_red):if my_red>255 then my_red=255