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

Comparing ray/src/common/tonemap.c (file contents):
Revision 3.18 by greg, Fri Jan 7 22:05:30 2005 UTC vs.
Revision 3.22 by greg, Thu Mar 23 22:01:43 2006 UTC

# Line 171 | Line 171 | int    len
171   {
172          static const char funcName[] = "tmCvColors";
173          static COLOR    csmall = {.5*MINLUM, .5*MINLUM, .5*MINLUM};
174 +        static BYTE     gamtab[1024];
175 +        static double   curgam = .0;
176          COLOR   cmon;
177          double  lum, slum;
178          double  d;
# Line 180 | Line 182 | int    len
182                  returnErr(TM_E_TMINVAL);
183          if ((ls == NULL) | (scan == NULL) | (len < 0))
184                  returnErr(TM_E_ILLEGAL);
185 +        if (cs != TM_NOCHROM && fabs(tms->mongam - curgam) > .02) {
186 +                curgam = tms->mongam;                   /* (re)build table */
187 +                for (i = 1024; i--; )
188 +                        gamtab[i] = (int)(256.*pow((i+.5)/1024., 1./curgam));
189 +        }
190          for (i = len; i--; ) {
191                  if (tmNeedMatrix(tms)) {                /* get monitor RGB */
192                          colortrans(cmon, tms->cmat, scan[i]);
# Line 188 | Line 195 | int    len
195                          cmon[GRN] = tms->inpsf*scan[i][GRN];
196                          cmon[BLU] = tms->inpsf*scan[i][BLU];
197                  }
198 + #ifdef isnan
199 +                if (isnan(cmon[RED]) || isinf(cmon[RED])) cmon[RED] = .0f;
200 +                if (isnan(cmon[GRN]) || isinf(cmon[GRN])) cmon[GRN] = .0f;
201 +                if (isnan(cmon[BLU]) || isinf(cmon[BLU])) cmon[BLU] = .0f;
202 + #endif
203                                                          /* world luminance */
204                  lum =   tms->clf[RED]*cmon[RED] +
205                          tms->clf[GRN]*cmon[GRN] +
# Line 226 | Line 238 | int    len
238                          cmon[RED] = cmon[GRN] = cmon[BLU] = lum;
239                  }
240                  d = tms->clf[RED]*cmon[RED]/lum;
241 <                cs[3*i  ] = d>=.999 ? 255 :
230 <                                (int)(256.*pow(d, 1./tms->mongam));
241 >                cs[3*i  ] = d>=.999 ? 255 : gamtab[(int)(1024.*d)];
242                  d = tms->clf[GRN]*cmon[GRN]/lum;
243 <                cs[3*i+1] = d>=.999 ? 255 :
233 <                                (int)(256.*pow(d, 1./tms->mongam));
243 >                cs[3*i+1] = d>=.999 ? 255 : gamtab[(int)(1024.*d)];
244                  d = tms->clf[BLU]*cmon[BLU]/lum;
245 <                cs[3*i+2] = d>=.999 ? 255 :
236 <                                (int)(256.*pow(d, 1./tms->mongam));
245 >                cs[3*i+2] = d>=.999 ? 255 : gamtab[(int)(1024.*d)];
246          }
247          returnOK;
248 + }
249 +
250 +
251 + TMbright
252 + tmCvLuminance(                          /* convert a single luminance */
253 + double  lum
254 + )
255 + {
256 +        double  d;
257 +
258 +        if (lum <= TM_NOLUM)
259 +                return(TM_NOBRT);
260 +        d = TM_BRTSCALE*log(lum);
261 +        if (d > 0.)
262 +                return((TMbright)(d+.5));
263 +        return((TMbright)(d-.5));
264   }
265  
266  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines