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.2 by greg, Fri Jul 26 17:04:12 2019 UTC vs.
Revision 2.8 by greg, Thu Sep 22 21:45:28 2022 UTC

# Line 30 | Line 30 | static int
30   headline(char *s, void *p)
31   {
32          NORMCODEC       *ncp = (NORMCODEC *)p;
33 +        int             rv;
34  
35          if (formatval(ncp->inpfmt, s))  /* don't pass format */
36                  return 0;
37  
38 +        if ((rv = isbigendian(s)) >= 0) {
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 52 | 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 59 | 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);
104                                  break;
105                          case 'f':
106 +                                fputendian(stdout);
107                                  fputformat("float", stdout);
108                                  break;
109                          case 'd':
110 +                                fputendian(stdout);
111                                  fputformat("double", stdout);
112                                  break;
113                          }
114 +                }
115                  fputc('\n', stdout);
116          }
117 <                                        /* get/put resolution string */
77 <        if (ncp->hdrflags & HF_RESIN && !fgetsresolu(&ncp->res, ncp->finp)) {
78 <                if (ncp->hdrflags & HF_STDERR) {
79 <                        fputs(ncp->inpname, stderr);
80 <                        fputs(": bad resolution string\n", stderr);
81 <                }
82 <                return 0;
83 <        }
84 <        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 117 | Line 150 | check_decode_normals(NORMCODEC *ncp)
150   int
151   decode_normal_next(FVECT nrm, NORMCODEC *ncp)
152   {
153 <        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  
160 <        ncp->curpos += 4;
161 <
162 <        decodedir(nrm, c);
163 <
160 >        if (c == lastc) {                       /* optimization */
161 >                VCOPY(nrm, lastv);
162 >        } else {
163 >                decodedir(nrm, c);
164 >                if (c) {
165 >                        lastc = c;
166 >                        VCOPY(lastv, nrm);
167 >                }
168 >        }
169          return (c != 0);
170   }
171  
# Line 134 | Line 174 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
174   int
175   seek_nc_pix(NORMCODEC *ncp, int x, int y)
176   {
137        long    seekpos;
138
177          if ((ncp->res.xr <= 0) | (ncp->res.yr <= 0)) {
178                  if (ncp->hdrflags & HF_STDERR) {
179                          fputs(progname, stderr);
# Line 151 | 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 <
156 <        if (seekpos != ncp->curpos &&
157 <                        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          }
164        ncp->curpos = seekpos;
200          return 1;
201   }
202  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines