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

Comparing ray/src/px/pcond3.c (file contents):
Revision 3.2 by greg, Thu Oct 10 17:09:26 1996 UTC vs.
Revision 3.5 by greg, Thu Jan 9 13:56:30 1997 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   #include "pcond.h"
12  
13  
14 < #define CVRATIO         0.025           /* fraction of pixels allowed > env. */
14 > #define CVRATIO         0.025           /* fraction of samples allowed > env. */
15  
16 #define BotMesopic      5.62e-3         /* top of scotopic range */
17 #define TopMesopic      5.62            /* bottom of photopic range */
18
16   #define exp10(x)        exp(2.302585093*(x))
17  
18 < int     modhist[HISTRES];               /* modified histogram */
18 > float   modhist[HISTRES];               /* modified histogram */
19 > double  mhistot;                        /* modified histogram total */
20   float   cumf[HISTRES+1];                /* cumulative distribution function */
21  
22  
23   mkcumf()                        /* make cumulative distribution function */
24   {
25          register int    i;
26 <        register long   sum;
26 >        register double sum;
27  
28 <        cumf[0] = 0.;
29 <        sum = modhist[0];
30 <        for (i = 1; i < HISTRES; i++) {
31 <                cumf[i] = (double)sum/histot;
28 >        mhistot = 0.;           /* compute modified total */
29 >        for (i = 0; i < HISTRES; i++)
30 >                mhistot += modhist[i];
31 >
32 >        sum = 0.;               /* compute cumulative function */
33 >        for (i = 0; i < HISTRES; i++) {
34 >                cumf[i] = sum/mhistot;
35                  sum += modhist[i];
36          }
37          cumf[HISTRES] = 1.;
# Line 60 | Line 61 | double Lw;
61                  return(Bldmin);
62          if (b >= bwmax-FTINY)
63                  return(Bldmax);
64 <        return(Bldmin + cf(Bl(Lw))*(Bldmax-Bldmin));
64 >        return(Bldmin + cf(b)*(Bldmax-Bldmin));
65   }
66  
67  
# Line 111 | Line 112 | double bw;
112   int
113   mkbrmap()                       /* make dynamic range map */
114   {
114        int     hdiffs[HISTRES], above, below;
115          double  T, b, s;
116 <        int     maxd, maxi, sd;
116 >        double  ceiling, trimmings;
117          register int    i;
118                                          /* copy initial histogram */
119 <        for (i = 0; i < HISTRES; i++)
120 <                modhist[i] = bwhist[i];
121 <        T = histot * (bwmax - bwmin) / HISTRES;
119 >        bcopy((char *)bwhist, (char *)modhist, sizeof(modhist));
120          s = (bwmax - bwmin)/HISTRES;
121                                          /* loop until satisfactory */
122 <        for ( ; ; ) {
123 <                mkcumf();               /* sync brightness mapping */
124 <                above = below = 0;      /* compute visibility overflow */
122 >        do {
123 >                mkcumf();                       /* sync brightness mapping */
124 >                if (mhistot <= histot*CVRATIO)
125 >                        return(-1);             /* no compression needed! */
126 >                T = mhistot * (bwmax - bwmin) / HISTRES;
127 >                trimmings = 0.;                 /* clip to envelope */
128                  for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s) {
129 <                        hdiffs[i] = modhist[i] - (int)(T*clampf(Lb(b)) + .5);
130 <                        if (hdiffs[i] > 0) above += hdiffs[i];
131 <                        else below -= hdiffs[i];
129 >                        ceiling = T*clampf(Lb(b));
130 >                        if (modhist[i] > ceiling) {
131 >                                trimmings += modhist[i] - ceiling;
132 >                                modhist[i] = ceiling;
133 >                        }
134                  }
135 <                if (above <= histot*CVRATIO)
136 <                        break;          /* close enough */
137 <                if (above-below >= 0)
135 <                        return(-1);     /* Houston, we have a problem.... */
136 <                /* original looped here as well (BEGIN_L2) */
137 <                maxd = 0;               /* find largest overvis */
138 <                for (i = 0; i < HISTRES; i++)
139 <                        if (hdiffs[i] > maxd)
140 <                                maxd = hdiffs[maxi=i];
141 <                /* broke loop here when (maxd == 0) (BREAK_L2) */
142 <                for (sd = shiftdir((maxi+.5)/HISTRES*(bwmax-bwmin)+bwmin);
143 <                                hdiffs[maxi] == maxd; sd = -sd)
144 <                        for (i = maxi+sd; i >= 0 & i < HISTRES; i += sd)
145 <                                if (hdiffs[i] < 0) {
146 <                                        if (hdiffs[i] <= -maxd) {
147 <                                                modhist[i] += maxd;
148 <                                                modhist[maxi] -= maxd;
149 <                                                hdiffs[i] += maxd;
150 <                                                hdiffs[maxi] = 0;
151 <                                        } else {
152 <                                                modhist[maxi] += hdiffs[i];
153 <                                                modhist[i] -= hdiffs[i];
154 <                                                hdiffs[maxi] += hdiffs[i];
155 <                                                hdiffs[i] = 0;
156 <                                        }
157 <                                        break;
158 <                                }
159 <                /* (END_L2) */
160 <        }
161 <        return(0);
135 >        } while (trimmings > histot*CVRATIO);
136 >
137 >        return(0);                      /* we got it */
138   }
139  
140  
# Line 214 | Line 190 | int    xres;
190   }
191  
192  
193 < #ifdef DEBUG
194 < doplots()                       /* generate debugging plots */
193 > putmapping(fp)                  /* put out mapping function */
194 > FILE    *fp;
195   {
196 <        double  T, b, s;
221 <        FILE    *fp;
222 <        char    fname[128];
196 >        double  b, s;
197          register int    i;
198 +        double  wlum, sf;
199  
200 <        T = histot * (bwmax - bwmin) / HISTRES;
200 >        sf = scalef*inpexp;
201 >        if (lumf == cielum) sf *= WHTEFFICACY;
202          s = (bwmax - bwmin)/HISTRES;
203 <
204 <        sprintf(fname, "%s_hist.plt", infn);
205 <        if ((fp = fopen(fname, "w")) == NULL)
206 <                syserror(fname);
207 <        fputs("include=curve.plt\n", fp);
208 <        fputs("title=\"Brightness Frequency Distribution\"\n", fp);
209 <        fprintf(fp, "subtitle=%s\n", infn);
234 <        fputs("ymin=0\n", fp);
235 <        fputs("xlabel=\"Perceptual Brightness B(Lw)\"\n", fp);
236 <        fputs("ylabel=\"Frequency Count\"\n", fp);
237 <        fputs("Alabel=\"Histogram\"\n", fp);
238 <        fputs("Alintype=0\n", fp);
239 <        fputs("Blabel=\"Envelope\"\n", fp);
240 <        fputs("Bsymsize=0\n", fp);
241 <        fputs("Adata=\n", fp);
242 <        for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s)
243 <                fprintf(fp, "\t%f %d\n", b, modhist[i]);
244 <        fputs(";\nBdata=\n", fp);
245 <        for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s)
246 <                fprintf(fp, "\t%f %f\n", b, T*clampf(Lb(b)));
247 <        fputs(";\n", fp);
248 <        fclose(fp);
203 >        for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s) {
204 >                wlum = Lb(b);
205 >                if (what2do&DO_LINEAR)
206 >                        fprintf(fp, "%e %e\n", wlum, sf*wlum);
207 >                else
208 >                        fprintf(fp, "%e %e\n", wlum, Lb(BLw(wlum)));
209 >        }
210   }
250 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines