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.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 39 | 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 57 | 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 64 | 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 78 | 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 */
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)
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 131 | Line 158 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
158          if (c == EOF && feof(ncp->finp))
159                  return -1;
160  
134        ncp->curpos += 4;
135
161          if (c == lastc) {                       /* optimization */
162                  VCOPY(nrm, lastv);
163          } else {
# Line 150 | Line 175 | decode_normal_next(FVECT nrm, NORMCODEC *ncp)
175   int
176   seek_nc_pix(NORMCODEC *ncp, int x, int y)
177   {
153        long    seekpos;
154
178          if ((ncp->res.xr <= 0) | (ncp->res.yr <= 0)) {
179                  if (ncp->hdrflags & HF_STDERR) {
180                          fputs(progname, stderr);
# Line 167 | 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 <
172 <        if (seekpos != ncp->curpos &&
173 <                        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          }
180        ncp->curpos = seekpos;
201          return 1;
202   }
203  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines