Texture access.

I have a camera that writes to a graphics buffer.
Is there an efficient way to directly access this buffer when it has been written into.

For example I may want to count the number of pixels that are of a certain colour, and do some scene manipulation depending on the result before the next frame update.

Alternatively, is there a post process filter idea that could produce similar output as using a for x…for y is way to slow.

Note using the pnmimage read pixels is much to slow.