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

Comparing ray/src/util/rcode_norm.c (file contents):
Revision 2.3 by greg, Tue Aug 13 16:31:35 2019 UTC vs.
Revision 2.8 by greg, Mon Jul 20 15:53:30 2020 UTC

# Line 22 | Line 22 | usage_exit(int code)
22   {
23          fputs("Usage: ", stderr);
24          fputs(progname, stderr);
25 <        fputs(" [-h[io]][-H[io]][-f[afd]] [input [output.nrm]]\n", stderr);
25 >        fputs(" [-h[io]][-H[io]][-f[afd]][-x xr -y yr] [input [output.nrm]]\n", stderr);
26          fputs("   Or: ", stderr);
27          fputs(progname, stderr);
28          fputs(" -r [-i][-u][-h[io]][-H[io]][-f[afd]] [input.nrm [output]]\n",
# Line 38 | Line 38 | encode_normals(NORMCODEC *ncp)
38          long    nexpected = (long)ncp->res.xr * ncp->res.yr;
39  
40          if (ncp->inpfmt[0]) {
41 <                if (strstr(ncp->inpfmt, "ascii") != NULL)
41 >                if (!strcmp(ncp->inpfmt, "ascii"))
42                          ncp->format = 'a';
43 <                else if (strstr(ncp->inpfmt, "float") != NULL)
43 >                else if (!strcmp(ncp->inpfmt, "float"))
44                          ncp->format = 'f';
45 <                else if (strstr(ncp->inpfmt, "double") != NULL)
45 >                else if (!strcmp(ncp->inpfmt, "double"))
46                          ncp->format = 'd';
47                  else {
48                          fputs(ncp->inpname, stderr);
# Line 52 | Line 52 | encode_normals(NORMCODEC *ncp)
52                          return 0;
53                  }
54          }
55 +        if (ncp->format == 'a')
56 +                SET_FILE_TEXT(ncp->finp);
57  
58          do {
59                  int     ok = 0;
# Line 65 | Line 67 | encode_normals(NORMCODEC *ncp)
67   #ifdef SMLFLT
68                  case 'f':
69                          ok = (getbinary(nrm, sizeof(*nrm), 3, ncp->finp) == 3);
70 +                        if (ncp->swapped)
71 +                                swap32((char *)nrm, 3);
72                          break;
73                  case 'd': {
74 <                                double  nrmd[3];
75 <                                ok = (getbinary(nrmd, sizeof(*nrmd),
76 <                                                3, ncp->finp) == 3);
77 <                                if (ok) VCOPY(nrm, nrmd);
78 <                        }
79 <                        break;
74 >                        double  nrmd[3];
75 >                        ok = (getbinary(nrmd, sizeof(*nrmd),
76 >                                        3, ncp->finp) == 3);
77 >                        if (ncp->swapped)
78 >                                swap64((char *)nrmd, 3);
79 >                        if (ok) VCOPY(nrm, nrmd);
80 >                        } break;
81   #else
82                  case 'f': {
83 <                                float   nrmf[3];
84 <                                ok = (getbinary(nrmf, sizeof(*nrmf),
85 <                                                3, ncp->finp) == 3);
86 <                                if (ok) VCOPY(nrm, nrmf);
87 <                        }
88 <                        break;
83 >                        float   nrmf[3];
84 >                        ok = (getbinary(nrmf, sizeof(*nrmf),
85 >                                        3, ncp->finp) == 3);
86 >                        if (ncp->swapped)
87 >                                swap32((char *)nrmf, 3);
88 >                        if (ok) VCOPY(nrm, nrmf);
89 >                        } break;
90                  case 'd':
91                          ok = (getbinary(nrm, sizeof(*nrm), 3, ncp->finp) == 3);
92 +                        if (ncp->swapped)
93 +                                swap64((char *)nrm, 3);
94                          break;
95   #endif
96                  }
# Line 183 | Line 191 | pixel_normals(NORMCODEC *ncp, int unbuf)
191                  fputs(": can only handle standard pixel ordering\n", stderr);
192                  return 0;
193          }
194 +
195          while (scanf("%d %d", &x, &y) == 2) {
196  
197                  y = ncp->res.yr-1 - y;
# Line 210 | Line 219 | pixel_normals(NORMCODEC *ncp, int unbuf)
219   int
220   main(int argc, char *argv[])
221   {
222 +        int             xres=0, yres=0;
223          int             reverse = 0;
224          int             bypixel = 0;
225          int             unbuffered = 0;
# Line 271 | Line 281 | main(int argc, char *argv[])
281                                  usage_exit(1);
282                          }
283                          break;
284 +                case 'x':
285 +                        xres = atoi(argv[++a]);
286 +                        break;
287 +                case 'y':
288 +                        yres = atoi(argv[++a]);
289 +                        break;
290                  case 'i':
291                          bypixel++;
292                          break;
# Line 282 | Line 298 | main(int argc, char *argv[])
298                  }
299          nc.hdrflags |= !reverse * HF_ENCODE;
300  
301 <        if ((nc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
301 >        if ((xres > 0) & (yres > 0)) {
302 >                nc.hdrflags &= ~HF_RESIN;
303 >                nc.res.rt = PIXSTANDARD;
304 >                nc.res.xr = xres;
305 >                nc.res.yr = yres;
306 >        } else if ((nc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
307                  fputs(progname, stderr);
308                  fputs(": unknown resolution for output\n", stderr);
309                  return 1;
# Line 321 | Line 342 | main(int argc, char *argv[])
342                  fputs(": cannot open for writing\n", stderr);
343                  return 1;
344          }
345 <        SET_FILE_BINARY(nc.finp);
346 <        if (reverse || nc.format != 'a')
326 <                SET_FILE_BINARY(stdout);
345 >        SET_FILE_BINARY(dc.finp);       /* starting assumption */
346 >        SET_FILE_BINARY(stdout);
347   #ifdef getc_unlocked                    /* avoid stupid semaphores */
348          flockfile(nc.finp);
349          flockfile(stdout);
# Line 331 | Line 351 | main(int argc, char *argv[])
351                                          /* read/copy header */
352          if (!process_nc_header(&nc, a, argv))
353                  return 1;
354 +
355 +        if (reverse && nc.format == 'a')
356 +                SET_FILE_TEXT(stdout);
357                                          /* process data */
358          if (!reverse) {
359                  if (!encode_normals(&nc))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines