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.9 by greg, Thu Sep 22 21:47:13 2022 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines