Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!fernwood!shograf!jack From: jack@shograf.com (Jack Ritter) Newsgroups: comp.graphics Subject: Re: Gamma Summary: gamma correction for non linear phosphors Message-ID: <1991Apr24.160214.911@shograf.com> Date: 24 Apr 91 16:02:14 GMT References: <1991Apr21.185211.29293@wpi.WPI.EDU> Organization: SHOgraphics Lines: 38 > I am writing a graphics program in C and one of the routines has to > apply the gamma function to do some lightening. The program is in C on an If "gamma function" is to mean gamma correction, here's code I use. GAMMA should be set to the tube's gamma correction factor (usually around 2.5). The routine converts a (linear) real from 0.0 -> 256.0 to a gamma-corrected int 0 -> 255. #define GAMMA 2.5 int gammacorrect(intensity) real intensity; { int ival; real dval; /* scale to 0-1 range */ dval = intensity/255.0; if (dval > 1.0) dval = 1.0; if (dval<=0.0) dval = 0.0001; /* log(0) blows up */ /* do gamma correction */ dval = exp ( log(dval) / GAMMA ); /* convert to integer range: 0-255 */ dval *= 255.0; ival = (int) (dval+0.5); if (ival > 255) ival = 255; return(ival); } -- "The traffic lights, they turn blue tomorrow" Jimi Hendrix Jack Ritter