ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/colrops.c
(Generate patch)

Comparing ray/src/common/colrops.c (file contents):
Revision 1.1 by greg, Fri Oct 19 16:33:44 1990 UTC vs.
Revision 2.4 by greg, Fri Oct 2 16:00:51 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "color.h"
12  
13 < #define MAXGSHIFT       2               /* maximum shift for gamma table */
13 > #define NULL            0
14  
15 < static BYTE     g_mant[256], g_nexp[256];
15 > extern char     *bmalloc();
16  
17 < static BYTE     g_bval[MAXGSHIFT+1][256];
17 > #define MAXGSHIFT       31              /* maximum shift for gamma table */
18  
19 + static BYTE     *g_mant = NULL, *g_nexp = NULL;
20  
21 < setcolrgam(g)                   /* set gamma conversion */
22 < double  g;
21 > static BYTE     (*g_bval)[256] = NULL;
22 >
23 > #ifndef pow
24 > extern double   pow();
25 > #endif
26 >
27 >
28 > setcolrcor(f, a2)               /* set brightness correction */
29 > double  (*f)();
30 > double  a2;
31   {
23        extern double   pow();
32          double  mult;
33          register int    i, j;
34 +                                        /* allocate tables */
35 +        if (g_bval == NULL && (g_bval =
36 +                        (BYTE (*)[256])bmalloc((MAXGSHIFT+1)*256)) == NULL)
37 +                return(-1);
38                                          /* compute colr -> gamb mapping */
39 +        mult = 1.0/256.0;
40          for (i = 0; i <= MAXGSHIFT; i++) {
28                mult = pow(0.5, (double)(i+8));
41                  for (j = 0; j < 256; j++)
42 <                        g_bval[i][j] = 256.0 * pow((j+.5)*mult, 1.0/g);
42 >                        g_bval[i][j] = 256.0 * (*f)((j+.5)*mult, a2);
43 >                mult *= 0.5;
44          }
45 +        return(0);
46 + }
47 +
48 +
49 + setcolrinv(f, a2)               /* set inverse brightness correction */
50 + double  (*f)();
51 + double  a2;
52 + {
53 +        double  mult;
54 +        register int    i, j;
55 +                                        /* allocate tables */
56 +        if (g_mant == NULL && (g_mant = (BYTE *)bmalloc(256)) == NULL)
57 +                return(-1);
58 +        if (g_nexp == NULL && (g_nexp = (BYTE *)bmalloc(256)) == NULL)
59 +                return(-1);
60                                          /* compute gamb -> colr mapping */
61          i = 0;
62          mult = 256.0;
63 <        for (j = 255; j >= 0; j--) {
64 <        rept:
37 <                g_mant[j] = mult * pow((j+.5)/256.0, g);
38 <                if (g_mant[j] < 128) {
63 >        for (j = 255; j > 0; j--) {
64 >                while ((g_mant[j] = mult * (*f)(j/256.0, a2)) < 128) {
65                          i++;
66                          mult *= 2.0;
41                        goto rept;
67                  }
68                  g_nexp[j] = i;
69          }
70 +        g_mant[0] = 0;
71 +        g_nexp[0] = COLXS;
72 +        return(0);
73   }
74  
75  
76 + setcolrgam(g)                   /* set gamma conversion */
77 + double  g;
78 + {
79 +        if (setcolrcor(pow, 1.0/g) < 0)
80 +                return(-1);
81 +        return(setcolrinv(pow, g));
82 + }
83 +
84 +
85   colrs_gambs(scan, len)          /* convert scanline of colrs to gamma bytes */
86   register COLR   *scan;
87   int     len;
88   {
89          register int    i, expo;
90  
91 +        if (g_bval == NULL)
92 +                return(-1);
93          while (len-- > 0) {
94                  expo = scan[0][EXP] - COLXS;
95                  if (expo < -MAXGSHIFT) {
# Line 88 | Line 127 | int    len;
127                  scan[0][EXP] = COLXS;
128                  scan++;
129          }
130 +        return(0);
131   }
132  
133  
# Line 97 | Line 137 | int    len;
137   {
138          register int    nexpo;
139  
140 +        if (g_mant == NULL | g_nexp == NULL)
141 +                return(-1);
142          while (len-- > 0) {
143                  nexpo = g_nexp[scan[0][RED]];
144                  if (g_nexp[scan[0][GRN]] < nexpo)
# Line 121 | Line 163 | int    len;
163                  scan[0][EXP] = COLXS - nexpo;
164                  scan++;
165          }
166 +        return(0);
167   }
168  
169  
# Line 129 | Line 172 | register COLR  *scan;
172   register int    len;
173   register int    adjust;
174   {
175 +        int     minexp;
176 +
177 +        if (adjust == 0)
178 +                return;
179 +        minexp = adjust < 0 ? -adjust : 0;
180          while (len-- > 0) {
181 <                scan[0][EXP] += adjust;
181 >                if (scan[0][EXP] <= minexp)
182 >                        scan[0][RED] = scan[0][GRN] = scan[0][BLU] =
183 >                        scan[0][EXP] = 0;
184 >                else
185 >                        scan[0][EXP] += adjust;
186                  scan++;
187          }
188   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines