Hi Peter,
if you want a better result ,
create getPixelRed ,green ,Blue functions and apply the previous algorithm for color component.
E.g
r_avr = R(x,y)+R(x+1,y) ........../ R_NUM
g_avr = G(x,y)+G(x+1,y) ...... /G_Num
B_avr = B(x,Y)+B(x+1,y)........../B_Num
final_Col = r_ave << 16 + g_avr << 8 + B_avr