How do I change the gamma of the immage?

I am not sure this the the correct way but it will Lighten and Darken the pic. Just add or subtract an arbitrary number from every single R, G, and B in the pic. Adding makes it brighter, subtracting makes it darker.