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

Comparing ray/src/util/rpiece.c (file contents):
Revision 2.9 by greg, Sun Aug 9 13:31:30 1992 UTC vs.
Revision 2.15 by greg, Thu Jan 21 17:46:31 1993 UTC

# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include "view.h"
16   #include "resolu.h"
17  
18 + #ifndef NFS
19 + #define  NFS                    1
20 + #endif
21                                  /* set the following to 0 to forgo forking */
22   #ifndef MAXFORK
23 < #define  MAXFORK                2       /* max. unreaped child processes */
23 > #if NFS
24 > #define  MAXFORK                3       /* allotment of duped processes */
25 > #else
26 > #define  MAXFORK                0
27   #endif
28 + #endif
29  
30                                  /* rpict command */
31   char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"};
# Line 102 | Line 109 | char  *argv[];
109                          case 'F':               /* syncronization file */
110                                  if (argv[i][2])
111                                          break;
112 <                                if ((syncfd = open(argv[++i], O_RDWR)) < 0) {
112 >                                if ((syncfd = open(argv[++i],
113 >                                                O_RDWR|O_CREAT, 0666)) < 0) {
114                                          fprintf(stderr, "%s: cannot open\n",
115                                                          argv[i]);
116                                          exit(1);
117                                  }
118                                  continue;
119 +                        case 'z':               /* z-file ist verbotten */
120 +                                fprintf(stderr, "%s: -z option not allowed\n",
121 +                                                argv[0]);
122 +                                exit(1);
123                          case 'o':               /* output file */
124                                  if (argv[i][2])
125                                          break;
# Line 123 | Line 135 | char  *argv[];
135          }
136          init(argc, argv);
137          rpiece();
138 <        rval = cleanup();
127 <        exit(rval);
138 >        exit(cleanup(0));
139   }
140  
141  
# Line 164 | Line 175 | char  **av;
175          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
176                  if ((fp = fdopen(dup(outfd), "r+")) == NULL)
177                          goto filerr;
178 <                getheader(fp, NULL);            /* skip header */
179 <                if (fscnresolu(&hr, &vr, fp) < 0 ||     /* check resolution */
178 >                getheader(fp, NULL, NULL);      /* skip header */
179 >                if (!fscnresolu(&hr, &vr, fp) ||        /* check resolution */
180                                  hr != hres*hmult || vr != vres*vmult) {
181                          fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n",
182                                          progname, outfile);
# Line 179 | Line 190 | char  **av;
190          scanorig = ftell(fp);           /* record position of first scanline */
191          if (fclose(fp) == -1)           /* done with stream i/o */
192                  goto filerr;
193 + #if NFS
194          sync();                         /* flush NFS buffers */
195 + #endif
196                                          /* start rpict process */
197          if (open_process(rpd, rpargv) <= 0) {
198                  fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
# Line 244 | Line 257 | int  *xp, *yp;
257          if (sscanf(buf, "%d %d", xp, yp) == 2)
258                  return(1);
259          fprintf(stderr, "%s: input format error\n", progname);
260 <        exit(1);
260 >        exit(cleanup(1));
261   }
262  
263  
264   int
265 < cleanup()                       /* close rpict process and clean up */
265 > cleanup(rstat)                  /* close rpict process and clean up */
266 > int  rstat;
267   {
268 <        register int  pid;
255 <        int  status, rstat = 0;
268 >        int  status;
269  
270          free((char *)pbuf);
271          fclose(torp);
272          fclose(fromrp);
273 <        while ((pid = wait(&status)) != -1)
273 >        while (wait(&status) != -1)
274                  if (rstat == 0)
275                          rstat = status>>8 & 0xff;
276          return(rstat);
# Line 268 | Line 281 | rpiece()                       /* render picture piece by piece */
281   {
282          VIEW  pview;
283          int  xorg, yorg;
284 <        
284 >                                        /* compute view parameters */
285 >        copystruct(&pview, &ourview);
286 >        switch (ourview.type) {
287 >        case VT_PER:
288 >                pview.horiz = 2.*180./PI*atan(
289 >                                tan(PI/180./2.*ourview.horiz)/hmult );
290 >                pview.vert = 2.*180./PI*atan(
291 >                                tan(PI/180./2.*ourview.vert)/vmult );
292 >                break;
293 >        case VT_PAR:
294 >        case VT_ANG:
295 >                pview.horiz = ourview.horiz / hmult;
296 >                pview.vert = ourview.vert / vmult;
297 >                break;
298 >        case VT_HEM:
299 >                pview.horiz = 2.*180./PI*asin(
300 >                                sin(PI/180./2.*ourview.horiz)/hmult );
301 >                pview.vert = 2.*180./PI*asin(
302 >                                sin(PI/180./2.*ourview.vert)/vmult );
303 >                break;
304 >        default:
305 >                fprintf(stderr, "%s: unknown view type '-vt%c'\n",
306 >                                progname, ourview.type);
307 >                exit(cleanup(1));
308 >        }
309 >                                        /* render each piece */
310          while (nextpiece(&xorg, &yorg)) {
311 <                copystruct(&pview, &ourview);   /* compute view for piece */
312 <                switch (ourview.type) {
275 <                case VT_PER:
276 <                        pview.horiz = 2.*180./PI*atan(
277 <                                        tan(PI/180./2.*ourview.horiz)/hmult );
278 <                        pview.vert = 2.*180./PI*atan(
279 <                                        tan(PI/180./2.*ourview.vert)/vmult );
280 <                        break;
281 <                case VT_PAR:
282 <                case VT_ANG:
283 <                        pview.horiz = ourview.horiz / hmult;
284 <                        pview.vert = ourview.vert / vmult;
285 <                        break;
286 <                case VT_HEM:
287 <                        pview.horiz = 2.*180./PI*asin(
288 <                                        sin(PI/180./2.*ourview.horiz)/hmult );
289 <                        pview.vert = 2.*180./PI*asin(
290 <                                        sin(PI/180./2.*ourview.vert)/vmult );
291 <                        break;
292 <                default:
293 <                        fprintf(stderr, "%s: unknown view type '-vt%c'\n",
294 <                                        progname, ourview.type);
295 <                        exit(1);
296 <                }
297 <                pview.hoff += xorg - 0.5*(hmult-1);
298 <                pview.voff += yorg - 0.5*(vmult-1);
311 >                pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1);
312 >                pview.voff = ourview.voff + yorg - 0.5*(vmult-1);
313                  fputs(VIEWSTR, torp);
314                  fprintview(&pview, torp);
315                  putc('\n', torp);
316 <                fflush(torp);                   /* assign piece to rpict */
316 >                fflush(torp);                   /* assigns piece to rpict */
317                  putpiece(xorg, yorg);           /* place piece in output */
318                  if (verbose) {                  /* notify caller */
319                          printf("%d %d done\n", xorg, yorg);
# Line 321 | Line 335 | int  xpos, ypos;
335          if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) {
336                  fprintf(stderr, "%s: requested piece (%d,%d) out of range\n",
337                                  progname, xpos, ypos);
338 <                exit(1);
338 >                exit(cleanup(1));
339          }
340                                  /* check header from rpict */
341 <        getheader(fromrp, NULL);
342 <        if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres || vr != vres) {
341 >        getheader(fromrp, NULL, NULL);
342 >        if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) {
343                  fprintf(stderr, "%s: resolution mismatch from %s\n",
344                                  progname, rpargv[0]);
345 <                exit(1);
345 >                exit(cleanup(1));
346          }
347                                  /* load new piece into buffer */
348          for (y = 0; y < vr; y++)
349                  if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) {
350                          fprintf(stderr, "%s: read error from %s\n",
351                                          progname, rpargv[0]);
352 <                        exit(1);
352 >                        exit(cleanup(1));
353                  }
354   #if MAXFORK
355                                  /* fork so we don't slow rpict down */
356          if ((pid = fork()) > 0) {
357 <                if (++nforked > MAXFORK) {
357 >                if (++nforked >= MAXFORK) {
358                          wait(&status);          /* reap a child */
359                          if (status)
360 <                                exit(status>>8 & 0xff);
360 >                                exit(cleanup(status>>8 & 0xff));
361                          nforked--;
362                  }
363                  return(pid);
# Line 351 | Line 365 | int  xpos, ypos;
365   #else
366          pid = -1;               /* no forking */
367   #endif
354                                /* lock file section so NFS doesn't mess up */
355        fls.l_whence = 0;
368          fls.l_len = (long)vres*hmult*hres*sizeof(COLR);
369          fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len;
370 + #if NFS
371 +                                /* lock file section so NFS doesn't mess up */
372 +        fls.l_whence = 0;
373          fls.l_type = F_WRLCK;
374          fcntl(outfd, F_SETLKW, &fls);
375 + #endif
376                                  /* write new piece to file */
377          if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1)
378                  goto seekerr;
# Line 375 | Line 391 | int  xpos, ypos;
391                                  goto seekerr;
392                  }
393          if (pid == -1) {        /* fork failed */
394 + #if NFS
395                  fls.l_type = F_UNLCK;           /* release lock */
396                  fcntl(outfd, F_SETLKW, &fls);
397 + #endif
398                  return(0);
399          }
400          _exit(0);               /* else exit child process (releasing lock) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines