ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/data.c
(Generate patch)

Comparing ray/src/rt/data.c (file contents):
Revision 1.8 by greg, Tue Jan 15 22:24:19 1991 UTC vs.
Revision 2.4 by greg, Thu Nov 12 10:11:51 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "color.h"
16  
17 + #include  "resolu.h"
18 +
19   #include  "data.h"
20  
21  
22 + extern char  *fgetword();
23 +
24   extern char  *libpath;                  /* library search path */
25  
26 < static DATARRAY  *dlist = NULL;         /* data array list */
26 > static DATARRAY  *dlist = NULL;         /* data array list */
27  
28 < static DATARRAY  *plist = NULL;         /* picture list */
28 > static DATARRAY  *plist = NULL;         /* picture list */
29  
30  
31   DATARRAY *
32   getdata(dname)                          /* get data array dname */
33   char  *dname;
34   {
35 +        char  word[64];
36          char  *dfname;
37          FILE  *fp;
38          int  asize;
# Line 72 | Line 77 | char  *dname;
77                  error(SYSTEM, errmsg);
78          }
79                                                          /* get dimensions */
80 <        if (fscanf(fp, "%d", &dp->nd) != 1)
80 >        if (fgetword(word, sizeof(word), fp) == NULL || !isint(word))
81                  goto scanerr;
82 <        if (dp->nd <= 0 || dp->nd > MAXDIM) {
82 >        dp->nd = atoi(word);
83 >        if (dp->nd <= 0 || dp->nd > MAXDDIM) {
84                  sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
85                  error(USER, errmsg);
86          }
87          asize = 1;
88          for (i = 0; i < dp->nd; i++) {
89 <                if (fscanf(fp, "%lf %lf %d",
84 <                                &dp->dim[i].org, &dp->dim[i].siz,
85 <                                &dp->dim[i].ne) != 3)
89 >                if (fgetword(word, sizeof(word), fp) == NULL || !isflt(word))
90                          goto scanerr;
91 +                dp->dim[i].org = atof(word);
92 +                if (fgetword(word, sizeof(word), fp) == NULL || !isflt(word))
93 +                        goto scanerr;
94 +                dp->dim[i].siz = atof(word);
95 +                if (fgetword(word, sizeof(word), fp) == NULL || !isint(word))
96 +                        goto scanerr;
97 +                dp->dim[i].ne = atoi(word);
98                  if (dp->dim[i].ne < 2)
99                          goto scanerr;
100                  asize *= dp->dim[i].ne;
# Line 91 | Line 102 | char  *dname;
102                          dp->dim[i].p = (double *)malloc(dp->dim[i].ne*sizeof(double));
103                          if (dp->dim[i].p == NULL)
104                                  goto memerr;
105 <                        for (j = 0; j < dp->dim[i].ne; j++)
106 <                                if (fscanf(fp, "%lf", &dp->dim[i].p[j]) != 1)
105 >                        for (j = 0; j < dp->dim[i].ne; j++) {
106 >                                if (fgetword(word, sizeof(word), fp) == NULL ||
107 >                                                !isflt(word))
108                                          goto scanerr;
109 +                                dp->dim[i].p[j] = atof(word);
110 +                        }
111                          for (j = 1; j < dp->dim[i].ne-1; j++)
112                                  if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) !=
113                                          (dp->dim[i].p[j] < dp->dim[i].p[j+1]))
# Line 107 | Line 121 | char  *dname;
121          if ((dp->arr = (DATATYPE *)malloc(asize*sizeof(DATATYPE))) == NULL)
122                  goto memerr;
123          
124 <        for (i = 0; i < asize; i++)
125 <                if (fscanf(fp, DSCANF, &dp->arr[i]) != 1)
124 >        for (i = 0; i < asize; i++) {
125 >                if (fgetword(word, sizeof(word), fp) == NULL || !isflt(word))
126                          goto scanerr;
127 <        
127 >                dp->arr[i] = atof(word);
128 >        }
129          fclose(fp);
130          dp->next = dlist;
131          return(dlist = dp);
# Line 124 | Line 139 | scanerr:
139   }
140  
141  
127 static double  inpaspect;               /* aspect ratio of input picture */
128
142   static
143 < headaspect(s)                           /* check string for aspect ratio */
143 > headaspect(s, iap)                      /* check string for aspect ratio */
144   char  *s;
145 + double  *iap;
146   {
147          if (isaspect(s))
148 <                inpaspect *= aspectval(s);
148 >                *iap *= aspectval(s);
149   }
150  
151  
# Line 140 | Line 154 | getpict(pname)                         /* get picture pname */
154   char  *pname;
155   {
156          extern char  *libpath;
157 +        double  inpaspect;
158          char  *pfname;
159          FILE  *fp;
160          COLOR  *scanin;
161 <        int  width, height;
162 <        int  x, y;
163 <        register int  i;
161 >        int  sl, ns;
162 >        RESOLU  inpres;
163 >        FLOAT  loc[2];
164 >        int  y;
165 >        register int  x, i;
166          register DATARRAY  *pp;
167                                                  /* look for array in list */
168          for (pp = plist; pp != NULL; pp = pp->next)
# Line 167 | Line 184 | char  *pname;
184                  sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
185                  error(SYSTEM, errmsg);
186          }
187 + #ifdef MSDOS
188 +        setmode(fileno(fp), O_BINARY);
189 + #endif
190                                                  /* get dimensions */
191          inpaspect = 1.0;
192 <        getheader(fp, headaspect);
193 <        if (fgetresolu(&width, &height, fp) != (YMAJOR|YDECR))
192 >        getheader(fp, headaspect, &inpaspect);
193 >        if (!fgetsresolu(&inpres, fp))
194                  goto readerr;
195          for (i = 0; i < 3; i++) {
196                  pp[i].nd = 2;
197 <                pp[i].dim[0].ne = height;
198 <                pp[i].dim[1].ne = width;
197 >                pp[i].dim[0].ne = inpres.yr;
198 >                pp[i].dim[1].ne = inpres.xr;
199                  pp[i].dim[0].org =
200                  pp[i].dim[1].org = 0.0;
201 <                if (width <= height*inpaspect) {
202 <                        pp[i].dim[0].siz = inpaspect*(double)height/width;
201 >                if (inpres.xr <= inpres.yr*inpaspect) {
202 >                        pp[i].dim[0].siz = inpaspect *
203 >                                                (double)inpres.yr/inpres.xr;
204                          pp[i].dim[1].siz = 1.0;
205                  } else {
206                          pp[i].dim[0].siz = 1.0;
207 <                        pp[i].dim[1].siz = (double)width/height/inpaspect;
207 >                        pp[i].dim[1].siz = (double)inpres.xr/inpres.yr /
208 >                                                inpaspect;
209                  }
210                  pp[i].dim[0].p = pp[i].dim[1].p = NULL;
211 <                pp[i].arr = (DATATYPE *)malloc(width*height*sizeof(DATATYPE));
211 >                pp[i].arr = (DATATYPE *)
212 >                                malloc(inpres.xr*inpres.yr*sizeof(DATATYPE));
213                  if (pp[i].arr == NULL)
214                          goto memerr;
215          }
216                                                          /* load picture */
217 <        if ((scanin = (COLOR *)malloc(width*sizeof(COLOR))) == NULL)
217 >        sl = scanlen(&inpres);
218 >        ns = numscans(&inpres);
219 >        if ((scanin = (COLOR *)malloc(sl*sizeof(COLOR))) == NULL)
220                  goto memerr;
221 <        for (y = height-1; y >= 0; y--) {
222 <                if (freadscan(scanin, width, fp) < 0)
221 >        for (y = 0; y < ns; y++) {
222 >                if (freadscan(scanin, sl, fp) < 0)
223                          goto readerr;
224 <                for (x = 0; x < width; x++)
225 <                        for (i = 0; i < 3; i++)
226 <                                pp[i].arr[y*width+x] = colval(scanin[x],i);
224 >                for (x = 0; x < sl; x++) {
225 >                        pix2loc(loc, &inpres, x, y);
226 >                        i = (int)(loc[1]*inpres.yr)*inpres.xr +
227 >                                        (int)(loc[0]*inpres.xr);
228 >                        pp[0].arr[i] = colval(scanin[x],RED);
229 >                        pp[1].arr[i] = colval(scanin[x],GRN);
230 >                        pp[2].arr[i] = colval(scanin[x],BLU);
231 >                }
232          }
233          free((char *)scanin);
234          fclose(fp);
# Line 262 | Line 292 | char  *pname;
292   double
293   datavalue(dp, pt)               /* interpolate data value at a point */
294   register DATARRAY  *dp;
295 < double  *pt;
295 > double  *pt;
296   {
297          DATARRAY  sd;
298          int  asize;
299          int  lower, upper;
300          register int  i;
301 <        double  x, y, y0, y1;
301 >        double  x, y, y0, y1;
302                                          /* set up dimensions for recursion */
303          sd.nd = dp->nd - 1;
304          asize = 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines