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

Comparing ray/src/rt/rxpiece.cpp (file contents):
Revision 2.3 by greg, Tue Sep 17 00:25:41 2024 UTC vs.
Revision 2.5 by greg, Tue Sep 17 16:29:09 2024 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14  
15   #include  "platform.h"
16   #include  "RpictSimulManager.h"
17 + #include  "ambient.h"
18 + #include  "pmapray.h"
19   #include  "random.h"
20  
21   extern char  *progname;                 /* argv[0] */
# Line 55 | Line 57 | static RenderDataType rpiece(char *pout, RenderDataTyp
57                  "OutputCS=RGB,XYZ,prims,spec\n"
58  
59  
60 + // We could call myRPmanager.Cleanup() but why waste time
61 + // unwinding data structures when the whole frame is going away?
62   void
63   quit(int code)                          /* quit program */
64   {
65 +        ambsync();                      // flush ambient cache
66 +
67 +        ray_done_pmap();                /* PMAP: free photon maps */
68 +
69          exit(code);
70   }
71  
# Line 315 | Line 323 | main(int  argc, char  *argv[])
323                                          // render tiles
324          dtype = rpiece(outfile, dtype, zfile);
325  
326 <        quit(dtype==RDTnone);           // clean up and exit
326 >        quit(dtype==RDTnone);           // status is 1 on failure
327  
328   badopt:
329          sprintf(errmsg, "command line error at '%s'", argv[i]);
# Line 598 | Line 606 | rpiece(char *pout, RenderDataType dt, char *zout)
606  
607          const bool      newOutput = (access(pout, F_OK) < 0);
608          FILE            *pdfp[2];
609 <        if (!newOutput) {                       // output exists?
609 >        if (newOutput) {                        // new output file?
610 >                CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1),
611 >                                 USER, "bad tiling specification");
612 >        } else {
613                  dt = myRPmanager.ReopenOutput(pdfp, pout, zout);
614                  if (dt == RDTnone)
615                          quit(1);
# Line 608 | Line 619 | rpiece(char *pout, RenderDataType dt, char *zout)
619                  myRPmanager.NewHeader(pout);    // get prev. header info
620                  const char *    tval = myRPmanager.GetHeadStr("TILED=");
621                  if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]);
622 <                if (!myRPmanager.GetView()) {
623 <                        sprintf(errmsg, "missing view in picture file '%s'", pout);
613 <                        error(USER, errmsg);
614 <                }
622 >                CHECK(myRPmanager.GetView()==NULL,
623 >                                USER, "missing view in picture file");
624                  ourview = *myRPmanager.GetView();
625          }
626          int     hvdim[2] = {hresolu, vresolu};  // set up tiled frame
# Line 635 | Line 644 | rpiece(char *pout, RenderDataType dt, char *zout)
644                  if (dt == RDTnone)
645                          quit(1);
646                  fprtresolu(hresolu, vresolu, pdfp[0]);
647 <        }
648 <        if (RDTdepthT(dt) == RDTdshort) {
640 <                if (newOutput)
647 >                fflush(pdfp[0]);
648 >                if (RDTdepthT(dt) == RDTdshort) {
649                          fprtresolu(hresolu, vresolu, pdfp[1]);
650 <                else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
651 <                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu))
652 <                        error(USER, "mismatched depth file resolution");
653 <        }
650 >                        fflush(pdfp[1]);
651 >                }
652 >        } else if (RDTdepthT(dt) == RDTdshort &&
653 >                        (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
654 >                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu)))
655 >                error(USER, "mismatched depth file resolution");
656                                                  // prepare (flat) pixel buffer
657          const long      pdata_beg = ftell(pdfp[0]);
658          const size_t    pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR)
# Line 653 | Line 663 | rpiece(char *pout, RenderDataType dt, char *zout)
663          if (pmlen&7) pmlen += 8 - (pmlen&7);    // 8-byte alignment to be safe
664          pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1];
665                                                  // map picture file to memory
666 <        if (ftruncate(fileno(pdfp[0]), pmlen) < 0)
666 >        if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0)
667                  error(SYSTEM, "cannot extend picture buffer");
668          uby8 *          pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE,
669                                                  MAP_SHARED, fileno(pdfp[0]), 0);
# Line 666 | Line 676 | rpiece(char *pout, RenderDataType dt, char *zout)
676          const size_t    zmlen = zdata_beg + zdpSiz*hresolu*vresolu;
677          uby8 *          zdMap = NULL;
678          if (RDTdepthT(dt)) {
679 <                if (ftruncate(fileno(pdfp[1]), zmlen) < 0)
679 >                if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0)
680                          error(SYSTEM, "cannot extend depth buffer");
681                  zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE,
682                                                  MAP_SHARED, fileno(pdfp[1]), 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines