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.54 by greg, Fri Jun 1 22:55:14 2012 UTC vs.
Revision 2.67 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 37 | 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 55 | Line 59 | main(
59   #define unguard()      
60   #endif
61  
58 extern char  *strerror();
59
62                                  /* rpict command */
63   char  *rpargv[128] = {"rpict", "-S", "1"};
64   int  rpargc = 3;
# Line 76 | Line 78 | int  nforked = 0;
78  
79   #define  sflock(t)      if ((t)!=synclst) dolock(fileno(syncfp),synclst=t)
80  
79 char  *progname;
81   int  verbose = 0;
82   int  nowarn = 0;
83   unsigned  timelim = 0;
# Line 101 | Line 102 | main(
102          char  *argv[]
103   )
104   {
105 <        register int  i, rval;
105 >        int  i, rval;
106          
107 <        progname = argv[0];
107 >        fixargv0(argv[0]);                      /* assigns global progname */
108          for (i = 1; i < argc; i++) {
109                                                  /* expand arguments */
110                  while ((rval = expandarg(&argc, &argv, i)) > 0)
# Line 151 | Line 152 | main(
152                                          ++i;
153                                          continue;
154                                  }
155 +                                if (argv[i][2] == 'X') {
156 +                                        fprintf(stderr, "%s: -pXYZ unsupported\n",
157 +                                                argv[0]);
158 +                                        ++i;
159 +                                        continue;
160 +                                }
161 +                                if (argv[i][2] == 'c') {
162 +                                        fprintf(stderr, "%s: -pc unsupported\n",
163 +                                                argv[0]);
164 +                                        i += 9;
165 +                                        continue;
166 +                                }
167                                  if (argv[i][2] != 'a' || argv[i][3])
168                                          break;
169                                  pixaspect = atof(argv[++i]);
170                                  continue;
171 +                        case 'S':
172 +                                fprintf(stderr, "%s: -S unsupported\n", argv[0]);
173 +                                i++;
174 +                                continue;
175                          case 'T':               /* time limit (hours) */
176                                  if (argv[i][2])
177                                          break;
# Line 275 | Line 292 | init(                  /* set up output file and start rpict */
292          normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres);
293          if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult))
294                  fprintf(stderr,
295 <                "%s: warning - resolution changed from %dx%d to %dx%d\n",
295 >                "%s: warning - changed resolution from %dx%d to %dx%d\n",
296                                  progname, hr, vr, hres*hmult, vres*vmult);
297          sprintf(hrbuf, "%d", hres);
298          rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf;
299          sprintf(vrbuf, "%d", vres);
300          rpargv[rpargc++] = "-y"; rpargv[rpargc++] = vrbuf;
301          rpargv[rpargc++] = "-pa"; rpargv[rpargc++] = "0";
302 +        rpargv[rpargc++] = "-pm"; rpargv[rpargc++] = "0";
303          rpargv[rpargc++] = av[ac-1];
304          rpargv[rpargc] = NULL;
305                                          /* open output file */
# Line 292 | Line 310 | init(                  /* set up output file and start rpict */
310                  newheader("RADIANCE", fp);      /* create header */
311                  printargs(ac, av, fp);
312                  fprintf(fp, "SOFTWARE= %s\n", VersionID);
313 +                fprintf(fp, "TILED= %d %d\n", hmult, vmult);
314                  fputs(VIEWSTR, fp);
315                  fprintview(&ourview, fp);
316 <                putc('\n', fp);
316 >                fputc('\n', fp);
317                  fputnow(fp);
318                  if (pixaspect < .99 || pixaspect > 1.01)
319                          fputaspect(pixaspect, fp);
320 +                fputprims(stdprims, fp);
321                  fputformat(COLRFMT, fp);
322 <                putc('\n', fp);
322 >                fputc('\n', fp);
323                  fprtresolu(hres*hmult, vres*vmult, fp);
324          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
325                  dolock(outfd, F_RDLCK);
# Line 322 | Line 342 | init(                  /* set up output file and start rpict */
342                  goto filerr;
343          dolock(outfd, F_UNLCK);
344                                          /* start rpict process */
345 +        rpd = sp_inactive;
346          if (open_process(&rpd, rpargv) <= 0) {
347                  fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
348                  exit(1);
# Line 392 | Line 413 | nextpiece(             /* get next piece assignment */
413  
414   static int
415   rvrpiece(               /* check for recoverable pieces */
416 <        register int    *xp,
417 <        register int    *yp
416 >        int     *xp,
417 >        int     *yp
418   )
419   {
420          static char  *pdone = NULL;     /* which pieces are done */
421          static long  readpos = -1;      /* how far we've read */
422 <        register int  i;
422 >        int  px, py, i;
423          /*
424           * This routine is called by nextpiece() with an
425           * exclusive lock on syncfp and the file pointer at the
# Line 407 | Line 428 | rvrpiece(              /* check for recoverable pieces */
428          if (rvrlim < 0)
429                  return(0);              /* only check if asked */
430          if (pdone == NULL)              /* first call */
431 <                pdone = calloc(hmult*vmult, sizeof(char));
431 >                pdone = (char *)calloc(hmult*vmult, sizeof(char));
432          if (pdone == NULL) {
433                  fprintf(stderr, "%s: out of memory\n", progname);
434                  exit(1);
435          }
436          if (readpos != -1)              /* mark what's been done */
437                  fseek(syncfp, readpos, 0);
438 <        while (fscanf(syncfp, "%d %d", xp, yp) == 2)
439 <                pdone[*xp*vmult+*yp] = 1;
438 >        while (fscanf(syncfp, "%d %d", &px, &py) == 2)
439 >                pdone[px*vmult+py] = 1;
440          if (!feof(syncfp)) {
441                  fprintf(stderr, "%s: format error in sync file\n", progname);
442                  exit(1);
# Line 456 | Line 477 | cleanup(                       /* close rpict process and clean up */
477   static void
478   rpiece(void)                    /* render picture piece by piece */
479   {
480 +        char  *err;
481          VIEW  pview;
482          int  xorg, yorg;
461                                        /* compute view parameters */
462        pview = ourview;
463        switch (ourview.type) {
464        case VT_PER:
465                pview.horiz = (2.*180./PI)*atan(
466                                tan((PI/180./2.)*ourview.horiz)/hmult );
467                pview.vert = (2.*180./PI)*atan(
468                                tan((PI/180./2.)*ourview.vert)/vmult );
469                break;
470        case VT_PAR:
471        case VT_ANG:
472                pview.horiz = ourview.horiz / hmult;
473                pview.vert = ourview.vert / vmult;
474                break;
475        case VT_CYL:
476                pview.horiz = ourview.horiz / hmult;
477                pview.vert = (2.*180./PI)*atan(
478                                tan((PI/180./2.)*ourview.vert)/vmult );
479                break;
480        case VT_HEM:
481                pview.horiz = (2.*180./PI)*asin(
482                                sin((PI/180./2.)*ourview.horiz)/hmult );
483                pview.vert = (2.*180./PI)*asin(
484                                sin((PI/180./2.)*ourview.vert)/vmult );
485                break;
486        case VT_PLS:
487                pview.horiz = sin((PI/180./2.)*ourview.horiz) /
488                                (1.0 + cos((PI/180./2.)*ourview.horiz)) / hmult;
489                pview.horiz *= pview.horiz;
490                pview.horiz = (2.*180./PI)*acos((1. - pview.horiz) /
491                                                (1. + pview.horiz));
492                pview.vert = sin((PI/180./2.)*ourview.vert) /
493                                (1.0 + cos((PI/180./2.)*ourview.vert)) / vmult;
494                pview.vert *= pview.vert;
495                pview.vert = (2.*180./PI)*acos((1. - pview.vert) /
496                                                (1. + pview.vert));
497                break;
498        default:
499                fprintf(stderr, "%s: unknown view type '-vt%c'\n",
500                                progname, ourview.type);
501                exit(cleanup(1));
502        }
483                                          /* render each piece */
484          while (nextpiece(&xorg, &yorg)) {
485 <                pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1);
486 <                pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1);
485 >                pview = ourview;
486 >                err = cropview(&pview, (double)xorg/hmult, (double)yorg/vmult,
487 >                                        (xorg+1.)/hmult, (yorg+1.)/vmult);
488 >                if (err != NULL) {
489 >                        fprintf(stderr, "%s: %s\n", progname, err);
490 >                        exit(cleanup(1));
491 >                }
492                  fputs(VIEWSTR, torp);
493                  fprintview(&pview, torp);
494 <                putc('\n', torp);
494 >                fputc('\n', torp);
495                  fflush(torp);                   /* assigns piece to rpict */
496                  putpiece(xorg, yorg);           /* place piece in output */
497          }
# Line 522 | Line 507 | int    ypos
507          struct flock  fls;
508          int  pid, status;
509          int  hr, vr;
510 <        register int  y;
510 >        int  y;
511                                  /* check bounds */
512          if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) {
513                  fprintf(stderr, "%s: requested piece (%d,%d) out of range\n",
# Line 584 | Line 569 | int    ypos
569          if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0)
570                  filerr("seek");
571          if (hmult == 1) {
572 <                if (writebuf(outfd, (char *)pbuf,
572 >                if (writebuf(outfd, pbuf,
573                                  vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR))
574                          filerr("write");
575          } else
576                  for (y = 0; y < vr; y++) {
577 <                        if (writebuf(outfd, (char *)(pbuf+y*hr),
577 >                        if (writebuf(outfd, pbuf+y*hr,
578                                          hr*sizeof(COLR)) != hr*sizeof(COLR))
579                                  filerr("write");
580                          if (y < vr-1 && lseek(outfd,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines