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.7 by greg, Sat Oct 5 11:17:10 1996 UTC vs.
Revision 3.9 by greg, Thu Oct 10 16:36:39 1996 UTC

# 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 208 | Line 207 | int    y;
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);
217 >                        sl0 = getascan(sb+1, 2*y);
218                          if (sl0 == NULL)
219                                  return(NULL);
220 <                        sl1 = getascan(sb->next, 2*y+1);
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 242 | Line 241 | int    y;
241          register int    x;
242                                          /* compute foveal y position */
243          iy = dy = (y+.5)/numscans(&inpres)*fvyr - .5;
244 <        if (iy >= fvyr-1) iy--;
244 >        while (iy >= fvyr-1) iy--;
245          dy -= (double)iy;
246          for (x = 0; x < scanlen(&inpres); x++) {
247                                          /* compute foveal x position */
248                  ix = dx = (x+.5)/scanlen(&inpres)*fvxr - .5;
249 <                if (ix >= fvxr-1) ix--;
249 >                while (ix >= fvxr-1) ix--;
250                  dx -= (double)ix;
251                                          /* interpolate sample rate */
252                  sr = (1.-dy)*((1.-dx)*tsampr(ix,iy) + dx*tsampr(ix+1,iy)) +
# Line 267 | Line 266 | double sr;
266          double  d;
267          register SCANBAR        *sb0;
268  
269 <        for (sb0 = rootbar; sb0->next != NULL && sb0->next->sampr > sr;
271 <                        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 290 | Line 288 | SCANBAR        *sb;
288          double  dx, dy;
289          int     ix, iy;
290  
291 <        if (sb->sampr == 1) {           /* no need to interpolate */
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)/sb->sampr - .5;
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 <        while (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 + #ifdef DEBUG
306          if (sl0 == NULL) {
307                  fprintf(stderr, "%s: internal - cannot backspace in ascanval\n",
308                                  progname);
309 <                exit(1);
309 >                abort();
310          }
311 + #endif
312          sl1 = getascan(sb, iy+1);
313                                          /* 2D linear interpolation */
314          copycolor(col, sl0[ix]);
# Line 324 | Line 324 | SCANBAR        *sb;
324          scalecolor(col, 1.-dy);
325          scalecolor(c1y, dy);
326          addcolor(col, c1y);
327 +        for (ix = 0; ix < 3; ix++)      /* make sure no negative */
328 +                if (colval(col,ix) < 0.)
329 +                        colval(col,ix) = 0.;
330   }
331  
332  
333   SCANBAR *
334 < sballoc(sr, ns, sl)             /* allocate scanbar */
335 < int     sr;             /* sampling rate */
334 > sballoc(se, ns, sl)             /* allocate scanbar */
335 > int     se;             /* sampling rate exponent */
336   int     ns;             /* number of scanlines */
337   int     sl;             /* original scanline length */
338   {
339 +        SCANBAR *sbarr;
340          register SCANBAR        *sb;
341  
342 <        sb = (SCANBAR *)malloc(sizeof(SCANBAR)+(sl/sr)*ns*sizeof(COLOR));
342 >        sbarr = sb = (SCANBAR *)malloc((se+1)*sizeof(SCANBAR));
343          if (sb == NULL)
344                  syserror("malloc");
345 <        sb->nscans = ns;
346 <        sb->len = sl/sr;
347 <        sb->nread = 0;
348 <        if ((sb->sampr = sr) > 1)
349 <                sb->next = sballoc(sr/2, ns*2, sl);
350 <        else
351 <                sb->next = NULL;
352 <        return(sb);
345 >        do {
346 >                sb->sampe = se;
347 >                sb->len = sl>>se;
348 >                sb->nscans = ns;
349 >                sb->sdata = (COLOR *)malloc(sb->len*ns*sizeof(COLOR));
350 >                if (sb->sdata == NULL)
351 >                        syserror("malloc");
352 >                sb->nread = 0;
353 >                ns <<= 1;
354 >                sb++;
355 >        } while (--se >= 0);
356 >        return(sbarr);
357   }
358  
359  
# Line 385 | Line 393 | initacuity()                   /* initialize variable acuity sampling
393                  tsampr(x,fvyr-1) = tsampr(x,fvyr-2);
394          }
395          for (y = 0; y < fvyr; y++) {
396 <                tsampr(y,0) = tsampr(y,1);
397 <                tsampr(y,fvxr-1) = tsampr(y,fvxr-2);
396 >                tsampr(0,y) = tsampr(1,y);
397 >                tsampr(fvxr-1,y) = tsampr(fvxr-2,y);
398          }
399                                          /* initialize with next power of two */
400 <        rootbar = sballoc(2<<(int)(log(maxsr)/log(2.)), 2, scanlen(&inpres));
400 >        rootbar = sballoc((int)(log(maxsr)/log(2.))+1, 2, scanlen(&inpres));
401   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines