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.15 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.29 by greg, Tue May 12 16:37:53 2009 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  data.c - routines dealing with interpolated data.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10 < #include  "standard.h"
10 > #include  <time.h>
11  
12 + #include  "platform.h"
13 + #include  "paths.h"
14 + #include  "standard.h"
15   #include  "color.h"
68
16   #include  "resolu.h"
17 <
17 > #include  "view.h"
18   #include  "data.h"
19  
20                                  /* picture memory usage before warning */
21   #ifndef PSIZWARN
22 < #ifdef BIGMEM
23 < #define PSIZWARN        5000000
22 > #ifdef SMLMEM
23 > #define PSIZWARN        3000000
24   #else
25 < #define PSIZWARN        1500000
25 > #define PSIZWARN        10000000
26   #endif
27   #endif
28  
# Line 88 | Line 35 | static const char      RCSid[] = "$Id$";
35  
36   static DATARRAY  *dtab[TABSIZ];         /* data array list */
37  
38 + static gethfunc headaspect;
39  
40 < DATARRAY *
41 < getdata(dname)                          /* get data array dname */
42 < char  *dname;
40 >
41 > extern DATARRAY *
42 > getdata(                                /* get data array dname */
43 >        char  *dname
44 > )
45   {
46          char  *dfname;
47          FILE  *fp;
# Line 122 | Line 72 | char  *dname;
72           *              0 0 ni p0i p1i .. pni
73           */
74  
75 <        if ((dfname = getpath(dname, getlibpath(), R_OK)) == NULL) {
75 >        if ((dfname = getpath(dname, getrlibpath(), R_OK)) == NULL) {
76                  sprintf(errmsg, "cannot find data file \"%s\"", dname);
77                  error(USER, errmsg);
78          }
# Line 133 | Line 83 | char  *dname;
83                                                          /* get dimensions */
84          if (fgetval(fp, 'i', (char *)&asize) <= 0)
85                  goto scanerr;
86 <        if (asize <= 0 | asize > MAXDDIM) {
86 >        if ((asize <= 0) | (asize > MAXDDIM)) {
87                  sprintf(errmsg, "bad number of dimensions for \"%s\"", dname);
88                  error(USER, errmsg);
89          }
# Line 189 | Line 139 | scanerr:
139          sprintf(errmsg, "%s in data file \"%s\"",
140                          feof(fp) ? "unexpected EOF" : "bad format", dfname);
141          error(USER, errmsg);
142 +        return NULL; /* pro forma return */
143   }
144  
145  
146   static int
147 < headaspect(s, iap)                      /* check string for aspect ratio */
148 < char  *s;
149 < double  *iap;
147 > headaspect(                     /* check string for aspect ratio */
148 >        char  *s,
149 >        void  *iap
150 > )
151   {
152          char    fmt[32];
153  
154          if (isaspect(s))
155 <                *iap *= aspectval(s);
155 >                *(double*)iap *= aspectval(s);
156          else if (formatval(fmt, s) && !globmatch(PICFMT, fmt))
157 <                *iap = 0.0;
157 >                *(double*)iap = 0.0;
158          return(0);
159   }
160  
161  
162 < DATARRAY *
163 < getpict(pname)                          /* get picture pname */
164 < char  *pname;
162 > extern DATARRAY *
163 > getpict(                                /* get picture pname */
164 >        char  *pname
165 > )
166   {
167          double  inpaspect;
168          char  *pfname;
# Line 217 | Line 170 | char  *pname;
170          COLR  *scanin;
171          int  sl, ns;
172          RESOLU  inpres;
173 <        FLOAT  loc[2];
173 >        RREAL  loc[2];
174          int  y;
175          register int  x, i;
176          register DATARRAY  *pp;
# Line 226 | Line 179 | char  *pname;
179                  if (!strcmp(pname, pp->name))
180                          return(pp);             /* found! */
181  
182 <        if ((pfname = getpath(pname, getlibpath(), R_OK)) == NULL) {
182 >        if ((pfname = getpath(pname, getrlibpath(), R_OK)) == NULL) {
183                  sprintf(errmsg, "cannot find picture file \"%s\"", pname);
184                  error(USER, errmsg);
185          }
# Line 239 | Line 192 | char  *pname;
192                  sprintf(errmsg, "cannot open picture file \"%s\"", pfname);
193                  error(SYSTEM, errmsg);
194          }
195 < #ifdef MSDOS
243 <        setmode(fileno(fp), O_BINARY);
244 < #endif
195 >        SET_FILE_BINARY(fp);
196                                                  /* get dimensions */
197          inpaspect = 1.0;
198 <        getheader(fp, headaspect, (char *)&inpaspect);
198 >        getheader(fp, headaspect, &inpaspect);
199          if (inpaspect <= FTINY || !fgetsresolu(&inpres, fp))
200                  goto readerr;
201          pp[0].nd = 2;
# Line 267 | Line 218 | char  *pname;
218          i = ns*sl*sizeof(COLR);
219   #if PSIZWARN
220          if (i > PSIZWARN) {                             /* memory warning */
221 <                sprintf(errmsg, "picture file \"%s\" using %d bytes of memory",
222 <                                pname, i);
221 >                sprintf(errmsg, "picture file \"%s\" using %.1f MB of memory",
222 >                                pname, i*(1.0/(1024*1024)));
223                  error(WARNING, errmsg);
224          }
225   #endif
# Line 291 | Line 242 | char  *pname;
242          fclose(fp);
243          i = hash(pname);
244          pp[0].next = dtab[i];           /* link into picture list */
245 <        copystruct(&pp[1], &pp[0]);
246 <        copystruct(&pp[2], &pp[0]);
245 >        pp[1] = pp[0];
246 >        pp[2] = pp[0];
247          pp[0].type = RED;               /* differentiate RGB records */
248          pp[1].type = GRN;
249          pp[2].type = BLU;
# Line 303 | Line 254 | memerr:
254   readerr:
255          sprintf(errmsg, "bad picture file \"%s\"", pfname);
256          error(USER, errmsg);
257 +        return NULL; /* pro forma return */
258   }
259  
260  
261 < void
262 < freedata(dta)                   /* release data array reference */
263 < DATARRAY  *dta;
261 > extern void
262 > freedata(                       /* release data array reference */
263 >        DATARRAY  *dta
264 > )
265   {
266          DATARRAY  head;
267          int  hval, nents;
# Line 324 | Line 277 | DATARRAY  *dta;
277                  head.next = dtab[hval];
278                  dpl = &head;
279                  while ((dp = dpl->next) != NULL)
280 <                        if ((dta == NULL | dta == dp)) {
280 >                        if ((dta == NULL) | (dta == dp)) {
281                                  dpl->next = dp->next;
282                                  if (dp->type == DATATY)
283                                          free((void *)dp->arr.d);
# Line 342 | Line 295 | DATARRAY  *dta;
295   }
296  
297  
298 < double
299 < datavalue(dp, pt)               /* interpolate data value at a point */
300 < register DATARRAY  *dp;
301 < double  *pt;
298 > extern double
299 > datavalue(              /* interpolate data value at a point */
300 >        register DATARRAY  *dp,
301 >        double  *pt
302 > )
303   {
304          DATARRAY  sd;
305          int  asize;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines