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

Comparing ray/src/common/falsecolor.c (file contents):
Revision 3.1 by greg, Mon Nov 14 22:18:18 2005 UTC vs.
Revision 3.2 by greg, Tue Nov 15 06:52:38 2005 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12  
13   #include        <stdio.h>
14   #include        <math.h>
15 + #include        <string.h>
16   #include        "tmprivat.h"
17   #include        "falsecolor.h"
18  
# Line 34 | Line 35 | fcInit(BYTE fcscale[256][3])
35   int
36   fcFixedLinear(FCstruct *fcs, double Lwmax)
37   {
38 <        double  v;
38 >        double  mult;
39          int     i;
40  
41          if ((fcs == NULL) | (Lwmax <= MINLUM))
42                  return(TM_E_ILLEGAL);
43          if (fcs->lumap != NULL)
44                  free((void *)fcs->lumap);
45 <        v = TM_BRTSCALE * log(Lwmax);
46 <        fcs->mbrmax = (int)(v<0. ? v-.5 : v+.5);
46 <        v = TM_BRTSCALE * log(Lwmax/256.);
47 <        fcs->mbrmin = (int)(v<0. ? v-.5 : v+.5);
45 >        fcs->mbrmin = tmCvLuminance(Lwmax/256.);
46 >        fcs->mbrmax = tmCvLuminance(Lwmax);
47          fcs->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1));
48          if (fcs->lumap == NULL)
49                  return(TM_E_NOMEM);
50 <        v = 255.999/tmLuminance(fcs->mbrmax);
50 >        mult = 255.999/tmLuminance(fcs->mbrmax);
51          for (i = fcs->mbrmin; i <= fcs->mbrmax; i++)
52 <                fcs->lumap[i] = (int)(v * tmLuminance(i));
52 >                fcs->lumap[i] = (int)(mult * tmLuminance(i));
53          returnOK;
54   }
55  
# Line 58 | Line 57 | fcFixedLinear(FCstruct *fcs, double Lwmax)
57   int
58   fcFixedLog(FCstruct *fcs, double Lwmin, double Lwmax)
59   {
61        double  v;
60          int     i;
61  
62          if ((fcs == NULL) | (Lwmin <= MINLUM) | (Lwmax <= Lwmin))
63                  return(TM_E_ILLEGAL);
64          if (fcs->lumap != NULL)
65                  free((void *)fcs->lumap);
66 <        v = TM_BRTSCALE * log(Lwmin);
67 <        fcs->mbrmin = (int)(v<0. ? v-.5 : v+.5);
70 <        v = TM_BRTSCALE * log(Lwmax);
71 <        fcs->mbrmax = (int)(v<0. ? v-.5 : v+.5);
66 >        fcs->mbrmin = tmCvLuminance(Lwmin);
67 >        fcs->mbrmax = tmCvLuminance(Lwmax);
68          fcs->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1));
69          if (fcs->lumap == NULL)
70                  return(TM_E_NOMEM);
# Line 129 | Line 125 | fcLogMapping(FCstruct *fcs, TMstruct *tms, int pctile)
125          if (i < 0)
126                  return(TM_E_TMFAIL);
127          wbrmax = tms->hbrmin + i;
128 <        return(fcFixedLog(fcs, tmLuminannce(wbrmin), tmLuminance(wbrmax)));
128 >        return(fcFixedLog(fcs, tmLuminance(wbrmin), tmLuminance(wbrmax)));
129   }
130  
131   /* Apply false color mapping to pixel values */
# Line 154 | Line 150 | fcMapPixels(FCstruct *fcs, BYTE *ps, TMbright *ls, int
150                  *ps++ = fcs->scale[li][BLU];
151          }
152          returnOK;
153 + }
154 +
155 + /* Determine if false color mapping is logarithmic */
156 + int
157 + fcIsLogMap(FCstruct *fcs)
158 + {
159 +        int     midval;
160 +
161 +        if (fcs == NULL || fcs->lumap == NULL)
162 +                return(-1);
163 +        midval = fcs->lumap[(fcs->mbrmax - fcs->mbrmin)/2];
164 +        return((127 <= midval) & (midval <= 129));
165 + }
166 +
167 + /* Duplicate a false color structure */
168 + FCstruct *
169 + fcDup(FCstruct *fcs)
170 + {
171 +        FCstruct        *fcnew;
172 +
173 +        if (fcs == NULL)
174 +                return(NULL);
175 +        fcnew = fcInit(fcs->scale);
176 +        if (fcnew == NULL)
177 +                return(NULL);
178 +        if (fcs->lumap != NULL) {
179 +                fcnew->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax -
180 +                                                        fcs->mbrmin + 1));
181 +                if (fcnew->lumap == NULL)
182 +                        return(fcnew);
183 +                fcnew->mbrmin = fcs->mbrmin; fcnew->mbrmax = fcs->mbrmax;
184 +                memcpy((void *)fcnew->lumap, (void *)fcs->lumap,
185 +                                sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1));
186 +        }
187 +        return(fcnew);
188   }
189  
190   /* Free data associated with the given false color mapping structure */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines