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.10 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include "rtmath.h"
14   #include "normcodec.h"
15  
16 char            *progname;              /* set in main() */
16  
18
17   /* Report usage error and exit */
18   static void
19   usage_exit(int code)
20   {
21          fputs("Usage: ", stderr);
22          fputs(progname, stderr);
23 <        fputs(" [-h[io]][-H[io]][-f[afd]] [input [output.nrm]]\n", stderr);
23 >        fputs(" [-h[io]][-H[io]][-f[afd]][-x xr -y yr] [input [output.nrm]]\n", stderr);
24          fputs("   Or: ", stderr);
25          fputs(progname, stderr);
26          fputs(" -r [-i][-u][-h[io]][-H[io]][-f[afd]] [input.nrm [output]]\n",
# Line 38 | Line 36 | encode_normals(NORMCODEC *ncp)
36          long    nexpected = (long)ncp->res.xr * ncp->res.yr;
37  
38          if (ncp->inpfmt[0]) {
39 <                if (strstr(ncp->inpfmt, "ascii") != NULL)
39 >                if (!strcmp(ncp->inpfmt, "ascii"))
40                          ncp->format = 'a';
41 <                else if (strstr(ncp->inpfmt, "float") != NULL)
41 >                else if (!strcmp(ncp->inpfmt, "float"))
42                          ncp->format = 'f';
43 <                else if (strstr(ncp->inpfmt, "double") != NULL)
43 >                else if (!strcmp(ncp->inpfmt, "double"))
44                          ncp->format = 'd';
45                  else {
46                          fputs(ncp->inpname, stderr);
# Line 52 | Line 50 | encode_normals(NORMCODEC *ncp)
50                          return 0;
51                  }
52          }
53 +        if (ncp->format == 'a')
54 +                SET_FILE_TEXT(ncp->finp);
55  
56          do {
57                  int     ok = 0;
# Line 65 | Line 65 | encode_normals(NORMCODEC *ncp)
65   #ifdef SMLFLT
66                  case 'f':
67                          ok = (getbinary(nrm, sizeof(*nrm), 3, ncp->finp) == 3);
68 +                        if (ncp->swapped)
69 +                                swap32((char *)nrm, 3);
70                          break;
71                  case 'd': {
72 <                                double  nrmd[3];
73 <                                ok = (getbinary(nrmd, sizeof(*nrmd),
74 <                                                3, ncp->finp) == 3);
75 <                                if (ok) VCOPY(nrm, nrmd);
76 <                        }
77 <                        break;
72 >                        double  nrmd[3];
73 >                        ok = (getbinary(nrmd, sizeof(*nrmd),
74 >                                        3, ncp->finp) == 3);
75 >                        if (ncp->swapped)
76 >                                swap64((char *)nrmd, 3);
77 >                        if (ok) VCOPY(nrm, nrmd);
78 >                        } break;
79   #else
80                  case 'f': {
81 <                                float   nrmf[3];
82 <                                ok = (getbinary(nrmf, sizeof(*nrmf),
83 <                                                3, ncp->finp) == 3);
84 <                                if (ok) VCOPY(nrm, nrmf);
85 <                        }
86 <                        break;
81 >                        float   nrmf[3];
82 >                        ok = (getbinary(nrmf, sizeof(*nrmf),
83 >                                        3, ncp->finp) == 3);
84 >                        if (ncp->swapped)
85 >                                swap32((char *)nrmf, 3);
86 >                        if (ok) VCOPY(nrm, nrmf);
87 >                        } break;
88                  case 'd':
89                          ok = (getbinary(nrm, sizeof(*nrm), 3, ncp->finp) == 3);
90 +                        if (ncp->swapped)
91 +                                swap64((char *)nrm, 3);
92                          break;
93   #endif
94                  }
# Line 183 | Line 189 | pixel_normals(NORMCODEC *ncp, int unbuf)
189                  fputs(": can only handle standard pixel ordering\n", stderr);
190                  return 0;
191          }
192 +
193          while (scanf("%d %d", &x, &y) == 2) {
194  
195                  y = ncp->res.yr-1 - y;
# Line 210 | Line 217 | pixel_normals(NORMCODEC *ncp, int unbuf)
217   int
218   main(int argc, char *argv[])
219   {
220 +        int             xres=0, yres=0;
221          int             reverse = 0;
222          int             bypixel = 0;
223          int             unbuffered = 0;
224          NORMCODEC       nc;
225          int             a;
226 <
227 <        progname = argv[0];
226 >                                        /* set global progname */
227 >        fixargv0(argv[0]);
228          set_nc_defaults(&nc);
229          nc.hdrflags = HF_ALL;
230          for (a = 1; a < argc && argv[a][0] == '-'; a++)
# Line 271 | Line 279 | main(int argc, char *argv[])
279                                  usage_exit(1);
280                          }
281                          break;
282 +                case 'x':
283 +                        xres = atoi(argv[++a]);
284 +                        break;
285 +                case 'y':
286 +                        yres = atoi(argv[++a]);
287 +                        break;
288                  case 'i':
289                          bypixel++;
290                          break;
# Line 282 | Line 296 | main(int argc, char *argv[])
296                  }
297          nc.hdrflags |= !reverse * HF_ENCODE;
298  
299 <        if ((nc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
299 >        if ((xres > 0) & (yres > 0)) {
300 >                nc.hdrflags &= ~HF_RESIN;
301 >                nc.res.rt = PIXSTANDARD;
302 >                nc.res.xr = xres;
303 >                nc.res.yr = yres;
304 >        } else if ((nc.hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESOUT) {
305                  fputs(progname, stderr);
306                  fputs(": unknown resolution for output\n", stderr);
307                  return 1;
# Line 321 | Line 340 | main(int argc, char *argv[])
340                  fputs(": cannot open for writing\n", stderr);
341                  return 1;
342          }
343 <        SET_FILE_BINARY(nc.finp);
344 <        if (reverse || nc.format != 'a')
326 <                SET_FILE_BINARY(stdout);
343 >        SET_FILE_BINARY(nc.finp);       /* starting assumption */
344 >        SET_FILE_BINARY(stdout);
345   #ifdef getc_unlocked                    /* avoid stupid semaphores */
346          flockfile(nc.finp);
347          flockfile(stdout);
# Line 331 | Line 349 | main(int argc, char *argv[])
349                                          /* read/copy header */
350          if (!process_nc_header(&nc, a, argv))
351                  return 1;
352 +
353 +        if (reverse && nc.format == 'a')
354 +                SET_FILE_TEXT(stdout);
355                                          /* process data */
356          if (!reverse) {
357                  if (!encode_normals(&nc))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines