#include #include /* * brightness(b) is proportional to input voltage(v) according to the following * equation: * b = k*v^g * * where "g" is gamma. Assume we want to express brightness in percent (0-100) * and voltage in pixel values (0-255). At full scale, we have: * 100 = k*255^g * * or... * k = 100/(255^g) * * substituting this value for "k" in the original equation gives the following: * b = (100/(255^g)) * v^g * * or... * v = [b / (100/(255^g))] ^ (1/g) * * or... * v = 255 * ((b/100) ^ (1/g)) * */ int pv(double g, double b) { /* inputs: * g gamma * b brightness (percent) * returns: * pixel value (0-255) */ return 255 * pow(b/100, 1/g) + 0.5; } int main() { double g, b; int v; b = 50; /* half pixels black, half white */ for (g = 1.6; g < 2.81; g += .1) { v = pv(g, b); printf("gamma = %.2f, value = %d (%02x)\n", g, v, v); } return 0; }