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.3 by greg, Wed Aug 14 21:00:14 2019 UTC vs.
Revision 2.7 by greg, Wed Aug 24 19:55:58 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 58 | Line 57 | process_nc_header(NORMCODEC *ncp, int ac, char *av[])
57                  }
58                  return 0;
59          }
60 +                                        /* get resolution string? */
61 +        if (ncp->hdrflags & HF_RESIN && !fgetsresolu(&ncp->res, ncp->finp)) {
62 +                if (ncp->hdrflags & HF_STDERR) {
63 +                        fputs(ncp->inpname, stderr);
64 +                        fputs(": bad resolution string\n", stderr);
65 +                }
66 +                return 0;
67 +        }
68          if (ncp->hdrflags & HF_HEADOUT) {       /* finish header */
69                  if (!(ncp->hdrflags & HF_HEADIN))
70                          newheader("RADIANCE", stdout);
# Line 65 | Line 72 | process_nc_header(NORMCODEC *ncp, int ac, char *av[])
72                          printargs(ac, av, stdout);
73                  if (ncp->hdrflags & HF_ENCODE) {
74                          fputformat(NORMAL32FMT, stdout);
75 <                } else
75 >                } else {
76 >                        fputs("NCOMP=3\n", stdout);
77 >                        if ((ncp->hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESIN)
78 >                                printf("NCOLS=%d\nNROWS=%d\n",
79 >                                                scanlen(&ncp->res),
80 >                                                numscans(&ncp->res));
81                          switch (ncp->format) {
82                          case 'a':
83                                  fputformat("ascii", stdout);
# Line 79 | Line 91 | process_nc_header(NORMCODEC *ncp, int ac, char *av[])
91                                  fputformat("double", stdout);
92                                  break;
93                          }
94 +                }
95                  fputc('\n', stdout);
96          }
97 <                                        /* 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)
97 >        if (ncp->hdrflags & HF_RESOUT)  /* put resolution string? */
98                  fputsresolu(&ncp->res, stdout);
99  
100 <        ncp->dstart = ncp->curpos = ftell(ncp->finp);
100 >        ncp->dstart = ftell(ncp->finp);
101          return 1;
102   }
103  
# Line 125 | Line 130 | check_decode_normals(NORMCODEC *ncp)
130   int
131   decode_normal_next(FVECT nrm, NORMCODEC *ncp)
132   {
133 <        int32   c = getint(4, ncp->finp);
133 >        static int32    lastc;
134 >        static FVECT    lastv;
135 >        int32           c = getint(4, ncp->finp);
136  
137          if (c == EOF && feof(ncp->finp))
138                  return -1;
139  
140 <        ncp->curpos += 4;
141 <
142 <        decodedir(nrm, c);
143 <
140 >        if (c == lastc) {                       /* optimization */
141 >                VCOPY(nrm, lastv);
142 >        } else {
143 >                decodedir(nrm, c);
144 >                if (c) {
145 >                        lastc = c;
146 >                        VCOPY(lastv, nrm);
147 >                }
148 >        }
149          return (c != 0);
150   }
151  
# Line 142 | Line 154 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
154   int
155   seek_nc_pix(NORMCODEC *ncp, int x, int y)
156   {
145        long    seekpos;
146
157          if ((ncp->res.xr <= 0) | (ncp->res.yr <= 0)) {
158                  if (ncp->hdrflags & HF_STDERR) {
159                          fputs(progname, stderr);
# Line 159 | Line 169 | seek_nc_pix(NORMCODEC *ncp, int x, int y)
169                  }
170                  return 0;
171          }
172 <        seekpos = ncp->dstart + 4*((long)y*scanlen(&ncp->res) + x);
173 <
164 <        if (seekpos != ncp->curpos &&
165 <                        fseek(ncp->finp, seekpos, SEEK_SET) == EOF) {
172 >        if (fseek(ncp->finp, ncp->dstart + 4*((long)y*scanlen(&ncp->res) + x),
173 >                        SEEK_SET) == EOF) {
174                  if (ncp->hdrflags & HF_STDERR) {
175                          fputs(ncp->inpname, stderr);
176                          fputs(": seek error\n", stderr);
177                  }
178                  return -1;
179          }
172        ncp->curpos = seekpos;
180          return 1;
181   }
182  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines