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.46 by greg, Wed Aug 22 17:49:54 2007 UTC vs.
Revision 2.66 by greg, Thu Sep 12 23:14:32 2024 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9   #include <stdio.h>
10   #include <signal.h>
11   #include <sys/types.h>
12 +
13 + #include "platform.h"
14   #ifndef NON_POSIX /* XXX need abstraction for process management */
15   #include <sys/wait.h>
16   #endif
17  
16 #include "platform.h"
18   #include "standard.h"
19   #include "color.h"
20   #include "view.h"
# Line 36 | Line 37 | main(
37   #ifndef NFS
38   #define  NFS                    1
39   #endif
40 <                                /* set the following to 0 to forgo forking */
40 >
41 > #ifndef RHAS_FORK_EXEC
42 > #undef MAXFORK
43 > #define MAXFORK                 0
44 > #endif
45   #ifndef MAXFORK
46   #if NFS
47   #define  MAXFORK                3       /* allotment of duped processes */
# Line 54 | Line 59 | main(
59   #define unguard()      
60   #endif
61  
57 extern char  *strerror();
58
62                                  /* rpict command */
63   char  *rpargv[128] = {"rpict", "-S", "1"};
64   int  rpargc = 3;
# Line 77 | Line 80 | int  nforked = 0;
80  
81   char  *progname;
82   int  verbose = 0;
83 + int  nowarn = 0;
84   unsigned  timelim = 0;
85   int  rvrlim = -1;
86  
# Line 99 | Line 103 | main(
103          char  *argv[]
104   )
105   {
106 <        register int  i, rval;
106 >        int  i, rval;
107          
108          progname = argv[0];
109          for (i = 1; i < argc; i++) {
# Line 107 | Line 111 | main(
111                  while ((rval = expandarg(&argc, &argv, i)) > 0)
112                          ;
113                  if (rval < 0) {
114 <                        fprintf(stderr, "%s: cannot expand '%s'",
114 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
115                                          argv[0], argv[i]);
116                          exit(1);
117                  }
118                  if (argv[i][0] == '-')
119                          switch (argv[i][1]) {
120 +                        case 'w':
121 +                                if (!argv[i][2])
122 +                                        nowarn = !nowarn;
123 +                                else if (argv[i][2] == '+')
124 +                                        nowarn = 0;
125 +                                else if (argv[i][2] == '-')
126 +                                        nowarn = 1;
127 +                                break;
128                          case 'v':
129                                  switch (argv[i][2]) {
130                                  case '\0':      /* verbose option */
# Line 135 | Line 147 | main(
147                                  }
148                                  break;
149                          case 'p':               /* pixel aspect ratio? */
150 +                                if (argv[i][2] == 'm') {
151 +                                        fprintf(stderr, "%s: -pm unsupported\n",
152 +                                                argv[0]);
153 +                                        ++i;
154 +                                        continue;
155 +                                }
156 +                                if (argv[i][2] == 'X') {
157 +                                        fprintf(stderr, "%s: -pXYZ unsupported\n",
158 +                                                argv[0]);
159 +                                        ++i;
160 +                                        continue;
161 +                                }
162 +                                if (argv[i][2] == 'c') {
163 +                                        fprintf(stderr, "%s: -pc unsupported\n",
164 +                                                argv[0]);
165 +                                        i += 9;
166 +                                        continue;
167 +                                }
168                                  if (argv[i][2] != 'a' || argv[i][3])
169                                          break;
170                                  pixaspect = atof(argv[++i]);
171                                  continue;
172 +                        case 'S':
173 +                                fprintf(stderr, "%s: -S unsupported\n", argv[0]);
174 +                                i++;
175 +                                continue;
176                          case 'T':               /* time limit (hours) */
177                                  if (argv[i][2])
178                                          break;
179                                  timelim = atof(argv[++i])*3600. + .5;
180 <                                break;
180 >                                continue;
181                          case 'x':               /* overall x resolution */
182                                  if (argv[i][2])
183                                          break;
# Line 188 | Line 222 | main(
222                                          break;
223                                  outfile = argv[++i];
224                                  continue;
225 <                        } else if (i >= argc-1)
226 <                                break;
225 >                        }
226 >                else if (i >= argc-1)
227 >                        break;
228                  rpargv[rpargc++] = argv[i];
229          }
230          if (i >= argc) {
# Line 218 | Line 253 | dolock(                /* lock or unlock a file */
253          if (fcntl(fd, F_SETLKW, &fls) < 0) {
254                  fprintf(stderr, "%s: cannot lock/unlock file: %s\n",
255                                  progname, strerror(errno));
256 <                exit(1);
256 >                _exit(1);
257          }
258   }
259  
# Line 246 | Line 281 | init(                  /* set up output file and start rpict */
281                  sflock(F_UNLCK);
282          }
283                                          /* compute piece size */
284 +        hr = hres; vr = vres;
285 +        if (pixaspect > FTINY)
286 +                normaspect(viewaspect(&ourview), &pixaspect, &hr, &vr);
287          hres /= hmult;
288          vres /= vmult;
289          if (hres <= 0 || vres <= 0) {
290 <                fprintf(stderr, "%s: illegal resolution/subdivision\n");
290 >                fprintf(stderr, "%s: illegal resolution/subdivision\n", progname);
291                  exit(1);
292          }
293          normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres);
294 +        if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult))
295 +                fprintf(stderr,
296 +                "%s: warning - changed resolution from %dx%d to %dx%d\n",
297 +                                progname, hr, vr, hres*hmult, vres*vmult);
298          sprintf(hrbuf, "%d", hres);
299          rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf;
300          sprintf(vrbuf, "%d", vres);
301          rpargv[rpargc++] = "-y"; rpargv[rpargc++] = vrbuf;
302          rpargv[rpargc++] = "-pa"; rpargv[rpargc++] = "0";
303 +        rpargv[rpargc++] = "-pm"; rpargv[rpargc++] = "0";
304          rpargv[rpargc++] = av[ac-1];
305          rpargv[rpargc] = NULL;
306                                          /* open output file */
# Line 268 | Line 311 | init(                  /* set up output file and start rpict */
311                  newheader("RADIANCE", fp);      /* create header */
312                  printargs(ac, av, fp);
313                  fprintf(fp, "SOFTWARE= %s\n", VersionID);
314 +                fprintf(fp, "TILED= %d %d\n", hmult, vmult);
315                  fputs(VIEWSTR, fp);
316                  fprintview(&ourview, fp);
317 <                putc('\n', fp);
317 >                fputc('\n', fp);
318 >                fputnow(fp);
319                  if (pixaspect < .99 || pixaspect > 1.01)
320                          fputaspect(pixaspect, fp);
321 +                fputprims(stdprims, fp);
322                  fputformat(COLRFMT, fp);
323 <                putc('\n', fp);
323 >                fputc('\n', fp);
324                  fprtresolu(hres*hmult, vres*vmult, fp);
325          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
326                  dolock(outfd, F_RDLCK);
# Line 297 | Line 343 | init(                  /* set up output file and start rpict */
343                  goto filerr;
344          dolock(outfd, F_UNLCK);
345                                          /* start rpict process */
346 +        rpd = sp_inactive;
347          if (open_process(&rpd, rpargv) <= 0) {
348                  fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
349                  exit(1);
# Line 367 | Line 414 | nextpiece(             /* get next piece assignment */
414  
415   static int
416   rvrpiece(               /* check for recoverable pieces */
417 <        register int    *xp,
418 <        register int    *yp
417 >        int     *xp,
418 >        int     *yp
419   )
420   {
421          static char  *pdone = NULL;     /* which pieces are done */
422          static long  readpos = -1;      /* how far we've read */
423 <        register int  i;
423 >        int  px, py, i;
424          /*
425           * This routine is called by nextpiece() with an
426           * exclusive lock on syncfp and the file pointer at the
# Line 382 | Line 429 | rvrpiece(              /* check for recoverable pieces */
429          if (rvrlim < 0)
430                  return(0);              /* only check if asked */
431          if (pdone == NULL)              /* first call */
432 <                pdone = calloc(hmult*vmult, sizeof(char));
432 >                pdone = (char *)calloc(hmult*vmult, sizeof(char));
433          if (pdone == NULL) {
434                  fprintf(stderr, "%s: out of memory\n", progname);
435                  exit(1);
436          }
437          if (readpos != -1)              /* mark what's been done */
438                  fseek(syncfp, readpos, 0);
439 <        while (fscanf(syncfp, "%d %d", xp, yp) == 2)
440 <                pdone[*xp*vmult+*yp] = 1;
439 >        while (fscanf(syncfp, "%d %d", &px, &py) == 2)
440 >                pdone[px*vmult+py] = 1;
441          if (!feof(syncfp)) {
442                  fprintf(stderr, "%s: format error in sync file\n", progname);
443                  exit(1);
# Line 431 | Line 478 | cleanup(                       /* close rpict process and clean up */
478   static void
479   rpiece(void)                    /* render picture piece by piece */
480   {
481 +        char  *err;
482          VIEW  pview;
483          int  xorg, yorg;
436                                        /* compute view parameters */
437        pview = ourview;
438        switch (ourview.type) {
439        case VT_PER:
440                pview.horiz = 2.*180./PI*atan(
441                                tan(PI/180./2.*ourview.horiz)/hmult );
442                pview.vert = 2.*180./PI*atan(
443                                tan(PI/180./2.*ourview.vert)/vmult );
444                break;
445        case VT_PAR:
446        case VT_ANG:
447                pview.horiz = ourview.horiz / hmult;
448                pview.vert = ourview.vert / vmult;
449                break;
450        case VT_CYL:
451                pview.horiz = ourview.horiz / hmult;
452                pview.vert = 2.*180./PI*atan(
453                                tan(PI/180./2.*ourview.vert)/vmult );
454                break;
455        case VT_HEM:
456                pview.horiz = 2.*180./PI*asin(
457                                sin(PI/180./2.*ourview.horiz)/hmult );
458                pview.vert = 2.*180./PI*asin(
459                                sin(PI/180./2.*ourview.vert)/vmult );
460                break;
461        default:
462                fprintf(stderr, "%s: unknown view type '-vt%c'\n",
463                                progname, ourview.type);
464                exit(cleanup(1));
465        }
484                                          /* render each piece */
485          while (nextpiece(&xorg, &yorg)) {
486 <                pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1);
487 <                pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1);
486 >                pview = ourview;
487 >                err = cropview(&pview, (double)xorg/hmult, (double)yorg/vmult,
488 >                                        (xorg+1.)/hmult, (yorg+1.)/vmult);
489 >                if (err != NULL) {
490 >                        fprintf(stderr, "%s: %s\n", progname, err);
491 >                        exit(cleanup(1));
492 >                }
493                  fputs(VIEWSTR, torp);
494                  fprintview(&pview, torp);
495 <                putc('\n', torp);
495 >                fputc('\n', torp);
496                  fflush(torp);                   /* assigns piece to rpict */
497                  putpiece(xorg, yorg);           /* place piece in output */
498          }
# Line 485 | Line 508 | int    ypos
508          struct flock  fls;
509          int  pid, status;
510          int  hr, vr;
511 <        register int  y;
511 >        int  y;
512                                  /* check bounds */
513          if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) {
514                  fprintf(stderr, "%s: requested piece (%d,%d) out of range\n",
# Line 536 | Line 559 | int    ypos
559                                  /* lock file section so NFS doesn't mess up */
560          fls.l_whence = 0;
561          fls.l_type = F_WRLCK;
562 + #if 0
563          if (fcntl(outfd, F_SETLKW, &fls) < 0)
564                  filerr("lock");
565 + #else
566 +        dolock(outfd, F_WRLCK);
567   #endif
568 + #endif
569                                  /* write new piece to file */
570          if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0)
571                  filerr("seek");
572          if (hmult == 1) {
573 <                if (writebuf(outfd, (char *)pbuf,
573 >                if (writebuf(outfd, pbuf,
574                                  vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR))
575                          filerr("write");
576          } else
577                  for (y = 0; y < vr; y++) {
578 <                        if (writebuf(outfd, (char *)(pbuf+y*hr),
578 >                        if (writebuf(outfd, pbuf+y*hr,
579                                          hr*sizeof(COLR)) != hr*sizeof(COLR))
580                                  filerr("write");
581                          if (y < vr-1 && lseek(outfd,
# Line 558 | Line 585 | int    ypos
585                  }
586   #if NFS
587          fls.l_type = F_UNLCK;           /* release lock */
588 + #if 0
589          if (fcntl(outfd, F_SETLKW, &fls) < 0)
590                  filerr("lock");
591 + #else
592 +        dolock(outfd, F_UNLCK);
593 + #endif
594   #endif
595          if (verbose) {                          /* notify caller */
596                  printf("%d %d done\n", xpos, ypos);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines