Getting number of BMP colors

How do you extract how many color's are being used in a particular bitmap?
 I tried getting the BITSPERPIXEL (and shifting the bits left 1), but even
if there's 1 color in the bitmap, it will return a large number.