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

Comparing ray/src/px/pf3.c (file contents):
Revision 2.18 by schorsch, Sun Mar 28 20:33:14 2004 UTC vs.
Revision 2.21 by greg, Fri Dec 8 17:56:26 2023 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7   *     8/13/86
8   */
9  
10 #include  "standard.h"
11
12 #include  <string.h>
13
14 #include  "color.h"
10   #include  "pfilt.h"
11  
12   #define  RSCA           1.13    /* square-radius multiplier: sqrt(4/PI) */
# Line 25 | Line 20 | short  *ringwt;                        /* weight (count) of ring values */
20   short  *ringndx;                /* ring index table */
21   float  *warr;                   /* array of pixel weights */
22  
23 < #define  lookgauss(x)           gausstable[(int)(10.*(x)+.5)]
23 > #define  lookgauss(x)           gausstable[(int)(20.*(x)+.5)]
24  
25   static double pickfilt(double  p0);
26   static void sumans(int  px, int  py, int  rcent, int  ccent, double  m);
27  
28  
29 < extern void
29 > void
30   initmask(void)                  /* initialize gaussian lookup table */
31   {
32          int  gtabsiz;
33          double  gaussN;
34          double  d;
35 <        register int  x;
35 >        int  x;
36  
37 <        gtabsiz = 111*CHECKRAD*CHECKRAD;
37 >        gtabsiz = 444*CHECKRAD*CHECKRAD;
38          gausstable = (float *)malloc(gtabsiz*sizeof(float));
39          if (gausstable == NULL)
40                  goto memerr;
41          d = x_c*y_r*0.25/(rad*rad);
42          gausstable[0] = exp(-d);
43          for (x = 1; x < gtabsiz; x++)
44 <                if (x*0.1 <= d)
44 >                if (x*0.05 <= d)
45                          gausstable[x] = gausstable[0];
46                  else
47 <                        gausstable[x] = exp(-x*0.1);
47 >                        gausstable[x] = exp(-x*0.05);
48          if (obarsize == 0)
49                  return;
50                                          /* compute integral of filter */
# Line 81 | Line 76 | memerr:
76   }
77  
78  
79 < extern void
79 > void
80   dobox(                  /* simple box filter */
81 <        COLOR  csum,
81 >        SCOLOR  csum,
82          int  xcent,
83          int  ycent,
84          int  c,
# Line 93 | Line 88 | dobox(                 /* simple box filter */
88          int  wsum;
89          double  d;
90          int  y;
91 <        register int  x, offs;
92 <        register COLOR  *scan;
91 >        int  x, offs;
92 >        COLORV  *scan, *scp;
93          
94          wsum = 0;
95 <        setcolor(csum, 0.0, 0.0, 0.0);
95 >        scolorblack(csum);
96          for (y = ycent+1-ybrad; y <= ycent+ybrad; y++) {
97                  if (y < 0) continue;
98                  if (y >= yres) break;
# Line 113 | Line 108 | dobox(                 /* simple box filter */
108                          if (d < -0.5) continue;
109                          if (d >= 0.5) break;
110                          wsum++;
111 <                        addcolor(csum, scan[x+offs]);
111 >                        scp = scan + (x+offs)*NCSAMP;
112 >                        saddscolor(csum, scp);
113                  }
114          }
115          if (wsum > 1) {
116                  d = 1.0/wsum;
117 <                scalecolor(csum, d);
117 >                scalescolor(csum, d);
118          }
119   }
120  
121  
122 < extern void
122 > void
123   dogauss(                /* gaussian filter */
124 <        COLOR  csum,
124 >        SCOLOR  csum,
125          int  xcent,
126          int  ycent,
127          int  c,
# Line 133 | Line 129 | dogauss(               /* gaussian filter */
129   )
130   {
131          double  dy, dx, weight, wsum;
132 <        COLOR  ctmp;
132 >        SCOLOR  ctmp;
133          int  y;
134 <        register int  x, offs;
135 <        register COLOR  *scan;
134 >        int  x, offs;
135 >        COLORV  *scan;
136  
137          wsum = FTINY;
138 <        setcolor(csum, 0.0, 0.0, 0.0);
138 >        scolorblack(csum);
139          for (y = ycent-yrad; y <= ycent+yrad; y++) {
140                  if (y < 0) continue;
141                  if (y >= yres) break;
# Line 152 | Line 148 | dogauss(               /* gaussian filter */
148                          dx = (x_c*(x+.5) - (c+.5))/rad;
149                          weight = lookgauss(dx*dx + dy*dy);
150                          wsum += weight;
151 <                        copycolor(ctmp, scan[x+offs]);
152 <                        scalecolor(ctmp, weight);
153 <                        addcolor(csum, ctmp);
151 >                        copyscolor(ctmp, scan+(x+offs)*NCSAMP);
152 >                        scalescolor(ctmp, weight);
153 >                        saddscolor(csum, ctmp);
154                  }
155          }
156          weight = 1.0/wsum;
157 <        scalecolor(csum, weight);
157 >        scalescolor(csum, weight);
158   }
159  
160  
161 < extern void
161 > void
162   dothresh(       /* gaussian threshold filter */
163          int  xcent,
164          int  ycent,
# Line 172 | Line 168 | dothresh(      /* gaussian threshold filter */
168   {
169          double  d;
170          int  r, y, offs;
171 <        register int  c, x;
172 <        register float  *gscan;
171 >        int  c, x;
172 >        float  *gscan;
173                                          /* compute ring sums */
174          memset((char *)ringsum, '\0', (orad+1)*sizeof(float));
175          memset((char *)ringwt, '\0', (orad+1)*sizeof(short));
# Line 207 | Line 203 | dothresh(      /* gaussian threshold filter */
203                          if (d < -0.5) continue;
204                          if (d >= 0.5) break;
205                          sumans(x, y, rcent, ccent,
206 <                        pickfilt((*ourbright)(scanin[y%barsize][x+offs])));
206 >                        pickfilt((*ourbright)(scanin[y%barsize]+(x+offs)*NCSAMP)));
207                  }
208          }
209   }
# Line 222 | Line 218 | pickfilt(                      /* find filter multiplier for p0 */
218          double  t, num, denom, avg, wsum;
219          double  mlimit[2];
220          int  ilimit = 4.0/TEPS;
221 <        register int  i;
221 >        int  i;
222                                  /* iterative search for m */
223          mlimit[0] = 1.0; mlimit[1] = orad/rad/CHECKRAD;
224          do {
# Line 284 | Line 280 | sumans(                /* sum input pixel to output */
280   )
281   {
282          double  dy2, dx;
283 <        COLOR  pval, ctmp;
283 >        SCOLOR  pval, ctmp;
284          int  ksiz, r, offs;
285          double  pc, pr, norm;
286 <        register int  i, c;
287 <        register COLOR  *scan;
286 >        int  i, c;
287 >        COLORV  *scan, *scp;
288          /*
289           * This normalization method fails at the picture borders because
290           * a different number of input pixels contribute there.
291           */
292 <        scan = scanin[py%barsize] + (px < 0 ? xres : px >= xres ? -xres : 0);
293 <        copycolor(pval, scan[px]);
292 >        scan = scanin[py%barsize] + (px < 0 ? xres : px >= xres ? -xres : 0)*NCSAMP;
293 >        copyscolor(pval, scan+px*NCSAMP);
294          pc = x_c*(px+.5);
295          pr = y_r*(py+.5);
296          ksiz = CHECKRAD*m*rad + 1;
# Line 327 | Line 323 | sumans(                /* sum input pixel to output */
323                  scan = scoutbar[r%obarsize];
324                  for (c = ccent-ksiz; c <= ccent+ksiz; c++) {
325                          offs = c < 0 ? ncols : c >= ncols ? -ncols : 0;
326 <                        if (offs && !wrapfilt)
326 >                        if ((offs != 0) & !wrapfilt)
327                                  continue;
328 <                        copycolor(ctmp, pval);
328 >                        copyscolor(ctmp, pval);
329                          dx = norm*warr[i++];
330 <                        scalecolor(ctmp, dx);
331 <                        addcolor(scan[c+offs], ctmp);
330 >                        scalescolor(ctmp, dx);
331 >                        scp = scan + (c+offs)*NCSAMP;
332 >                        saddscolor(scp, ctmp);
333                  }
334          }
335   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines