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

Comparing ray/src/util/glareval.c (file contents):
Revision 1.2 by greg, Mon Mar 18 14:33:53 1991 UTC vs.
Revision 1.5 by greg, Thu Mar 21 12:28:23 1991 UTC

# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20   #define vfork           fork
21   #endif
22  
23 < #define NSCANS          32              /* number of scanlines to buffer */
23 > #define NSCANS          64              /* number of scanlines to buffer */
24  
25   int     rt_pid = -1;            /* process id for rtrace */
26   int     fd_tort, fd_fromrt;     /* pipe descriptors */
# Line 39 | Line 39 | struct {
39   static long     ncall = 0L;     /* number of calls to getpictscan */
40   static long     nread = 0L;     /* number of scanlines read */
41  
42 + extern long     ftell();
43  
44 +
45   COLR *
46   getpictscan(y)                  /* get picture scanline */
47   int     y;
48   {
47        extern long     ftell();
49          int     minused;
50          register int    i;
51                                          /* first check our buffers */
# Line 59 | Line 60 | int    y;
60                          minused = i;
61          }
62                                          /* not there, read it in */
63 <        if (scanpos[y] == -1) {                 /* need to search */
64 <                while (curpos > y) {
63 >        if (scanpos[y] < 0) {                   /* need to search */
64 >                for (i = y+1; i < curpos; i++)
65 >                        if (scanpos[i] >= 0) {
66 >                                if (fseek(pictfp, scanpos[i], 0) < 0)
67 >                                        goto seekerr;
68 >                                curpos = i;
69 >                                break;
70 >                        }
71 >                while (curpos >= y) {
72                          scanpos[curpos] = ftell(pictfp);
73                          if (freadcolrs(scan[minused].sl, pxsiz, pictfp) < 0)
74                                  goto readerr;
75 +                        nread++;
76                          curpos--;
77                  }
78 <        } else if (fseek(pictfp, scanpos[y], 0) < 0) {
79 <                fprintf(stderr, "%s: picture seek error\n", progname);
80 <                exit(1);
78 >        } else {
79 >                if (curpos != y && fseek(pictfp, scanpos[y], 0) < 0)
80 >                        goto seekerr;
81 >                if (freadcolrs(scan[minused].sl, pxsiz, pictfp) < 0)
82 >                        goto readerr;
83 >                nread++;
84 >                curpos = y-1;
85          }
73        if (freadcolrs(scan[minused].sl, pxsiz, pictfp) < 0)
74                goto readerr;
75        nread++;
76        curpos = y-1;
86          scan[minused].lused = ncall;
87          scan[minused].y = y;
88          return(scan[minused].sl);
89   readerr:
90          fprintf(stderr, "%s: picture read error\n", progname);
91          exit(1);
92 + seekerr:
93 +        fprintf(stderr, "%s: picture seek error\n", progname);
94 +        exit(1);
95   }
96  
97  
# Line 149 | Line 161 | int    vv;
161   float   *vb;
162   {
163          float   rt_buf[6*MAXPIX];       /* rtrace send/receive buffer */
164 <        int     npix_tort;              /* number of pixels in buffer */
164 >        register int    n;              /* number of pixels in buffer */
165          short   buf_vh[MAXPIX];         /* pixel positions */
166          FVECT   dir;
167          register int    vh;
156        register int    i;
168  
169 + #ifdef DEBUG
170          if (verbose)
171                  fprintf(stderr, "%s: computing view span at %d...\n",
172                                  progname, vv);
173 <        npix_tort = 0;
173 > #endif
174 >        n = 0;
175          for (vh = -hsize; vh <= hsize; vh++) {
176                  if (compdir(dir, vh, vv) < 0) { /* off viewable region */
177                          vb[vh+hsize] = -1.0;
# Line 169 | Line 182 | float  *vb;
182                  if (rt_pid == -1)               /* missing information */
183                          continue;
184                                                  /* send to rtrace */
185 <                if (npix_tort >= MAXPIX) {              /* flush */
186 <                        rt_compute(rt_buf, npix_tort);
187 <                        for (i = 0; i < npix_tort; i++)
188 <                                vb[buf_vh[i]+hsize] = luminance(rt_buf+3*i);
176 <                        npix_tort = 0;
185 >                if (n >= MAXPIX) {                      /* flush */
186 >                        rt_compute(rt_buf, n);
187 >                        while (n-- > 0)
188 >                                vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
189                  }
190 <                rt_buf[6*npix_tort] = ourview.vp[0];
191 <                rt_buf[6*npix_tort+1] = ourview.vp[1];
192 <                rt_buf[6*npix_tort+2] = ourview.vp[2];
193 <                rt_buf[6*npix_tort+3] = dir[0];
194 <                rt_buf[6*npix_tort+4] = dir[1];
195 <                rt_buf[6*npix_tort+5] = dir[2];
196 <                buf_vh[npix_tort++] = vh;
190 >                rt_buf[6*n] = ourview.vp[0];
191 >                rt_buf[6*n+1] = ourview.vp[1];
192 >                rt_buf[6*n+2] = ourview.vp[2];
193 >                rt_buf[6*n+3] = dir[0];
194 >                rt_buf[6*n+4] = dir[1];
195 >                rt_buf[6*n+5] = dir[2];
196 >                buf_vh[n++] = vh;
197          }
198 <        if (npix_tort > 0) {                    /* process pending buffer */
187 <                rt_compute(rt_buf, npix_tort);
188 <                for (i = 0; i < npix_tort; i++)
189 <                        vb[buf_vh[i]+hsize] = luminance(rt_buf+3*i);
190 <        }
198 > #ifdef DEBUG
199          if (verbose)
200                  pict_stats();
201 + #endif
202 +        if (n > 0) {                            /* process pending buffer */
203 +                rt_compute(rt_buf, n);
204 +                while (n-- > 0)
205 +                        vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
206 +        }
207   }
208  
209  
# Line 199 | Line 213 | int    np;
213   {
214          static float    nbuf[6] = {0.,0.,0.,0.,0.,0.};
215  
216 + #ifdef DEBUG
217          if (verbose && np > 1)
218                  fprintf(stderr, "%s: sending %d samples to rtrace...\n",
219                                  progname, np);
220 + #endif
221          if (writebuf(fd_tort,(char *)pb,6*sizeof(float)*np) < 6*sizeof(float)*np
222                  || writebuf(fd_tort,(char *)nbuf,sizeof(nbuf)) < sizeof(nbuf)) {
223                  fprintf(stderr, "%s: error writing to rtrace process\n",
# Line 243 | Line 259 | char   *fn;
259          scanpos = (long *)malloc(pysiz*sizeof(long));
260          if (scanpos == NULL)
261                  memerr("scanline positions");
262 <        for (i = 0; i < pysiz; i++)
262 >        for (i = pysiz-1; i >= 0; i--)
263                  scanpos[i] = -1L;
264 +        curpos = pysiz-1;
265          for (i = 0; i < NSCANS; i++) {
266                  scan[i].lused = -1;
267                  scan[i].y = -1;
# Line 252 | Line 269 | char   *fn;
269                  if (scan[i].sl == NULL)
270                          memerr("scanline buffers");
271          }
255        curpos = pysiz-1;
272   }
273  
274  
# Line 298 | Line 314 | char   *av[];
314                  perror(progname);
315                  exit(1);
316          }
317 +        close(p0[0]);
318 +        close(p1[1]);
319          fd_tort = p0[1];
320          fd_fromrt = p1[0];
321   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines