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 2.13 by gregl, Wed Dec 3 11:06:17 1997 UTC vs.
Revision 2.26 by schorsch, Fri Jan 2 11:43:42 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  data.c - routines dealing with interpolated data.
6   */
7  
8 < #include  "standard.h"
8 > #include "copyright.h"
9  
10 < #include  "color.h"
10 > #include  <time.h>
11  
12 + #include  "platform.h"
13 + #include  "standard.h"
14 + #include  "color.h"
15   #include  "resolu.h"
16
16   #include  "data.h"
17  
18                                  /* picture memory usage before warning */
19   #ifndef PSIZWARN
20 < #ifdef BIGMEM
22 < #define PSIZWARN        5000000
23 < #else
20 > #ifdef SMLMEM
21   #define PSIZWARN        1500000
22 + #else
23 + #define PSIZWARN        5000000
24   #endif
25   #endif
26  
# Line 32 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31   #define hash(s)         (shash(s)%TABSIZ)
32  
33  
35 extern char  *getlibpath();             /* library search path */
36
34   static DATARRAY  *dtab[TABSIZ];         /* data array list */
35  
36 + static gethfunc headaspect;
37  
38 +
39   DATARRAY *
40   getdata(dname)                          /* get data array dname */
41   char  *dname;
# Line 50 | Line 49 | char  *dname;
49          for (dp = dtab[hash(dname)]; dp != NULL; dp = dp->next)
50                  if (!strcmp(dname, dp->name))
51                          return(dp);             /* found! */
53
52          /*
53           *      If we haven't loaded the data already, we will look
54           *  for it in the directories specified by the library path.
# Line 71 | Line 69 | char  *dname;
69           *              0 0 ni p0i p1i .. pni
70           */
71  
72 <        if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) {
72 >        if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) {
73                  sprintf(errmsg, "cannot find data file \"%s\"", dname);
74                  error(USER, errmsg);
75          }
# Line 80 | Line 78 | char  *dname;
78                  error(SYSTEM, errmsg);
79          }
80                                                          /* get dimensions */
81 <        if (fgetval(fp, 'i', &asize) <= 0)
81 >        if (fgetval(fp, 'i', (char *)&asize) <= 0)
82                  goto scanerr;
83 <        if (asize <= 0 | asize > MAXDDIM) {
83 >        if ((asize <= 0) | (asize > MAXDDIM)) {
84                  sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
85                  error(USER, errmsg);
86          }
# Line 93 | Line 91 | char  *dname;
91          dp->nd = asize;
92          asize = 1;
93          for (i = 0; i < dp->nd; i++) {
94 <                if (fgetval(fp, DATATY, &dp->dim[i].org) <= 0)
94 >                if (fgetval(fp, DATATY, (char *)&dp->dim[i].org) <= 0)
95                          goto scanerr;
96 <                if (fgetval(fp, DATATY, &dp->dim[i].siz) <= 0)
96 >                if (fgetval(fp, DATATY, (char *)&dp->dim[i].siz) <= 0)
97                          goto scanerr;
98 <                if (fgetval(fp, 'i', &dp->dim[i].ne) <= 0)
98 >                if (fgetval(fp, 'i', (char *)&dp->dim[i].ne) <= 0)
99                          goto scanerr;
100                  if (dp->dim[i].ne < 2)
101                          goto scanerr;
# Line 108 | Line 106 | char  *dname;
106                          if (dp->dim[i].p == NULL)
107                                  goto memerr;
108                          for (j = 0; j < dp->dim[i].ne; j++)
109 <                                if (fgetval(fp, DATATY, &dp->dim[i].p[j]) <= 0)
109 >                                if (fgetval(fp, DATATY,
110 >                                                (char *)&dp->dim[i].p[j]) <= 0)
111                                          goto scanerr;
112                          for (j = 1; j < dp->dim[i].ne-1; j++)
113                                  if ((dp->dim[i].p[j-1] < dp->dim[i].p[j]) !=
# Line 124 | Line 123 | char  *dname;
123                  goto memerr;
124          
125          for (i = 0; i < asize; i++)
126 <                if (fgetval(fp, DATATY, &dp->arr.d[i]) <= 0)
126 >                if (fgetval(fp, DATATY, (char *)&dp->arr.d[i]) <= 0)
127                          goto scanerr;
128          fclose(fp);
129          i = hash(dname);
# Line 140 | Line 139 | scanerr:
139   }
140  
141  
142 < static
143 < headaspect(s, iap)                      /* check string for aspect ratio */
144 < char  *s;
145 < double  *iap;
142 > static int
143 > headaspect(                     /* check string for aspect ratio */
144 >        char  *s,
145 >        void  *iap
146 > )
147   {
148 +        char    fmt[32];
149 +
150          if (isaspect(s))
151 <                *iap *= aspectval(s);
151 >                *(double*)iap *= aspectval(s);
152 >        else if (formatval(fmt, s) && !globmatch(PICFMT, fmt))
153 >                *(double*)iap = 0.0;
154 >        return(0);
155   }
156  
157  
# Line 160 | Line 165 | char  *pname;
165          COLR  *scanin;
166          int  sl, ns;
167          RESOLU  inpres;
168 <        FLOAT  loc[2];
168 >        RREAL  loc[2];
169          int  y;
170          register int  x, i;
171          register DATARRAY  *pp;
# Line 169 | Line 174 | char  *pname;
174                  if (!strcmp(pname, pp->name))
175                          return(pp);             /* found! */
176  
177 <        if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) {
177 >        if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) {
178                  sprintf(errmsg, "cannot find picture file \"%s\"", pname);
179                  error(USER, errmsg);
180          }
# Line 182 | Line 187 | char  *pname;
187                  sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
188                  error(SYSTEM, errmsg);
189          }
190 < #ifdef MSDOS
186 <        setmode(fileno(fp), O_BINARY);
187 < #endif
190 >        SET_FILE_BINARY(fp);
191                                                  /* get dimensions */
192          inpaspect = 1.0;
193          getheader(fp, headaspect, &inpaspect);
194 <        if (!fgetsresolu(&inpres, fp))
194 >        if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp))
195                  goto readerr;
196          pp[0].nd = 2;
197          pp[0].dim[0].ne = inpres.yr;
# Line 230 | Line 233 | char  *pname;
233                          copycolr(pp[0].arr.c[i], scanin[x]);
234                  }
235          }
236 <        free((char *)scanin);
236 >        free((void *)scanin);
237          fclose(fp);
238          i = hash(pname);
239          pp[0].next = dtab[i];           /* link into picture list */
240 <        copystruct(&pp[1], &pp[0]);
241 <        copystruct(&pp[2], &pp[0]);
240 >        pp[1] = pp[0];
241 >        pp[2] = pp[0];
242          pp[0].type = RED;               /* differentiate RGB records */
243          pp[1].type = GRN;
244          pp[2].type = BLU;
# Line 249 | Line 252 | readerr:
252   }
253  
254  
255 < freedata(dname)                 /* free memory associated with dname */
256 < char  *dname;
255 > void
256 > freedata(dta)                   /* release data array reference */
257 > DATARRAY  *dta;
258   {
259          DATARRAY  head;
260          int  hval, nents;
261 <        register DATARRAY  *dp, *dpl;
261 >        register DATARRAY  *dpl, *dp;
262          register int  i;
263  
264 <        if (dname == NULL) {                    /* free all if NULL */
264 >        if (dta == NULL) {                      /* free all if NULL */
265                  hval = 0; nents = TABSIZ;
266          } else {
267 <                hval = hash(dname); nents = 1;
267 >                hval = hash(dta->name); nents = 1;
268          }
269          while (nents--) {
270                  head.next = dtab[hval];
271                  dpl = &head;
272                  while ((dp = dpl->next) != NULL)
273 <                        if (dname == NULL || !strcmp(dname, dp->name)) {
273 >                        if ((dta == NULL) | (dta == dp)) {
274                                  dpl->next = dp->next;
275                                  if (dp->type == DATATY)
276 <                                        free((char *)dp->arr.d);
276 >                                        free((void *)dp->arr.d);
277                                  else
278 <                                        free((char *)dp->arr.c);
278 >                                        free((void *)dp->arr.c);
279                                  for (i = 0; i < dp->nd; i++)
280                                          if (dp->dim[i].p != NULL)
281 <                                                free((char *)dp->dim[i].p);
281 >                                                free((void *)dp->dim[i].p);
282                                  freestr(dp->name);
283 <                                free((char *)dp);
283 >                                free((void *)dp);
284                          } else
285                                  dpl = dp;
286                  dtab[hval++] = head.next;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines