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.7 by greg, Fri Oct 24 16:31:18 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   RMATRIX *cmtx = NULL;                   /* coefficient matrix */
36  
# Line 68 | Line 73 | iheadline(char *s, void *p)
73                  ncomp = ncompval(s);
74                  return(1);
75          }
71        if (isexpos(s)) {
72                if (fabs(1. - exposval(s)) > 0.04)
73                        fputs("Warning - ignoring EXPOSURE setting\n", stderr);
74                return(1);
75        }
76          if (formatval(fmt, s)) {
77                  for (in_type = DTend; --in_type > DTfromHeader; )
78                          if (!strcmp(fmt, cm_fmt_id[in_type]))
# Line 84 | Line 84 | iheadline(char *s, void *p)
84                  iswapped = (i != nativebigendian());
85                  return(1);
86          }
87 +        if (!strncmp(s, VIEWSTR, VIEWSTRL)) {
88 +                strcpy(viewspec, s);
89 +                return(1);
90 +        }
91 +        if (isaspect(s)) {
92 +                strcpy(pixasp, s);
93 +                return(1);
94 +        }
95          return(0);
96   }
97  
# Line 155 | Line 163 | get_iotypes(void)
163   int
164   checkline(char *s, void *p)
165   {
166 <        int     *xyres = (int *)p;
167 <        char    fmt[MAXFMTLEN];
166 >        static int      exposWarned = 0;
167 >        int             *xyres = (int *)p;
168 >        char            fmt[MAXFMTLEN];
169  
170          if (!strncmp(s, "NCOLS=", 6)) {
171                  xyres[0] = atoi(s+6);
# Line 176 | Line 185 | checkline(char *s, void *p)
185                  return(1);
186          }
187          if (isexpos(s)) {
188 <                if (fabs(1. - exposval(s)) > 0.04)
189 <                        fputs("Warning - ignoring EXPOSURE setting\n", stderr);
188 >                if (!exposWarned && fabs(1. - exposval(s)) > 0.04) {
189 >                        fputs("Warning - ignoring EXPOSURE setting(s)\n",
190 >                                        stderr);
191 >                        exposWarned++;
192 >                }
193                  return(1);
194          }
195          if (formatval(fmt, s)) {
# Line 228 | Line 240 | open_output(char *ospec, int fno)
240          if (!ospec) {
241                  ospec = "<stdout>";
242                  fp = stdout;
231                SET_FILE_BINARY(fp);
243          } else if (ospec[0] == '!') {
244                  if (!(fp = popen(ospec+1, "w"))) {
245                          fprintf(stderr, "Cannot start: %s\n", ospec);
246                          return(NULL);
247                  }
248 <                SET_FILE_BINARY(fp);
238 <        } else if (!(fp = fopen(ospec, "wb"))) {
248 >        } else if (!(fp = fopen(ospec, "w"))) {
249                  fprintf(stderr, "%s: cannot open for writing\n", ospec);
250                  return(NULL);
251          }
252 +        SET_FILE_BINARY(fp);
253          newheader("RADIANCE", fp);
254          if (cmtx->info)                 /* prepend matrix metadata */
255                  fputs(cmtx->info, fp);
# Line 246 | Line 257 | open_output(char *ospec, int fno)
257                  fputnow(fp);
258          if (fno >= 0)
259                  fprintf(fp, "FRAME=%d\n", fno);
260 +        if (viewspec[0])
261 +                fputs(viewspec, fp);
262 +        if (pixasp[0])
263 +                fputs(pixasp, fp);
264          switch (out_type) {
265          case DTfloat:
266          case DTdouble:
# Line 381 | Line 396 | writerr:
396          return(0);
397   }
398  
399 + #if defined(_WIN32) || defined(_WIN64)
400 + #define multi_process   solo_process
401 + #else
402 +
403   /* allocate a scrambled index array of the specified length */
404   int *
405   scramble(int n)
# Line 408 | Line 427 | scramble(int n)
427   int
428   multi_process(void)
429   {
411 #if defined(_WIN32) || defined(_WIN64)
412        fputs("Bad call to multi_process()\n", stderr);
413        return(0);
414 #else
430          int     coff = nprocs;
431          int     odd = 0;
432          char    fbuf[512];
# Line 473 | Line 488 | multi_process(void)
488                                  return(0);
489                          }
490                          i = in_type==DTfloat ? ncomp*(int)sizeof(float) : ncomp+1;
491 <                        maplen = dstart + yres*xres*i;
491 >                        maplen = dstart + (size_t)yres*xres*i;
492                          imap = mmap(NULL, maplen, PROT_READ,
493                                          MAP_FILE|MAP_SHARED, fileno(finp), 0);
494 <                        fclose(finp);           /* will load from map (randomly) */
494 >                        fclose(finp);           /* will read from map (randomly) */
495                          if (imap == MAP_FAILED) {
496                                  fprintf(stderr, "%s: unable to map input file\n", fbuf);
497                                  return(0);
# Line 502 | Line 517 | multi_process(void)
517                                  }
518                              }
519                          munmap(imap, maplen);
520 <                }                       /* write out accumulated column result */
520 >                }                       /* write accumulated column picture/matrix */
521                  sprintf(fbuf, out_spec, c);
522                  fout = open_output(fbuf, c);
523                  if (!fout)
# Line 527 | Line 542 | multi_process(void)
542          }
543          free(osum);
544          free(syarr);
545 <        if (coff)                       /* children return here... */
545 >        if (coff)                       /* child processes return here... */
546                  return(1);
547          c = 0;                          /* ...but parent waits for children */
548          while (++coff < nprocs) {
# Line 540 | Line 555 | multi_process(void)
555   writerr:
556          fprintf(stderr, "%s: write error\n", fbuf);
557          return(0);
543 #endif
558   }
559  
560 + #endif          /* ! Windows */
561 +
562   int
563   main(int argc, char *argv[])
564   {
# Line 579 | Line 595 | badopt:                        fprintf(stderr, "%s: bad option: %s\n", argv
595          if ((argc-a < 1) | (argc-a > 2) || argv[a][0] == '-')
596                  goto userr;
597          in_spec = argv[a];
598 <        cmtx = rmx_load(argv[a+1], RMPnone);    /* may load from stdin */
598 >        cmtx = rmx_load(argv[a+1]);     /* loads from stdin if a+1==argc */
599          if (cmtx == NULL)
600                  return(1);              /* error reported */
601 +        if (nprocs > cmtx->ncols)
602 +                nprocs = cmtx->ncols;
603   #if defined(_WIN32) || defined(_WIN64)
604          if (nprocs > 1) {
605                  fprintf(stderr, "%s: warning - Windows only allows -N 1\n", argv[0]);
606                  nprocs = 1;
607          }
608   #else
591        if (nprocs > cmtx->ncols)
592                nprocs = cmtx->ncols;
609          if ((nprocs > 1) & !out_spec) {
610                  fprintf(stderr, "%s: multi-processing result cannot go to stdout\n",
611                                  argv[0]);

Diff Legend

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