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

Comparing ray/src/px/pcond4.c (file contents):
Revision 3.4 by greg, Fri Oct 4 17:51:41 1996 UTC vs.
Revision 3.8 by greg, Tue Oct 8 12:48:00 1996 UTC

# Line 126 | Line 126 | int    y;
126          register int    x, i;
127  
128          vy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
129 <        if (vy >= fvyr-1) vy--;
129 >        while (vy >= fvyr-1) vy--;
130          dy -= (double)vy;
131          for (x = 0; x < scanlen(&inpres); x++) {
132                  vx = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
133 <                if (vx >= fvxr-1) vx--;
133 >                while (vx >= fvxr-1) vx--;
134                  dx -= (double)vx;
135                  for (i = 0; i < 3; i++) {
136                          lv = (1.-dy)*colval(veilscan(vy)[vx],i) +
# Line 146 | Line 146 | int    y;
146  
147   /****************** ACUITY STUFF *******************/
148  
149 < typedef struct scanbar {
150 <        short   sampr;          /* sample area size (power of 2) */
149 > typedef struct {
150 >        short   sampe;          /* sample area size (exponent of 2) */
151          short   nscans;         /* number of scanlines in this bar */
152          int     len;            /* individual scanline length */
153        struct scanbar  *next;  /* next higher resolution scanbar */
153          int     nread;          /* number of scanlines loaded */
154 <                        /* followed by the scanline data */
154 >        COLOR   *sdata;         /* scanbar data */
155   } SCANBAR;
156  
157 < #define bscan(sb,y)     ((COLOR *)((sb)+1)+((y)%(sb)->nscans)*(sb)->len)
157 > #define bscan(sb,y)     ((COLOR *)(sb)->sdata+((y)%(sb)->nscans)*(sb)->len)
158  
159   SCANBAR *rootbar;               /* root scan bar (lowest resolution) */
160  
# Line 180 | Line 179 | double La;
179          };
180          double  l10La;
181          register int    i;
182 <                                        /* interpolate/extrapolate data */
182 >                                        /* check limits */
183 >        if (La <= 7.85e-4)
184 >                return(resfreq[0]);
185 >        if (La >= 1.78e3)
186 >                return(resfreq[NPOINTS-1]);
187 >                                        /* interpolate data */
188          l10La = log10(La);
189          for (i = 0; i < NPOINTS-2 && l10lum[i+1] <= l10La; i++)
190                  ;
# Line 199 | Line 203 | int    y;
203          register COLOR  *sl0, *sl1, *mysl;
204          register int    i;
205  
206 <        if (y < sb->nread - sb->nscans) {
207 <                fprintf(stderr, "%s: internal - cannot backspace in getascan\n",
204 <                                progname);
205 <                exit(1);
206 <        }
206 >        if (y < sb->nread - sb->nscans)                 /* too far back? */
207 >                return(NULL);
208          for ( ; y >= sb->nread; sb->nread++) {          /* read as necessary */
209                  mysl = bscan(sb, sb->nread);
210 <                if (sb->sampr == 1) {
210 >                if (sb->sampe == 0) {
211                          if (freadscan(mysl, sb->len, infp) < 0) {
212                                  fprintf(stderr, "%s: %s: scanline read error\n",
213                                                  progname, infn);
214                                  exit(1);
215                          }
216                  } else {
217 <                        sl0 = getascan(sb->next, 2*y);
218 <                        sl1 = getascan(sb->next, 2*y+1);
217 >                        sl0 = getascan(sb+1, 2*y);
218 >                        if (sl0 == NULL)
219 >                                return(NULL);
220 >                        sl1 = getascan(sb+1, 2*y+1);
221                          for (i = 0; i < sb->len; i++) {
222                                  copycolor(mysl[i], sl0[2*i]);
223                                  addcolor(mysl[i], sl0[2*i+1]);
# Line 263 | Line 266 | double sr;
266          double  d;
267          register SCANBAR        *sb0;
268  
269 <        for (sb0 = rootbar; sb0->next != NULL && sb0->next->sampr > sr;
267 <                        sb0 = sb0->next)
269 >        for (sb0 = rootbar; sb0->sampe != 0 && 1<<sb0[1].sampe > sr; sb0++)
270                  ;
271          ascanval(col, x, y, sb0);
272 <        if (sb0->next == NULL)          /* don't extrapolate highest */
272 >        if (sb0->sampe == 0)            /* don't extrapolate highest */
273                  return;
274 <        ascanval(c1, x, y, sb0->next);
275 <        d = (sb0->sampr - sr)/(sb0->sampr - sb0->next->sampr);
274 >        ascanval(c1, x, y, sb0+1);
275 >        d = ((1<<sb0->sampe) - sr)/(1<<sb0[1].sampe);
276          scalecolor(col, 1.-d);
277          scalecolor(c1, d);
278          addcolor(col, c1);
# Line 286 | Line 288 | SCANBAR        *sb;
288          double  dx, dy;
289          int     ix, iy;
290  
291 <        ix = dx = (x+.5)/sb->sampr - .5;
292 <        if (ix >= sb->len-1) ix--;
291 >        if (sb->sampe == 0) {           /* no need to interpolate */
292 >                sl0 = getascan(sb, y);
293 >                copycolor(col, sl0[x]);
294 >                return;
295 >        }
296 >                                        /* compute coordinates for sb */
297 >        ix = dx = (x+.5)/(1<<sb->sampe) - .5;
298 >        while (ix >= sb->len-1) ix--;
299          dx -= (double)ix;
300 <        iy = dy = (y+.5)/sb->sampr - .5;
301 <        if (iy >= numscans(&inpres)/sb->sampr-1) iy--;
300 >        iy = dy = (y+.5)/(1<<sb->sampe) - .5;
301 >        while (iy >= (numscans(&inpres)>>sb->sampe)-1) iy--;
302          dy -= (double)iy;
303                                          /* get scanlines */
304          sl0 = getascan(sb, iy);
305 +        if (sl0 == NULL) {
306 +                fprintf(stderr, "%s: internal - cannot backspace in ascanval\n",
307 +                                progname);
308 +                exit(1);
309 +        }
310          sl1 = getascan(sb, iy+1);
311                                          /* 2D linear interpolation */
312          copycolor(col, sl0[ix]);
# Line 318 | Line 331 | int    sr;             /* sampling rate */
331   int     ns;             /* number of scanlines */
332   int     sl;             /* original scanline length */
333   {
334 +        SCANBAR *sbarr;
335          register SCANBAR        *sb;
336  
337 <        sb = (SCANBAR *)malloc(sizeof(SCANBAR)+(sl/sr)*ns*sizeof(COLOR));
337 >        sbarr = sb = (SCANBAR *)malloc((sr+1)*sizeof(SCANBAR));
338          if (sb == NULL)
339                  syserror("malloc");
340 <        sb->nscans = ns;
341 <        sb->len = sl/sr;
342 <        sb->nread = 0;
343 <        if ((sb->sampr = sr) > 1)
344 <                sb->next = sballoc(sr/2, ns*2, sl);
345 <        else
346 <                sb->next = NULL;
347 <        return(sb);
340 >        do {
341 >                sb->sdata = (COLOR *)malloc((sl>>sr)*ns*sizeof(COLOR));
342 >                if (sb->sdata == NULL)
343 >                        syserror("malloc");
344 >                sb->sampe = sr;
345 >                sb->nscans = ns;
346 >                sb->len = sl>>sr;
347 >                sb->nread = 0;
348 >                ns <<= 1;
349 >                sb++;
350 >        } while (--sr >= 0);
351 >        return(sbarr);
352   }
353  
354  
# Line 374 | Line 392 | initacuity()                   /* initialize variable acuity sampling
392                  tsampr(y,fvxr-1) = tsampr(y,fvxr-2);
393          }
394                                          /* initialize with next power of two */
395 <        rootbar = sballoc(2<<(int)(log(maxsr)/log(2.)), 2, scanlen(&inpres));
395 >        rootbar = sballoc((int)(log(maxsr)/log(2.))+1, 2, scanlen(&inpres));
396   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines