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

Comparing ray/src/hd/rhcopy.c (file contents):
Revision 3.22 by schorsch, Thu Jan 1 11:21:55 2004 UTC vs.
Revision 3.33 by greg, Thu Nov 7 23:17:58 2019 UTC

# Line 31 | Line 31 | struct phead {
31   };
32   static int openholo(char *fname, int append);
33   static void addray(FVECT ro, FVECT rd, double d, COLR cv);
34 < static int holheadline(char *s, int *hf);
34 > static gethfunc holheadline;
35   static int bpcmp(const void *b1p, const void *b2p);
36   static int addclump(HOLO *hp, int *bq, int nb);
37   static void addholo(char *hdf);
38 < static int picheadline(char *s, struct phead *ph);
38 > static gethfunc picheadline;
39   static void addpicz(char *pcf, char *zbf);
40  
41  
# Line 85 | Line 85 | main(
85   userr:
86          fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n",
87                          progname);
88 <        fprintf(stderr, "   Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n",
88 >        fprintf(stderr, "   Or: %s output.hdk [-u][-d] -p inp1.hdr inp1.zbf ..\n",
89                          progname);
90          exit(1);
91   }
# Line 94 | Line 94 | userr:
94   #define H_BADF  01
95   #define H_OBST  02
96   #define H_OBSF  04
97 + #define H_SWAP  010
98  
99 < int
99 > static int
100   holheadline(            /* check holodeck header line */
101 <        register char   *s,
102 <        int     *hf
101 >        char    *s,
102 >        void    *vhf
103   )
104   {
105 <        char    fmt[32];
105 >        int     be;
106 >        char    fmt[MAXFMTLEN];
107 >        int     *hf = vhf;
108  
109          if (formatval(fmt, s)) {
110                  if (strcmp(fmt, HOLOFMT))
# Line 121 | Line 124 | holheadline(           /* check holodeck header line */
124                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
125                  return(0);
126          }
127 +        if ((be = isbigendian(s)) >= 0) {
128 +                if (be != nativebigendian())
129 +                        *hf |= H_SWAP;
130 +        }
131          return(0);
132   }
133  
# Line 133 | Line 140 | openholo(              /* open existing holodeck file for i/o */
140          FILE    *fp;
141          int     fd;
142          int     hflags = 0;
143 <        long    nextloc;
143 >        off_t   nextloc;
144          int     n;
145                                          /* open holodeck file */
146 <        if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) {
146 >        if ((fp = fopen(fname, append ? "rb+" : "rb")) == NULL) {
147                  sprintf(errmsg, "cannot open \"%s\" for %s", fname,
148                                  append ? "appending" : "reading");
149                  error(SYSTEM, errmsg);
150          }
151                                          /* check header and magic number */
152 <        if (getheader(fp, holheadline, (char *)&hflags) < 0 ||
153 <                        hflags&H_BADF || getw(fp) != HOLOMAGIC) {
154 <                sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
152 >        if (getheader(fp, holheadline, &hflags) < 0 ||
153 >                        hflags&(H_BADF|H_SWAP) || getw(fp) != HOLOMAGIC) {
154 >                sprintf(errmsg, "holodeck \"%s\" not in expected format", fname);
155                  error(USER, errmsg);
156          }
157          fd = dup(fileno(fp));                   /* dup file handle */
158          nextloc = ftell(fp);                    /* get stdio position */
159          fclose(fp);                             /* done with stdio */
160          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
161 <                lseek(fd, (off_t)nextloc, SEEK_SET);
161 >                lseek(fd, nextloc, SEEK_SET);
162                  read(fd, (char *)&nextloc, sizeof(nextloc));
163                  hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
164                                  hflags&H_OBSF ? &unobstr : (char *)NULL;
# Line 173 | Line 180 | addray(                /* add a ray to our output holodeck */
180   )
181   {
182          int     sn, bi, n;
183 <        register HOLO   *hp;
183 >        HOLO    *hp;
184          GCOORD  gc[2];
185 <        BYTE    rr[2][2];
185 >        uby8    rr[2][2];
186          BEAM    *bp;
187          double  d0, d1;
188          unsigned        dc;
189 <        register RAYVAL *rv;
189 >        RAYVAL  *rv;
190                                  /* check each output section */
191          for (sn = noutsects; sn--; ) {
192                  hp = hdlist[sn];
# Line 222 | Line 229 | bpcmp(                 /* compare beam positions on disk */
229          const void      *b2p
230   )
231   {
232 <        register off_t  pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo;
232 >        off_t   pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo;
233  
234          if (pdif > 0L) return(1);
235          if (pdif < 0L) return(-1);
# Line 240 | Line 247 | addclump(              /* transfer the given clump and free */
247          FVECT   ro, rd;
248          double  d;
249          int     i;
250 <        register int    k;
251 <        register BEAM   *bp;
250 >        int     k;
251 >        BEAM    *bp;
252                                          /* sort based on file position */
253          beamdir = hp->bi;
254          qsort((char *)bq, nb, sizeof(*bq), bpcmp);
# Line 285 | Line 292 | addholo(                       /* add a holodeck file */
292  
293  
294  
295 < int
295 > static int
296   picheadline(            /* process picture header line */
297          char    *s,
298 <        struct phead    *ph
298 >        void    *vph
299   )
300   {
301          char    fmt[32];
302 +        struct phead *ph = vph;
303  
304          if (formatval(fmt, s)) {
305                  ph->badfmt = strcmp(fmt, COLRFMT);
# Line 332 | Line 340 | addpicz(               /* add a picture + depth-buffer */
340          double  aftd;
341          COLOR   ctmp;
342          int     j;
343 <        register int    i;
343 >        int     i;
344                                  /* open files */
345 <        if ((pfp = fopen(pcf, "r")) == NULL) {
345 >        if ((pfp = fopen(pcf, "rb")) == NULL) {
346                  sprintf(errmsg, "cannot open picture file \"%s\"", pcf);
347                  error(SYSTEM, pcf);
348          }
# Line 342 | Line 350 | addpicz(               /* add a picture + depth-buffer */
350                  sprintf(errmsg, "cannot open depth file \"%s\"", zbf);
351                  error(SYSTEM, pcf);
352          }
353 +        SET_FD_BINARY(zfd);
354                                  /* load picture header */
355          phd.vw = stdview;
356          phd.expos = 1.0;
357          phd.badfmt = phd.gotview = phd.altprims = 0;
358 <        if (getheader(pfp, picheadline, (char *)&phd) < 0 ||
358 >        if (getheader(pfp, picheadline, &phd) < 0 ||
359                          phd.badfmt || !fgetsresolu(&prs, pfp)) {
360                  sprintf(errmsg, "bad format for picture file \"%s\"", pcf);
361                  error(USER, errmsg);
# Line 357 | Line 366 | addpicz(               /* add a picture + depth-buffer */
366                  error(USER, errmsg);
367          }
368          if (phd.altprims) {
369 <                sprintf(errmsg, "ignoring primary values in picture \"%s\"",
369 >                sprintf(errmsg, "ignoring color primaries in picture \"%s\"",
370                                  pcf);
371                  error(WARNING, errmsg);
372          }
# Line 390 | Line 399 | addpicz(               /* add a picture + depth-buffer */
399                  }
400                  if (eshft)                              /* shift exposure */
401                          shiftcolrs(cscn, i, eshft);
402 <                i *= sizeof(float);                     /* read depth */
403 <                if (read(zfd, (char *)zscn, i) != i) {
402 >                                                        /* read depth */
403 >                if (read(zfd, zscn, i*sizeof(float)) != i*sizeof(float)) {
404                          sprintf(errmsg, "error reading depth file \"%s\"", zbf);
405                          error(USER, errmsg);
406                  }
407 <                for (i = scanlen(&prs); i--; ) {        /* do each pixel */
407 >                while (i--) {                           /* process each pixel */
408 >                        if (zscn[i] <= 0.0)
409 >                                continue;               /* illegal depth */
410                          pix2loc(vl, &prs, i, j);
411                          aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]);
412                          if (aftd < -FTINY)
# Line 423 | Line 434 | addpicz(               /* add a picture + depth-buffer */
434  
435   void
436   eputs(                  /* put error message to stderr */
437 <        register char  *s
437 >        char  *s
438   )
439   {
440          static int  midline = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines