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

Comparing ray/src/rt/ambio.c (file contents):
Revision 2.4 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.16 by greg, Mon Dec 11 23:57:32 2023 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  Declarations of external symbols in ambient.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
10 > #include "copyright.h"
11  
12   #include "ray.h"
68
13   #include "ambient.h"
14  
15  
16 < #define  putvec(v,fp)   putflt((v)[0],fp);putflt((v)[1],fp);putflt((v)[2],fp)
16 > int     *AMB_CNDX = CNDX;       /* open ambient file RGBE indices */
17 > float   *AMB_WLPART = WLPART;   /* open ambient file limits+partitions (nm) */
18  
74 #define  getvec(v,fp)   (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp)
19  
20 < #define  badflt(x)      ((x) < -FHUGE || (x) > FHUGE)
20 > #define  badflt(x)      (((x) < -FHUGE) | ((x) > FHUGE))
21  
22 < #define  badvec(v)      (badflt((v)[0]) || badflt((v)[1]) || badflt((v)[2]))
22 > #define  badvec(v)      (badflt((v)[0]) | badflt((v)[1]) | badflt((v)[2]))
23  
24  
25 + int
26 + amb_headline(           /* check ambient headline (copy to file if *p) */
27 +        char *hl,
28 +        void *p
29 + )
30 + {
31 +        static int      ambcndx[4];
32 +        static float    ambwlpart[4];
33 +        FILE            *fout = (FILE *)p;
34 +        char            fmt[MAXFMTLEN];
35  
36 +        if (formatval(fmt, hl)) {
37 +                if (strcmp(fmt, AMBFMT))
38 +                        return(-1);
39 +                return(0);
40 +        }
41 +        if (isncomp(hl)) {
42 +                ambcndx[3] = ncompval(hl);
43 +                if ((ambcndx[3] < 3) | (ambcndx[3] > MAXCSAMP))
44 +                        return(-1);
45 +                AMB_CNDX = ambcndx;
46 +                return(1);
47 +        }
48 +        if (iswlsplit(hl)) {
49 +                if (!wlsplitval(ambwlpart, hl))
50 +                        return(-1);
51 +                AMB_WLPART = ambwlpart;
52 +                return(1);
53 +        }
54 +        if (fout)
55 +                fputs(hl, fout);
56 +        return(0);
57 + }
58 +
59 +
60   void
61   putambmagic(fp)                 /* write out ambient value magic number */
62   FILE  *fp;
63   {
64 <        putint((long)AMBMAGIC, 2, fp);
64 >        putint(AMBMAGIC, 2, fp);
65   }
66  
67  
# Line 91 | Line 69 | int
69   hasambmagic(fp)                 /* read in and check validity of magic # */
70   FILE  *fp;
71   {
72 <        register int  magic;
72 >        int  magic;
73  
74          magic = getint(2, fp);
75          if (feof(fp))
# Line 100 | Line 78 | FILE  *fp;
78   }
79  
80  
81 + #define  putpos(v,fp)   putflt((v)[0],fp);putflt((v)[1],fp);putflt((v)[2],fp)
82 +
83 + #define  getpos(v,fp)   (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp)
84 +
85 + #define  putv2(v2,fp)   putflt((v2)[0],fp);putflt((v2)[1],fp)
86 +
87 + #define  getv2(v2,fp)   (v2)[0]=getflt(fp);(v2)[1]=getflt(fp)
88 +
89   int
90 < writambval(av, fp)              /* write ambient value to stream */
91 < register AMBVAL  *av;
92 < FILE  *fp;
90 > writambval(                     /* write ambient value to stream */
91 >        AMBVAL  *av,
92 >        FILE  *fp
93 > )
94   {
95 <        COLR  col;
95 >        SCOLR  sclr;
96  
97 <        putint((long)av->lvl, 1, fp);
97 >        putint(av->lvl, 1, fp);
98          putflt(av->weight, fp);
99 <        putvec(av->pos, fp);
100 <        putvec(av->dir, fp);
101 <        setcolr(col, colval(av->val,RED),
102 <                        colval(av->val,GRN), colval(av->val,BLU));
103 <        fwrite((char *)col, sizeof(col), 1, fp);
104 <        putflt(av->rad, fp);
105 <        putvec(av->gpos, fp);
106 <        putvec(av->gdir, fp);
99 >        putpos(av->pos, fp);
100 >        putint(av->ndir, sizeof(av->ndir), fp);
101 >        putint(av->udir, sizeof(av->udir), fp);
102 >        putv2(av->rad, fp);
103 >        putv2(av->gpos, fp);
104 >        putv2(av->gdir, fp);
105 >        putint(av->corral, sizeof(av->corral), fp);
106 >        if ((AMB_CNDX == CNDX) & (AMB_WLPART == WLPART)) {
107 >                scolor_scolr(sclr, av->val);
108 >        } else {
109 >                SCOLOR  scol;
110 >                convertscolor(scol, AMB_CNDX[3], AMB_WLPART[0], AMB_WLPART[3],
111 >                                av->val, NCSAMP, WLPART[0], WLPART[3]);
112 >                scolor2scolr(sclr, scol, AMB_CNDX[3]);
113 >        }
114 >        putbinary(sclr, AMB_CNDX[3]+1, 1, fp);
115 >
116          return(ferror(fp) ? -1 : 0);
117   }
118  
119  
120   int
121 < ambvalOK(av)                    /* check consistency of ambient value */
122 < register AMBVAL  *av;
121 > ambvalOK(                       /* check consistency of ambient value */
122 >        AMBVAL  *av
123 > )
124   {
125 <        double  d;
125 >        int     i;
126  
127          if (badvec(av->pos)) return(0);
128 <        if (badvec(av->dir)) return(0);
129 <        d = DOT(av->dir,av->dir);
130 <        if (d < 0.9999 || d > 1.0001) return(0);
131 <        if (av->lvl < 0 || av->lvl > 100) return(0);
132 <        if (av->weight <= 0. || av->weight > 1.) return(0);
133 <        if (av->rad <= 0. || av->rad >= FHUGE) return(0);
134 <        if (colval(av->val,RED) < 0. ||
135 <                        colval(av->val,RED) > FHUGE ||
136 <                        colval(av->val,GRN) < 0. ||
137 <                        colval(av->val,GRN) > FHUGE ||
141 <                        colval(av->val,BLU) < 0. ||
142 <                        colval(av->val,BLU) > FHUGE) return(0);
143 <        if (badvec(av->gpos)) return(0);
144 <        if (badvec(av->gdir)) return(0);
128 >        if (!av->ndir | !av->udir) return(0);
129 >        if ((av->weight <= 0.) | (av->weight > 1.)) return(0);
130 >        if ((av->rad[0] <= 0.) | (av->rad[0] >= FHUGE)) return(0);
131 >        if ((av->rad[1] <= 0.) | (av->rad[1] >= FHUGE)) return(0);
132 >        if (av->rad[0] > av->rad[1]+FTINY) return(0);
133 >        if (badflt(av->gpos[0]) | badflt(av->gpos[1])) return(0);
134 >        if (badflt(av->gdir[0]) | badflt(av->gdir[1])) return(0);
135 >        for (i = NCSAMP; i-- > 0; )
136 >                if ((av->val[i] < 0.) | (av->val[i] >= FHUGE))
137 >                        return(0);
138          return(1);
139   }
140  
141  
142   int
143 < readambval(av, fp)              /* read ambient value from stream */
144 < register AMBVAL  *av;
145 < FILE  *fp;
143 > readambval(                     /* read ambient value from stream */
144 >        AMBVAL  *av,
145 >        FILE  *fp
146 > )
147   {
148 <        COLR  col;
148 >        SCOLR  sclr;
149  
150 <        av->lvl = getint(1, fp);
150 >        av->lvl = getint(1, fp) & 0xff;
151          if (feof(fp))
152                  return(0);
153          av->weight = getflt(fp);
154 <        getvec(av->pos, fp);
155 <        getvec(av->dir, fp);
156 <        if (fread((char *)col, sizeof(col), 1, fp) != 1)
154 >        getpos(av->pos, fp);
155 >        av->ndir = getint(sizeof(av->ndir), fp);
156 >        av->udir = getint(sizeof(av->udir), fp);
157 >        getv2(av->rad, fp);
158 >        getv2(av->gpos, fp);
159 >        getv2(av->gdir, fp);
160 >        av->corral = (uint32)getint(sizeof(av->corral), fp);
161 >        if (getbinary(sclr, AMB_CNDX[3]+1, 1, fp) != 1)
162                  return(0);
163 <        colr_color(av->val, col);
164 <        av->rad = getflt(fp);
165 <        getvec(av->gpos, fp);
166 <        getvec(av->gdir, fp);
163 >        if ((AMB_CNDX == CNDX) & (AMB_WLPART == WLPART)) {
164 >                scolr_scolor(av->val, sclr);
165 >        } else {
166 >                SCOLOR  scol;
167 >                scolr2scolor(scol, sclr, AMB_CNDX[3]);
168 >                convertscolor(av->val, NCSAMP, WLPART[0], WLPART[3],
169 >                                scol, AMB_CNDX[3], AMB_WLPART[0], AMB_WLPART[3]);
170 >        }
171          return(feof(fp) ? 0 : ambvalOK(av));
172   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines