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.5 by greg, Thu Nov 7 23:20:28 2019 UTC vs.
Revision 2.8 by greg, Thu Sep 22 21:45:28 2022 UTC

# Line 39 | 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 57 | 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 64 | 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 78 | 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 */
84 <        if (ncp->hdrflags & HF_RESIN && !fgetsresolu(&ncp->res, ncp->finp)) {
85 <                if (ncp->hdrflags & HF_STDERR) {
86 <                        fputs(ncp->inpname, stderr);
87 <                        fputs(": bad resolution string\n", stderr);
88 <                }
89 <                return 0;
90 <        }
91 <        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 131 | Line 157 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
157          if (c == EOF && feof(ncp->finp))
158                  return -1;
159  
134        ncp->curpos += 4;
135
160          if (c == lastc) {                       /* optimization */
161                  VCOPY(nrm, lastv);
162          } else {
# Line 150 | Line 174 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
174   int
175   seek_nc_pix(NORMCODEC *ncp, int x, int y)
176   {
153        long    seekpos;
154
177          if ((ncp->res.xr <= 0) | (ncp->res.yr <= 0)) {
178                  if (ncp->hdrflags & HF_STDERR) {
179                          fputs(progname, stderr);
# Line 167 | 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 <
172 <        if (seekpos != ncp->curpos &&
173 <                        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          }
180        ncp->curpos = seekpos;
200          return 1;
201   }
202  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines