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

Comparing ray/src/util/pvsum.c (file contents):
Revision 2.2 by greg, Thu Mar 27 16:35:00 2025 UTC vs.
Revision 2.8 by greg, Fri Oct 24 22:41:10 2025 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "rtio.h"
11   #include "resolu.h"
12   #include "platform.h"
13 #include "paths.h"
13   #include "random.h"
14   #include "rmatrix.h"
15   #if !defined(_WIN32) && !defined(_WIN64)
16   #include <sys/mman.h>
17 + #include <sys/wait.h>
18   #endif
19  
20 + #define  VIEWSTR        "VIEW="         /* borrowed from common/view.h */
21 + #define  VIEWSTRL       5
22 +
23   int     nprocs = 1;                     /* # of calculation processes (Unix) */
24   int     in_type = DTfromHeader;         /* input data type */
25   int     out_type = DTfromHeader;        /* output data type */
# Line 26 | Line 29 | char   *out_spec = NULL;               /* output file specification *
29   int     iswapped = 0;                   /* input data is byte-swapped? */
30   int     ncomp = 3;                      /* # input components */
31   int     xres=0, yres=0;                 /* input image dimensions */
32 + char    viewspec[128] = "";             /* VIEW= line from first header */
33 + char    pixasp[48] = "";                /* PIXASPECT= line from header */
34  
35 + int     gargc;                          /* global argc */
36 + char    **gargv;                        /* global argv */
37 +
38   RMATRIX *cmtx = NULL;                   /* coefficient matrix */
39  
40   /* does the given spec contain integer format? */
# Line 68 | Line 76 | iheadline(char *s, void *p)
76                  ncomp = ncompval(s);
77                  return(1);
78          }
71        if (isexpos(s)) {
72                if (fabs(1. - exposval(s)) > 0.04)
73                        fputs("Warning - ignoring EXPOSURE setting\n", stderr);
74                return(1);
75        }
79          if (formatval(fmt, s)) {
80                  for (in_type = DTend; --in_type > DTfromHeader; )
81                          if (!strcmp(fmt, cm_fmt_id[in_type]))
# Line 84 | Line 87 | iheadline(char *s, void *p)
87                  iswapped = (i != nativebigendian());
88                  return(1);
89          }
90 +        if (!strncmp(s, VIEWSTR, VIEWSTRL)) {
91 +                strcpy(viewspec, s);
92 +                return(1);
93 +        }
94 +        if (isaspect(s)) {
95 +                strcpy(pixasp, s);
96 +                return(1);
97 +        }
98          return(0);
99   }
100  
# Line 155 | Line 166 | get_iotypes(void)
166   int
167   checkline(char *s, void *p)
168   {
169 <        int     *xyres = (int *)p;
170 <        char    fmt[MAXFMTLEN];
169 >        static int      exposWarned = 0;
170 >        int             *xyres = (int *)p;
171 >        char            fmt[MAXFMTLEN];
172  
173          if (!strncmp(s, "NCOLS=", 6)) {
174                  xyres[0] = atoi(s+6);
# Line 176 | Line 188 | checkline(char *s, void *p)
188                  return(1);
189          }
190          if (isexpos(s)) {
191 <                if (fabs(1. - exposval(s)) > 0.04)
192 <                        fputs("Warning - ignoring EXPOSURE setting\n", stderr);
191 >                if (!exposWarned && fabs(1. - exposval(s)) > 0.04) {
192 >                        fputs("Warning - ignoring EXPOSURE setting(s)\n",
193 >                                        stderr);
194 >                        exposWarned++;
195 >                }
196                  return(1);
197          }
198          if (formatval(fmt, s)) {
# Line 228 | Line 243 | open_output(char *ospec, int fno)
243          if (!ospec) {
244                  ospec = "<stdout>";
245                  fp = stdout;
231                SET_FILE_BINARY(fp);
246          } else if (ospec[0] == '!') {
247                  if (!(fp = popen(ospec+1, "w"))) {
248                          fprintf(stderr, "Cannot start: %s\n", ospec);
249                          return(NULL);
250                  }
251 <                SET_FILE_BINARY(fp);
238 <        } else if (!(fp = fopen(ospec, "wb"))) {
251 >        } else if (!(fp = fopen(ospec, "w"))) {
252                  fprintf(stderr, "%s: cannot open for writing\n", ospec);
253                  return(NULL);
254          }
255 +        SET_FILE_BINARY(fp);
256          newheader("RADIANCE", fp);
257          if (cmtx->info)                 /* prepend matrix metadata */
258                  fputs(cmtx->info, fp);
259          else
260                  fputnow(fp);
261 +        printargs(gargc, gargv, fp);    /* this command */
262          if (fno >= 0)
263                  fprintf(fp, "FRAME=%d\n", fno);
264 +        if (viewspec[0])
265 +                fputs(viewspec, fp);
266 +        if (pixasp[0])
267 +                fputs(pixasp, fp);
268          switch (out_type) {
269          case DTfloat:
270          case DTdouble:
# Line 381 | Line 400 | writerr:
400          return(0);
401   }
402  
403 + #if defined(_WIN32) || defined(_WIN64)
404 + #define multi_process   solo_process
405 + #else
406 +
407   /* allocate a scrambled index array of the specified length */
408   int *
409   scramble(int n)
# Line 408 | Line 431 | scramble(int n)
431   int
432   multi_process(void)
433   {
411 #if defined(_WIN32) || defined(_WIN64)
412        fputs("Bad call to multi_process()\n", stderr);
413        return(0);
414 #else
434          int     coff = nprocs;
435          int     odd = 0;
436          char    fbuf[512];
# Line 473 | Line 492 | multi_process(void)
492                                  return(0);
493                          }
494                          i = in_type==DTfloat ? ncomp*(int)sizeof(float) : ncomp+1;
495 <                        maplen = dstart + yres*xres*i;
495 >                        maplen = dstart + (size_t)yres*xres*i;
496                          imap = mmap(NULL, maplen, PROT_READ,
497                                          MAP_FILE|MAP_SHARED, fileno(finp), 0);
498 <                        fclose(finp);           /* will load from map (randomly) */
498 >                        fclose(finp);           /* will read from map (randomly) */
499                          if (imap == MAP_FAILED) {
500                                  fprintf(stderr, "%s: unable to map input file\n", fbuf);
501                                  return(0);
# Line 502 | Line 521 | multi_process(void)
521                                  }
522                              }
523                          munmap(imap, maplen);
524 <                }                       /* write out accumulated column result */
524 >                }                       /* write accumulated column picture/matrix */
525                  sprintf(fbuf, out_spec, c);
526                  fout = open_output(fbuf, c);
527                  if (!fout)
# Line 527 | Line 546 | multi_process(void)
546          }
547          free(osum);
548          free(syarr);
549 <        if (coff)                       /* children return here... */
549 >        if (coff)                       /* child processes return here... */
550                  return(1);
551          c = 0;                          /* ...but parent waits for children */
552          while (++coff < nprocs) {
# Line 540 | Line 559 | multi_process(void)
559   writerr:
560          fprintf(stderr, "%s: write error\n", fbuf);
561          return(0);
543 #endif
562   }
563  
564 + #endif          /* ! Windows */
565 +
566   int
567   main(int argc, char *argv[])
568   {
569          int     a;
570  
571 +        gargc = argc;                   /* for header output */
572 +        gargv = argv;
573 +
574          for (a = 1; a < argc-1 && argv[a][0] == '-'; a++)
575                  switch (argv[a][1]) {
576                  case 'o':               /* output spec/format */
# Line 579 | Line 602 | badopt:                        fprintf(stderr, "%s: bad option: %s\n", argv
602          if ((argc-a < 1) | (argc-a > 2) || argv[a][0] == '-')
603                  goto userr;
604          in_spec = argv[a];
605 <        cmtx = rmx_load(argv[a+1], RMPnone);    /* may load from stdin */
605 >        cmtx = rmx_load(argv[a+1]);     /* loads from stdin if a+1==argc */
606          if (cmtx == NULL)
607                  return(1);              /* error reported */
608 +        if (nprocs > cmtx->ncols)
609 +                nprocs = cmtx->ncols;
610   #if defined(_WIN32) || defined(_WIN64)
611          if (nprocs > 1) {
612                  fprintf(stderr, "%s: warning - Windows only allows -N 1\n", argv[0]);
613                  nprocs = 1;
614          }
615   #else
591        if (nprocs > cmtx->ncols)
592                nprocs = cmtx->ncols;
616          if ((nprocs > 1) & !out_spec) {
617                  fprintf(stderr, "%s: multi-processing result cannot go to stdout\n",
618                                  argv[0]);

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)