counting the no. of pixels within a bounded area

I am struggling with counting the no. of pixels manually within a bounded area of a .bmp file.
What I came up with is load a .bmp file, go through each pixel, identify the colour of them, save in an array and increase a counter by spotting a particular colour.
I think glReadPixel, glStorePixel and other methods should be applied. That’s what I’ve got so far.
Any Genius can point me to a correct and clear direction, I’d be appreciated.

Check out this link. I don’t think this is supported in hardware on all platforms, though:

thanks mate