The buffer->pixels are all rgb colours. Adding them together is going to look a bit funny - if you wanted that to give you an average colour then they'd have to split in to separate r,g,b bits, then do the add, the divide, and then convert back to an integer.
Say you have two colours, colour0 and colour1, then this is how to get the average colour
unsigned int r0 = (colour0>>16)&0xff;
unsigned int g0 = (colour0>>8)&0xff;
unsigned int b0 = colour0&0xff;
unsigned int r1 = (colour1>>16)&0xff;
unsigned int g1 = (colour1>>8)&0xff;
unsigned int b1 = colour1&0xff;
unsigned int r = (r0+r1)/2;
unsigned int g = (g0+g1)/2;
unsigned int b = (b0+b1)/2;
unsigned int averagecolour = (r<<16)|(g<<8)|b;
You can extend that to blend more colours, eg. (r0+r1+r2)/3 or (r0+r1+r2+r3)/4 etc.
But your real problem is that once you have got this rgb, you are trying to use it to look up a palette entry.
First of all this:
if (col<0xFF000000) col=0xFF000000;
is always going to set col to 0xff000000, because all rgb colours with no alpha are less than 0xff000000.
Then this:
col&255
is always going to be 0, because 0xff00000 & 255 is always 0.
So, I guess your palette colour 0 is black and pal->pixels[0] is black and that's what you see.
You could easily see this in the VS2008 debugger - you should try to learn to use it for single stepping through the code and watching the numbers change.
If you want to write the average colour into the screen, you can't use the palette, you'll need to use the calculation above to blend the colours, and do
screen_buffer->pixels[x+y*wwidth] = averagecolour;
Quick question:
Is buffer->pixels palette indexes or rgb colours? You didn't show it. Above I assumed they were rgb colours. But, if you're adding together palette indexes that's probably not going to work either - same problem, they always end up as 0 because of the if and the &. Then you might be able to use the resultant averaged palette index to look up a colour, but that's very unlikely to be what you really want - you'd have to have arranged the palette colours in a very special way.
Jim