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.2 by greg, Sat Jul 20 02:07:23 2019 UTC vs.
Revision 2.11 by greg, Wed Jun 4 22:34:27 2025 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines