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

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