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.2 by greg, Thu Jul 16 12:08:47 1992 UTC vs.
Revision 2.13 by greg, Tue May 14 17:39:10 2019 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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   * Read and write portable ambient values
6 + *
7 + *  Declarations of external symbols in ambient.h
8   */
9  
10 < #include <stdio.h>
10 > #include "copyright.h"
11  
12 < #include "color.h"
14 <
12 > #include "ray.h"
13   #include "ambient.h"
14  
15  
16 < #define  putvec(v,fp)   putflt((v)[0],fp);putflt((v)[1],fp);putflt((v)[2],fp)
16 > #define  badflt(x)      (((x) < -FHUGE) | ((x) > FHUGE))
17  
18 < #define  getvec(v,fp)   (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp)
18 > #define  badvec(v)      (badflt((v)[0]) | badflt((v)[1]) | badflt((v)[2]))
19  
20  
21 < extern double  getflt();
24 < extern long  getint();
25 <
26 <
21 > void
22   putambmagic(fp)                 /* write out ambient value magic number */
23   FILE  *fp;
24   {
25 <        putint((long)AMBMAGIC, 2, fp);
25 >        putint(AMBMAGIC, 2, fp);
26   }
27  
28  
29 + int
30   hasambmagic(fp)                 /* read in and check validity of magic # */
31   FILE  *fp;
32   {
33 <        register int  magic;
33 >        int  magic;
34  
35          magic = getint(2, fp);
36          if (feof(fp))
# Line 43 | Line 39 | FILE  *fp;
39   }
40  
41  
42 < writambval(av, fp)              /* write ambient value to stream */
43 < register AMBVAL  *av;
44 < FILE  *fp;
42 > #define  putpos(v,fp)   putflt((v)[0],fp);putflt((v)[1],fp);putflt((v)[2],fp)
43 >
44 > #define  getpos(v,fp)   (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp)
45 >
46 > #define  putv2(v2,fp)   putflt((v2)[0],fp);putflt((v2)[1],fp)
47 >
48 > #define  getv2(v2,fp)   (v2)[0]=getflt(fp);(v2)[1]=getflt(fp)
49 >
50 > int
51 > writambval(                     /* write ambient value to stream */
52 >        AMBVAL  *av,
53 >        FILE  *fp
54 > )
55   {
56 <        COLR  col;
56 >        COLR  clr;
57  
58 <        putint((long)av->lvl, 1, fp);
58 >        putint(av->lvl, 1, fp);
59          putflt(av->weight, fp);
60 <        putvec(av->pos, fp);
61 <        putvec(av->dir, fp);
62 <        setcolr(col, colval(av->val,RED),
60 >        putpos(av->pos, fp);
61 >        putint(av->ndir, sizeof(av->ndir), fp);
62 >        putint(av->udir, sizeof(av->udir), fp);
63 >        setcolr(clr, colval(av->val,RED),
64                          colval(av->val,GRN), colval(av->val,BLU));
65 <        fwrite((char *)col, sizeof(col), 1, fp);
66 <        putflt(av->rad, fp);
67 <        putvec(av->gpos, fp);
68 <        putvec(av->gdir, fp);
65 >        putbinary((char *)clr, sizeof(clr), 1, fp);
66 >        putv2(av->rad, fp);
67 >        putv2(av->gpos, fp);
68 >        putv2(av->gdir, fp);
69 >        putint(av->corral, sizeof(av->corral), fp);
70          return(ferror(fp) ? -1 : 0);
71   }
72  
73  
74 < readambval(av, fp)              /* read ambient value from stream */
75 < register AMBVAL  *av;
76 < FILE  *fp;
74 > int
75 > ambvalOK(                       /* check consistency of ambient value */
76 >        AMBVAL  *av
77 > )
78   {
79 <        COLR  col;
79 >        double  d;
80  
81 <        av->lvl = getint(1, fp);
81 >        if (badvec(av->pos)) return(0);
82 >        if (!av->ndir | !av->udir) return(0);
83 >        if ((av->weight <= 0.) | (av->weight > 1.)) return(0);
84 >        if ((av->rad[0] <= 0.) | (av->rad[0] >= FHUGE)) return(0);
85 >        if ((av->rad[1] <= 0.) | (av->rad[1] >= FHUGE)) return(0);
86 >        if ((colval(av->val,RED) < 0.) |
87 >                        (colval(av->val,RED) >= FHUGE) |
88 >                        (colval(av->val,GRN) < 0.) |
89 >                        (colval(av->val,GRN) >= FHUGE) |
90 >                        (colval(av->val,BLU) < 0.) |
91 >                        (colval(av->val,BLU) >= FHUGE)) return(0);
92 >        if (badflt(av->gpos[0]) || badflt(av->gpos[1])) return(0);
93 >        if (badflt(av->gdir[0]) || badflt(av->gdir[1])) return(0);
94 >        return(1);
95 > }
96 >
97 >
98 > int
99 > readambval(                     /* read ambient value from stream */
100 >        AMBVAL  *av,
101 >        FILE  *fp
102 > )
103 > {
104 >        COLR  clr;
105 >
106 >        av->lvl = getint(1, fp) & 0xff;
107          if (feof(fp))
108                  return(0);
109          av->weight = getflt(fp);
110 <        getvec(av->pos, fp);
111 <        getvec(av->dir, fp);
112 <        if (fread((char *)col, sizeof(col), 1, fp) != 1)
110 >        getpos(av->pos, fp);
111 >        av->ndir = getint(sizeof(av->ndir), fp);
112 >        av->udir = getint(sizeof(av->udir), fp);
113 >        if (getbinary((char *)clr, sizeof(clr), 1, fp) != 1)
114                  return(0);
115 <        colr_color(av->val, col);
116 <        av->rad = getflt(fp);
117 <        getvec(av->gpos, fp);
118 <        getvec(av->gdir, fp);
119 <        return(feof(fp) ? 0 : 1);
115 >        colr_color(av->val, clr);
116 >        getv2(av->rad, fp);
117 >        getv2(av->gpos, fp);
118 >        getv2(av->gdir, fp);
119 >        av->corral = (uint32)getint(sizeof(av->corral), fp);
120 >        return(feof(fp) ? 0 : ambvalOK(av));
121   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines