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

Comparing ray/src/rt/rpict.c (file contents):
Revision 2.49 by gwlarson, Tue Mar 3 19:14:28 1998 UTC vs.
Revision 2.99 by greg, Wed Nov 15 18:02:53 2023 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  rpict.c - routines and variables for picture generation.
6   */
7  
8 < #include  "ray.h"
8 > #include "copyright.h"
9  
10   #include  <sys/types.h>
11  
12 < #ifndef NIX
13 < #ifdef BSD
14 < #include  <sys/time.h>
15 < #include  <sys/resource.h>
12 > #include  "platform.h"
13 > #ifdef NON_POSIX
14 > #ifdef MINGW
15 >  #include  <sys/time.h>
16 > #endif
17   #else
18 < #include  <sys/times.h>
19 < #include  <unistd.h>
18 > #ifdef BSD
19 >  #include  <sys/time.h>
20 >  #include  <sys/resource.h>
21 > #else
22 >  #include  <sys/times.h>
23 >  #include  <unistd.h>
24 > #endif
25   #endif
23 #endif
26  
27 < extern time_t   time();
26 <
27 > #include  <time.h>
28   #include  <signal.h>
29  
30 + #include  "ray.h"
31 + #include  "paths.h"
32 + #include  "ambient.h"
33   #include  "view.h"
30
31 #include  "resolu.h"
32
34   #include  "random.h"
34
35   #include  "paths.h"
36 + #include  "hilbert.h"
37 + #include  "pmapbias.h"
38 + #include  "pmapdiag.h"
39  
40   #define  RFTEMPLATE     "rfXXXXXX"
41  
42   #ifndef SIGCONT
43 + #ifdef SIGIO     /* XXX can we live without this? */
44   #define SIGCONT         SIGIO
45   #endif
46 + #endif
47  
48 + CUBE  thescene;                         /* our scene */
49 + OBJECT  nsceneobjs;                     /* number of objects in our scene */
50 +
51 + extern RGBPRIMP  out_prims;             /* output color primitives (NULL if spectral) */
52 +
53   int  dimlist[MAXDIM];                   /* sampling dimensions */
54   int  ndims = 0;                         /* number of sampling dimensions */
55   int  samplendx;                         /* sample index number */
56  
57 + void  (*addobjnotify[])() = {ambnotify, NULL};
58 +
59   VIEW  ourview = STDVIEW;                /* view parameters */
60   int  hresolu = 512;                     /* horizontal resolution */
61   int  vresolu = 512;                     /* vertical resolution */
# Line 55 | Line 67 | double dstrpix = 0.67;                 /* square pixel distribution
67  
68   double  mblur = 0.;                     /* motion blur parameter */
69  
70 + double  dblur = 0.;                     /* depth-of-field blur parameter */
71 +
72 + void  (*trace)() = NULL;                /* trace call */
73 +
74 + int  do_irrad = 0;                      /* compute irradiance? */
75 +
76 + int  rand_samp = 0;                     /* pure Monte Carlo sampling? */
77 +
78   double  dstrsrc = 0.0;                  /* square source distribution */
79   double  shadthresh = .05;               /* shadow threshold */
80   double  shadcert = .5;                  /* shadow certainty */
# Line 73 | Line 93 | double specjitter = 1.;                /* specular sampling jitter *
93  
94   int  backvis = 1;                       /* back face visibility */
95  
96 < int  maxdepth = 6;                      /* maximum recursion depth */
97 < double  minweight = 5e-3;               /* minimum ray weight */
96 > int  maxdepth = 7;                      /* maximum recursion depth */
97 > double  minweight = 1e-4;               /* minimum ray weight */
98  
99 + char  *ambfile = NULL;                  /* ambient file name */
100   COLOR  ambval = BLKCOLOR;               /* ambient value */
101   int  ambvwt = 0;                        /* initial weight for ambient value */
102   double  ambacc = 0.2;                   /* ambient accuracy */
103 < int  ambres = 32;                       /* ambient resolution */
104 < int  ambdiv = 128;                      /* ambient divisions */
105 < int  ambssamp = 0;                      /* ambient super-samples */
103 > int  ambres = 64;                       /* ambient resolution */
104 > int  ambdiv = 512;                      /* ambient divisions */
105 > int  ambssamp = 128;                    /* ambient super-samples */
106   int  ambounce = 0;                      /* ambient bounces */
107 < char  *amblist[128];                    /* ambient include/exclude list */
107 > char  *amblist[AMBLLEN];                /* ambient include/exclude list */
108   int  ambincl = -1;                      /* include == 1, exclude == 0 */
109  
89 #ifdef MSDOS
90 int  ralrm = 60;                        /* seconds between reports */
91 #else
110   int  ralrm = 0;                         /* seconds between reports */
93 #endif
111  
112   double  pctdone = 0.0;                  /* percentage done */
96
113   time_t  tlastrept = 0L;                 /* time at last report */
114 + time_t  tstart;                         /* starting time */
115  
99 extern time_t  tstart;                  /* starting time */
100
101 extern unsigned long  nrays;            /* number of rays traced */
102
116   #define  MAXDIV         16              /* maximum sample size */
117  
118   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
# Line 108 | Line 121 | int  hres, vres;                       /* resolution for this frame */
121  
122   static VIEW     lastview;               /* the previous view input */
123  
124 < extern char  *mktemp();
124 > static void report(int);
125 > static int nextview(FILE *fp);
126 > static void render(char *zfile, char *oldfile);
127 > static void fillscanline(COLOR *scanline, float *zline, char *sd, int xres,
128 >                int y, int xstep);
129 > static void fillscanbar(COLOR *scanbar[], float *zbar[], int xres,
130 >                int y, int ysize);
131 > static int fillsample(COLOR *colline, float *zline, int x, int y,
132 >                int xlen, int ylen, int b);
133 > static double pixvalue(COLOR  col, int  x, int  y);
134 > static int salvage(char  *oldfile);
135 > static int pixnumber(int  x, int  y, int  xres, int  yres);
136  
113 double  pixvalue();
137  
115 #ifdef NIX
116 #define  file_exists(f) (access(f,F_OK)==0)
117 #else
118 #include  <sys/types.h>
119 #include  <sys/stat.h>
120 int
121 file_exists(fname)                              /* ordinary file exists? */
122 char  *fname;
123 {
124        struct stat  sbuf;
125        if (stat(fname, &sbuf) < 0) return(0);
126        return((sbuf.st_mode & S_IFREG) != 0);
127 }
128 #endif
138  
139 <
140 < quit(code)                      /* quit program */
132 < int  code;
139 > void
140 > quit(int code)                  /* quit program */
141   {
142          if (code)                       /* report status */
143 <                report();
143 >                report(0);
144 > #ifndef NON_POSIX
145          headclean();                    /* delete header file */
146          pfclean();                      /* clean up persist files */
147 + #endif
148          exit(code);
149   }
150  
151  
152 < #ifndef NIX
153 < report()                /* report progress */
152 > #ifndef NON_POSIX
153 > static void
154 > report(int dummy)               /* report progress */
155   {
156 <        extern char  *myhostname();
157 <        double  u, s;
156 >        char                    bcStat [128];
157 >        double          u, s;
158   #ifdef BSD
159 <        struct rusage  rubuf;
159 >        struct rusage   rubuf;
160   #else
161 <        struct tms  tbuf;
162 <        double  period;
161 >        double          period = 1.0 / 60.0;
162 >        struct tms      tbuf;
163   #endif
164  
165          tlastrept = time((time_t *)NULL);
166   #ifdef BSD
167          getrusage(RUSAGE_SELF, &rubuf);
168 <        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
169 <        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
168 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
169 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
170          getrusage(RUSAGE_CHILDREN, &rubuf);
171 <        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
172 <        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
171 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
172 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
173   #else
174          times(&tbuf);
175   #ifdef _SC_CLK_TCK
176          period = 1.0 / sysconf(_SC_CLK_TCK);
166 #else
167        period = 1.0 / 60.0;
177   #endif
178          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
179          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
180   #endif
181  
182 +        /* PMAP: Get photon map bias compensation statistics */
183 +        pmapBiasCompReport(bcStat);
184 +        
185          sprintf(errmsg,
186 <                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
187 <                        nrays, pctdone, u/3600., s/3600.,
188 <                        (tlastrept-tstart)/3600., myhostname());
186 >                        "%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
187 >                        nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.),
188 >                        (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
189          eputs(errmsg);
190 < #ifndef BSD
190 > #ifdef SIGCONT
191          signal(SIGCONT, report);
192   #endif
193   }
194   #else
195 < report()                /* report progress */
195 > static void
196 > report(int dummy)               /* report progress */
197   {
198 +        char    bcStat [128];
199 +        
200          tlastrept = time((time_t *)NULL);
201 <        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
202 <                        nrays, pctdone, (tlastrept-tstart)/3600.0);
201 >
202 >        /* PMAP: Get photon map bias compensation statistics */
203 >        pmapBiasCompReport(bcStat);
204 >        
205 >        sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n",
206 >                        nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0);
207          eputs(errmsg);
208   }
209   #endif
210  
211  
212 < rpict(seq, pout, zout, prvr)                    /* generate image(s) */
213 < int  seq;
214 < char  *pout, *zout, *prvr;
212 > void
213 > rpict(                  /* generate image(s) */
214 >        int  seq,
215 >        char  *pout,
216 >        char  *zout,
217 >        char  *prvr
218 > )
219   /*
220   * If seq is greater than zero, then we will render a sequence of
221   * images based on view parameter strings read from the standard input.
# Line 205 | Line 228 | char  *pout, *zout, *prvr;
228   * sequenced file naming.
229   */
230   {
208        extern char  *rindex(), *strncpy(), *strcat(), *strcpy();
231          char  fbuf[128], fbuf2[128];
232          int  npicts;
233 <        register char  *cp;
233 >        char  *cp;
234          RESOLU  rs;
235          double  pa;
236                                          /* check sampling */
# Line 224 | Line 246 | char  *pout, *zout, *prvr;
246          if (seq <= 0)
247                  seq = 0;
248          else if (prvr != NULL && isint(prvr)) {
249 <                register int  rn;               /* skip to specified view */
249 >                int  rn;                /* skip to specified view */
250                  if ((rn = atoi(prvr)) < seq)
251                          error(USER, "recover frame less than start frame");
252                  if (pout == NULL)
# Line 232 | Line 254 | char  *pout, *zout, *prvr;
254                  for ( ; seq < rn; seq++)
255                          if (nextview(stdin) == EOF)
256                                  error(USER, "unexpected EOF on view input");
257 +                setview(&ourview);
258                  prvr = fbuf;                    /* mark for renaming */
259          }
260 <        if (pout != NULL & prvr != NULL) {
260 >        if ((pout != NULL) & (prvr != NULL)) {
261                  sprintf(fbuf, pout, seq);
262                  if (!strcmp(prvr, fbuf)) {      /* rename */
263                          strcpy(fbuf2, fbuf);
# Line 244 | Line 267 | char  *pout, *zout, *prvr;
267                                  cp--;
268                          strcpy(cp, RFTEMPLATE);
269                          prvr = mktemp(fbuf2);
270 <                        if (rename(fbuf, prvr) < 0)
270 >                        if (rename(fbuf, prvr) < 0) {
271                                  if (errno == ENOENT) {  /* ghost file */
272                                          sprintf(errmsg,
273                                                  "new output file \"%s\"",
# Line 257 | Line 280 | char  *pout, *zout, *prvr;
280                                                  fbuf, prvr);
281                                          error(SYSTEM, errmsg);
282                                  }
283 +                        }
284                  }
285          }
286          npicts = 0;                     /* render sequence */
# Line 265 | Line 289 | char  *pout, *zout, *prvr;
289                          break;
290                  pctdone = 0.0;
291                  if (pout != NULL) {
292 +                        int     myfd;
293 +                        close(1);                       /* reassign stdout */
294                          sprintf(fbuf, pout, seq);
295 <                        if (file_exists(fbuf)) {
296 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
295 >                tryagain:
296 >                        errno = 0;                      /* exclusive open */
297 >                        if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
298 >                                if ((errno != EEXIST) | (prvr != NULL) ||
299 >                                                !strcmp(fbuf, pout)) {
300                                          sprintf(errmsg,
301 <                                                "output file \"%s\" exists",
301 >                                                "cannot open output file \"%s\"",
302                                                  fbuf);
303 <                                        error(USER, errmsg);
303 >                                        error(SYSTEM, errmsg);
304                                  }
305 +                                setview(&ourview);
306                                  continue;               /* don't clobber */
307                          }
308 <                        if (freopen(fbuf, "w", stdout) == NULL) {
309 <                                sprintf(errmsg,
310 <                                        "cannot open output file \"%s\"", fbuf);
281 <                                error(SYSTEM, errmsg);
308 >                        if (myfd != 1) {
309 >                                unlink(fbuf);
310 >                                goto tryagain;          /* leave it open */
311                          }
312 < #ifdef MSDOS
284 <                        setmode(fileno(stdout), O_BINARY);
285 < #endif
312 >                        SET_FD_BINARY(1);
313                          dupheader();
314                  }
315                  hres = hresolu; vres = vresolu; pa = pixaspect;
316 <                if (prvr != NULL)
317 <                        if (viewfile(prvr, &ourview, &rs) <= 0
291 <                                        || rs.or != PIXSTANDARD) {
316 >                if (prvr != NULL) {
317 >                        if (viewfile(prvr, &ourview, &rs) <= 0) {
318                                  sprintf(errmsg,
319                          "cannot recover view parameters from \"%s\"", prvr);
320                                  error(WARNING, errmsg);
# Line 297 | Line 323 | char  *pout, *zout, *prvr;
323                                  hres = scanlen(&rs);
324                                  vres = numscans(&rs);
325                          }
326 +                }
327                  if ((cp = setview(&ourview)) != NULL)
328                          error(USER, cp);
329                  normaspect(viewaspect(&ourview), &pa, &hres, &vres);
# Line 312 | Line 339 | char  *pout, *zout, *prvr;
339                  fputs(VIEWSTR, stdout);
340                  fprintview(&ourview, stdout);
341                  putchar('\n');
342 <                if (pa < .99 || pa > 1.01)
342 >                if ((pa < .99) | (pa > 1.01))
343                          fputaspect(pa, stdout);
344 <                fputformat(COLRFMT, stdout);
345 <                putchar('\n');
344 >                fputnow(stdout);
345 >                if (out_prims == xyzprims) {
346 >                        fputformat(CIEFMT, stdout);
347 >                } else {
348 >                        fputprims(out_prims, stdout);
349 >                        fputformat(COLRFMT, stdout);
350 >                }
351 >                putchar('\n');          /* close header */
352                  if (zout != NULL)
353                          sprintf(cp=fbuf, zout, seq);
354                  else
# Line 330 | Line 363 | char  *pout, *zout, *prvr;
363   }
364  
365  
366 < nextview(fp)                            /* get next view from fp */
367 < FILE  *fp;
366 > static int
367 > nextview(                               /* get next view from fp */
368 >        FILE  *fp
369 > )
370   {
371          char  linebuf[256];
372  
373 <        copystruct(&lastview, &ourview);
373 >        lastview = ourview;
374          while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
375                  if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
376                          return(0);
# Line 343 | Line 378 | FILE  *fp;
378   }      
379  
380  
381 < render(zfile, oldfile)                          /* render the scene */
382 < char  *zfile, *oldfile;
381 > static void
382 > render(                         /* render the scene */
383 >        char  *zfile,
384 >        char  *oldfile
385 > )
386   {
349        extern long  lseek();
387          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
388          float  *zbar[MAXDIV+1];         /* z values */
389          char  *sampdens;                /* previous sample density */
# Line 356 | Line 393 | char  *zfile, *oldfile;
393          int  zfd;
394          COLOR  *colptr;
395          float  *zptr;
396 <        register int  i;
396 >        int  i;
397 >                                        /* check for empty image */
398 >        if ((hres <= 0) | (vres <= 0)) {
399 >                error(WARNING, "empty output picture");
400 >                fprtresolu(0, 0, stdout);
401 >                return;
402 >        }
403                                          /* allocate scanlines */
404          for (i = 0; i <= psample; i++) {
405                  scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR));
# Line 367 | Line 410 | char  *zfile, *oldfile;
410          ystep = (psample*99+70)/140;
411          if (hstep > 2) {
412                  i = hres/hstep + 2;
413 <                if ((sampdens = malloc(i)) == NULL)
413 >                if ((sampdens = (char *)malloc(i)) == NULL)
414                          goto memerr;
415                  while (i--)
416                          sampdens[i] = hstep;
# Line 379 | Line 422 | char  *zfile, *oldfile;
422                          sprintf(errmsg, "cannot open z-file \"%s\"", zfile);
423                          error(SYSTEM, errmsg);
424                  }
425 < #ifdef MSDOS
383 <                setmode(zfd, O_BINARY);
384 < #endif
425 >                SET_FD_BINARY(zfd);
426                  for (i = 0; i <= psample; i++) {
427                          zbar[i] = (float *)malloc(hres*sizeof(float));
428                          if (zbar[i] == NULL)
# Line 398 | Line 439 | char  *zfile, *oldfile;
439          i = salvage(oldfile);
440          if (i >= vres)
441                  goto alldone;
442 <        if (zfd != -1 && i > 0 &&
443 <                        lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
442 >        if ((zfd != -1) & (i > 0) &&
443 >                        lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0)
444                  error(SYSTEM, "z-file seek error in render");
445          pctdone = 100.0*i/vres;
446          if (ralrm > 0)                  /* report init stats */
447 <                report();
448 < #ifndef  BSD
447 >                report(0);
448 > #ifdef SIGCONT
449          else
409 #endif
450          signal(SIGCONT, report);
451 + #endif
452          ypos = vres-1 - i;                      /* initialize sampling */
453          if (directvis)
454                  init_drawsources(psample);
# Line 433 | Line 474 | char  *zfile, *oldfile;
474                  if (directvis)                          /* add bitty sources */
475                          drawsources(scanbar, zbar, 0, hres, ypos, ystep);
476                                                          /* write it out */
477 < #ifndef  BSD
477 > #ifdef SIGCONT
478                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
479   #endif
480                  for (i = ystep; i > 0; i--) {
# Line 449 | Line 490 | char  *zfile, *oldfile;
490                                                          /* record progress */
491                  pctdone = 100.0*(vres-1-ypos)/vres;
492                  if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm)
493 <                        report();
494 < #ifndef  BSD
493 >                        report(0);
494 > #ifdef SIGCONT
495                  else
496                          signal(SIGCONT, report);
497   #endif
498          }
499                                                  /* clean up */
500 + #ifdef SIGCONT
501          signal(SIGCONT, SIG_IGN);
502 + #endif
503          if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float))
504                                  < hres*sizeof(float))
505                  goto writerr;
# Line 468 | Line 511 | alldone:
511                  if (close(zfd) == -1)
512                          goto writerr;
513                  for (i = 0; i <= psample; i++)
514 <                        free((char *)zbar[i]);
514 >                        free((void *)zbar[i]);
515          }
516          for (i = 0; i <= psample; i++)
517 <                free((char *)scanbar[i]);
517 >                free((void *)scanbar[i]);
518          if (sampdens != NULL)
519                  free(sampdens);
520          pctdone = 100.0;
521          if (ralrm > 0)
522 <                report();
522 >                report(0);
523 > #ifdef SIGCONT
524          signal(SIGCONT, SIG_DFL);
525 + #endif
526          return;
527   writerr:
528          error(SYSTEM, "write error in render");
# Line 486 | Line 531 | memerr:
531   }
532  
533  
534 < fillscanline(scanline, zline, sd, xres, y, xstep)       /* fill scan at y */
535 < register COLOR  *scanline;
536 < register float  *zline;
537 < register char  *sd;
538 < int  xres, y, xstep;
534 > static void
535 > fillscanline(   /* fill scan at y */
536 >        COLOR   *scanline,
537 >        float   *zline,
538 >        char  *sd,
539 >        int  xres,
540 >        int  y,
541 >        int  xstep
542 > )
543   {
544          static int  nc = 0;             /* number of calls */
545          int  bl = xstep, b = xstep;
546          double  z;
547 <        register int  i;
547 >        int  i;
548  
549          z = pixvalue(scanline[0], 0, y);
550          if (zline) zline[0] = z;
# Line 521 | Line 570 | int  xres, y, xstep;
570   }
571  
572  
573 < fillscanbar(scanbar, zbar, xres, y, ysize)      /* fill interior */
574 < register COLOR  *scanbar[];
575 < register float  *zbar[];
576 < int  xres, y, ysize;
573 > static void
574 > fillscanbar(    /* fill interior */
575 >        COLOR   *scanbar[],
576 >        float   *zbar[],
577 >        int  xres,
578 >        int  y,
579 >        int  ysize
580 > )
581   {
582          COLOR  vline[MAXDIV+1];
583          float  zline[MAXDIV+1];
584          int  b = ysize;
585 <        register int  i, j;
585 >        int  i, j;
586  
587          for (i = 0; i < xres; i++) {
588                  copycolor(vline[0], scanbar[0][i]);
# Line 550 | Line 603 | int  xres, y, ysize;
603   }
604  
605  
606 < int
607 < fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */
608 < register COLOR  *colline;
609 < register float  *zline;
610 < int  x, y;
611 < int  xlen, ylen;
612 < int  b;
606 > static int
607 > fillsample( /* fill interior points */
608 >        COLOR   *colline,
609 >        float   *zline,
610 >        int  x,
611 >        int  y,
612 >        int  xlen,
613 >        int  ylen,
614 >        int  b
615 > )
616   {
617          double  ratio;
618          double  z;
619          COLOR  ctmp;
620          int  ncut;
621 <        register int  len;
621 >        int  len;
622  
623          if (xlen > 0)                   /* x or y length is zero */
624                  len = xlen;
# Line 603 | Line 659 | int  b;
659   }
660  
661  
662 < double
663 < pixvalue(col, x, y)             /* compute pixel value */
664 < COLOR  col;                     /* returned color */
665 < int  x, y;                      /* pixel position */
662 > static double
663 > pixvalue(               /* compute pixel value */
664 >        COLOR  col,                     /* returned color */
665 >        int  x,                 /* pixel position */
666 >        int  y
667 > )
668   {
669 +        static COLORMAT xyz2myrgbmat;
670          RAY  thisray;
671          FVECT   lorg, ldir;
672 <        double  hpos, vpos, lmax, d;
672 >        double  hpos, vpos, lmax;
673 >        int     i;
674                                                  /* compute view ray */
675 +        setcolor(col, 0.0, 0.0, 0.0);
676          hpos = (x+pixjitter())/hres;
677          vpos = (y+pixjitter())/vres;
678          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
679 <                                        &ourview, hpos, vpos)) < -FTINY) {
619 <                setcolor(col, 0.0, 0.0, 0.0);
679 >                                        &ourview, hpos, vpos)) < -FTINY)
680                  return(0.0);
681 <        }
682 <
623 <        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
624 <
681 >                                                /* set pixel index */
682 >        samplendx = pixnumber(x,y,hres,vres);
683                                                  /* optional motion blur */
684          if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
685                                          &lastview, hpos, vpos)) >= -FTINY) {
686 <                register int    i;
629 <                register double  d = mblur*(.5-urand(281+samplendx));
686 >                double  d = mblur*(.5-urand(281+samplendx));
687  
688                  thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
689                  for (i = 3; i--; ) {
# Line 636 | Line 693 | int  x, y;                     /* pixel position */
693                  if (normalize(thisray.rdir) == 0.0)
694                          return(0.0);
695          }
696 +                                                /* depth-of-field */
697 +        if (!jitteraperture(thisray.rorg, thisray.rdir, &ourview, dblur))
698 +                return(0.0);
699  
700 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
700 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
701  
702          rayvalue(&thisray);                     /* trace ray */
703  
704 <        copycolor(col, thisray.rcol);           /* return color */
704 >        if (out_prims == stdprims) {            /* return color */
705 >                scolor_rgb(col, thisray.rcol);
706 >        } else if (out_prims == xyzprims) {
707 >                scolor_cie(col, thisray.rcol);
708 >                scalecolor(col, WHTEFFICACY);
709 >        } else if (NCSAMP > 3) {
710 >                COLOR   xyz;
711 >                if (xyz2myrgbmat[0][0] == 0)
712 >                        compxyz2rgbWBmat(xyz2myrgbmat, out_prims);
713 >                scolor_cie(xyz, thisray.rcol);
714 >                colortrans(col, xyz2myrgbmat, xyz);
715 >                clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
716 >        } else
717 >                copycolor(col, thisray.rcol);
718  
719 <        return(thisray.rt);                     /* return distance */
719 >        return(raydistance(&thisray));          /* return distance */
720   }
721  
722  
723 < int
724 < salvage(oldfile)                /* salvage scanlines from killed program */
725 < char  *oldfile;
723 > static int
724 > salvage(                /* salvage scanlines from killed program */
725 >        char  *oldfile
726 > )
727   {
728          COLR  *scanline;
729          FILE  *fp;
# Line 663 | Line 737 | char  *oldfile;
737                  error(WARNING, errmsg);
738                  goto gotzip;
739          }
740 < #ifdef MSDOS
667 <        setmode(fileno(fp), O_BINARY);
668 < #endif
740 >        SET_FILE_BINARY(fp);
741                                  /* discard header */
742          getheader(fp, NULL, NULL);
743                                  /* get picture size */
# Line 677 | Line 749 | char  *oldfile;
749                  goto gotzip;
750          }
751  
752 <        if (x != hres || y != vres) {
752 >        if ((x != hres) | (y != vres)) {
753                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
754                                  oldfile);
755                  error(USER, errmsg);
# Line 694 | Line 766 | char  *oldfile;
766          }
767          if (fflush(stdout) == EOF)
768                  goto writerr;
769 <        free((char *)scanline);
769 >        free((void *)scanline);
770          fclose(fp);
771          unlink(oldfile);
772          return(y);
# Line 705 | Line 777 | gotzip:
777   writerr:
778          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
779          error(SYSTEM, errmsg);
780 +        return -1; /* pro forma return */
781   }
782  
783 <
784 < int
785 < pixnumber(x, y, xres, yres)             /* compute pixel index (brushed) */
786 < register int  x, y;
787 < int  xres, yres;
783 > static int
784 > pixnumber(              /* compute pixel index (screen door) */
785 >        int  x,
786 >        int  y,
787 >        int  xres,
788 >        int  yres
789 > )
790   {
791 <        x -= y;
792 <        while (x < 0)
793 <                x += xres;
794 <        return((((x>>2)*yres + y) << 2) + (x & 3));
791 >        unsigned        nbits = 0;
792 >        bitmask_t       coord[2];
793 >
794 >        if (xres < yres) xres = yres;
795 >        while (xres > 0) {
796 >                xres >>= 1;
797 >                ++nbits;
798 >        }
799 >        coord[0] = x; coord[1] = y;
800 >        return ((int)hilbert_c2i(2, nbits, coord));
801   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines