#include <stdio.h> #include <math.h> #include <gl/gl.h> #include <gl/device.h>
/* Example: gammaramp.c */
/* * This example program shows the use of gamma ramps. Gamma ramps * are useful for correcting the appeareance of photographs * (images) and antialiased lines (to correct for monitor * phosphors), and for implementing color-map tricks. * * Pressing PF7 or PF8 changes the gamma correction factor and * loads the new gamma ramp. A window shows the current gamma * factor and a black-to-white scale. */
/* ----------------------------------------------------------- */
/* * This routine prints out the current value of gamma in a window. * At the bottom of the window is a color bar. */
void show_val (float gam) {
char gamstr[32]; cpack (0x0); /* black */ clear(); cpack (0xff); /* red */ cmov2 (10, 80); charstr ("Currently, the gamma correction factor is "); sprintf (gamstr, "%3.2f", gam); charstr (gamstr); cmov2 (10, 60); charstr ("To lower gamma, press PF7"); cmov2 (10, 40); charstr ("To raise gamma, press PF8"); /* draw a sample color bar */ cpack (0x0); /* black */ pmv2 (10, 10); pdr2 (10, 25); cpack (0xffffff); /* white */ pdr2 (390, 25); pdr2 (390, 10); pclos ();
}
/* ----------------------------------------------------------- */
/* * The following routine updates the adapter gamma ramps * based on the value of gamma passed to it. Note that the * entire screen is affected (because there is only one set * of ramps for the entire screen). */ void update_ramps (float gam) { short rramp[256], gramp[256], bramp[256]; int i; double corr, og; /* compute the new gamma ramp */ og = 1.0 / (gam + 0.00001); corr = 255.0 * pow ((double) (1.0 / 255.0), og); for (i=0; i<256; i++) { rramp[i] = gramp[i] = bramp[i] = (short) (corr * pow((float) (i), og)); } /* load the new gamma ramp */ gammaramp (rramp, gramp, bramp); }
/* ----------------------------------------------------------- */
main() { float gamma = 1.0; float delta = 0.05; short dev, val; prefsize (400, 100); minsize (400, 100); maxsize (400, 100); /* disable resizing of window */ winopen ("gamma-ramp demo"); RGBmode (); /* gamma ramps work in color map mode too! */ gconfig (); update_ramps (gamma); /* initialize the gamma ramps */ show_val (gamma); /* print current value of gamma */ qdevice (RIGHTMOUSE); /* queue up desired devices */ qdevice (ESCKEY); qdevice (F7KEY); qdevice (F8KEY); while (TRUE) { dev = qread (&val); switch (dev) { case ESCKEY: case RIGHTMOUSE: exit(0); case F7KEY: if (val == FALSE) break; /* do nothing for key release */ gamma += delta; update_ramps (gamma); show_val (gamma); break; case F8KEY: if (val == FALSE) break; /* do nothing for key release */ gamma -= delta; update_ramps (gamma); show_val (gamma); break; case REDRAW: show_val (gamma); default: break; } }
}
Pixel Coverage in GL3.2 Version 4 for AIX: Programming Concepts describes aspects of antialiasing (smoothing lines for screen display) related to color variation in the pixels.