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

Comparing ray/src/common/normcodec.c (file contents):
Revision 2.4 by greg, Mon Aug 26 23:33:24 2019 UTC vs.
Revision 2.8 by greg, Thu Sep 22 21:45:28 2022 UTC

# Line 20 | Line 20 | set_nc_defaults(NORMCODEC *ncp)
20          ncp->finp = stdin;
21          ncp->inpname = "<stdin>";
22          ncp->format = 'a';
23        ncp->swapped = 0;
23          ncp->res.rt = PIXSTANDARD;
24          if (!progname) progname = "norm_codec";
25   }
# Line 40 | Line 39 | headline(char *s, void *p)
39                  ncp->swapped = (nativebigendian() != rv);
40                  return 0;
41          }
42 +        if (!strncmp(s, "NCOMP=", 6)) {
43 +                if (atoi(s+6) != 3) {
44 +                        if (ncp->hdrflags & HF_STDERR) {
45 +                                fputs(ncp->inpname, stderr);
46 +                                fputs(": NCOMP must equal 3\n", stderr);
47 +                        }
48 +                        return -1;
49 +                }
50 +                return 0;
51 +        }
52 +        if (!strncmp(s, "NROWS=", 6)) {
53 +                ncp->res.yr = atoi(s+6);
54 +                return 0;
55 +        }
56 +        if (!strncmp(s, "NCOLS=", 6)) {
57 +                ncp->res.xr = atoi(s+6);
58 +                return 0;
59 +        }
60          if (ncp->hdrflags & HF_HEADOUT)
61                  fputs(s, stdout);       /* copy to standard output */
62          return 1;
# Line 58 | Line 75 | process_nc_header(NORMCODEC *ncp, int ac, char *av[])
75                  }
76                  return 0;
77          }
78 +                                        /* get resolution string? */
79 +        if (ncp->hdrflags & HF_RESIN &&
80 +                        (ncp->res.xr <= 0) | (ncp->res.yr <= 0) &&
81 +                        !fgetsresolu(&ncp->res, ncp->finp)) {
82 +                if (ncp->hdrflags & HF_STDERR) {
83 +                        fputs(ncp->inpname, stderr);
84 +                        fputs(": bad resolution string\n", stderr);
85 +                }
86 +                return 0;
87 +        }
88          if (ncp->hdrflags & HF_HEADOUT) {       /* finish header */
89                  if (!(ncp->hdrflags & HF_HEADIN))
90                          newheader("RADIANCE", stdout);
# Line 65 | Line 92 | process_nc_header(NORMCODEC *ncp, int ac, char *av[])
92                          printargs(ac, av, stdout);
93                  if (ncp->hdrflags & HF_ENCODE) {
94                          fputformat(NORMAL32FMT, stdout);
95 <                } else
95 >                } else {
96 >                        fputs("NCOMP=3\n", stdout);
97 >                        if ((ncp->hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESIN)
98 >                                printf("NCOLS=%d\nNROWS=%d\n",
99 >                                                scanlen(&ncp->res),
100 >                                                numscans(&ncp->res));
101                          switch (ncp->format) {
102                          case 'a':
103                                  fputformat("ascii", stdout);
# Line 79 | Line 111 | process_nc_header(NORMCODEC *ncp, int ac, char *av[])
111                                  fputformat("double", stdout);
112                                  break;
113                          }
114 +                }
115                  fputc('\n', stdout);
116          }
117 <                                        /* get/put resolution string */
85 <        if (ncp->hdrflags & HF_RESIN && !fgetsresolu(&ncp->res, ncp->finp)) {
86 <                if (ncp->hdrflags & HF_STDERR) {
87 <                        fputs(ncp->inpname, stderr);
88 <                        fputs(": bad resolution string\n", stderr);
89 <                }
90 <                return 0;
91 <        }
92 <        if (ncp->hdrflags & HF_RESOUT)
117 >        if (ncp->hdrflags & HF_RESOUT)  /* put resolution string? */
118                  fputsresolu(&ncp->res, stdout);
119  
120 <        ncp->dstart = ncp->curpos = ftell(ncp->finp);
120 >        ncp->dstart = ftell(ncp->finp);
121          return 1;
122   }
123  
# Line 125 | Line 150 | check_decode_normals(NORMCODEC *ncp)
150   int
151   decode_normal_next(FVECT nrm, NORMCODEC *ncp)
152   {
153 <        int32   lastc;
154 <        FVECT   lastv;
155 <        int32   c = getint(4, ncp->finp);
153 >        static int32    lastc;
154 >        static FVECT    lastv;
155 >        int32           c = getint(4, ncp->finp);
156  
157          if (c == EOF && feof(ncp->finp))
158                  return -1;
159  
135        ncp->curpos += 4;
136
160          if (c == lastc) {                       /* optimization */
161                  VCOPY(nrm, lastv);
162          } else {
# Line 151 | Line 174 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
174   int
175   seek_nc_pix(NORMCODEC *ncp, int x, int y)
176   {
154        long    seekpos;
155
177          if ((ncp->res.xr <= 0) | (ncp->res.yr <= 0)) {
178                  if (ncp->hdrflags & HF_STDERR) {
179                          fputs(progname, stderr);
# Line 168 | Line 189 | seek_nc_pix(NORMCODEC *ncp, int x, int y)
189                  }
190                  return 0;
191          }
192 <        seekpos = ncp->dstart + 4*((long)y*scanlen(&ncp->res) + x);
193 <
173 <        if (seekpos != ncp->curpos &&
174 <                        fseek(ncp->finp, seekpos, SEEK_SET) == EOF) {
192 >        if (fseek(ncp->finp, ncp->dstart + 4*((long)y*scanlen(&ncp->res) + x),
193 >                        SEEK_SET) == EOF) {
194                  if (ncp->hdrflags & HF_STDERR) {
195                          fputs(ncp->inpname, stderr);
196                          fputs(": seek error\n", stderr);
197                  }
198                  return -1;
199          }
181        ncp->curpos = seekpos;
200          return 1;
201   }
202  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines