Deduplicate gamma-scaling code between osx.x and x11.c.

This involves a bit of macro munging because they use different
types (float vs. unsigned short) for their gamma table values.