1 /*
2 * This software is copyrighted as noted below. It may be freely copied,
3 * modified, and redistributed, provided that the copyright notice is
4 * preserved on all copies.
5 *
6 * There is no warranty or other guarantee of fitness for this software,
7 * it is provided solely "as is". Bug reports or fixes may be sent
8 * to the author, who may or may not act on them as he desires.
9 *
10 * You may not include this software in a program or other software product
11 * without supplying the source, or without informing the end-user that the
12 * source is available for no extra charge.
13 *
14 * If you modify this software, you should include a notice giving the
15 * name of the person performing the modification, the date of modification,
16 * and the reason for such modification.
17 */
18 /* gamma.c, 6/30/86, T. McCollough, UU */
19
20 #include <math.h>
21
22 #include "round.h"
23
gamma(x,gamma_value)24 int gamma ( x, gamma_value )
25 int x;
26 float gamma_value;
27 {
28 static int gammamap[256];
29 static float gv = 0.0;
30
31 if (gv != gamma_value) {
32 int i;
33
34 gv = gamma_value;
35 for (i = 0 ; i < 256 ; i++)
36 gammamap[i] =
37 round_positive(255.0 * pow( i/255.0, 1.0/gv));
38 }
39
40 return gammamap[x];
41 }
42