ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambio.c
Revision: 2.2
Committed: Thu Jul 16 12:08:47 1992 UTC (31 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +19 -0 lines
Log Message:
added header and magic number to ambient value file

File Contents

# User Rev Content
1 greg 2.1 /* Copyright (c) 1992 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Read and write portable ambient values
9     */
10    
11     #include <stdio.h>
12    
13     #include "color.h"
14    
15     #include "ambient.h"
16    
17    
18     #define putvec(v,fp) putflt((v)[0],fp);putflt((v)[1],fp);putflt((v)[2],fp)
19    
20     #define getvec(v,fp) (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp)
21    
22    
23     extern double getflt();
24     extern long getint();
25    
26    
27 greg 2.2 putambmagic(fp) /* write out ambient value magic number */
28     FILE *fp;
29     {
30     putint((long)AMBMAGIC, 2, fp);
31     }
32    
33    
34     hasambmagic(fp) /* read in and check validity of magic # */
35     FILE *fp;
36     {
37     register int magic;
38    
39     magic = getint(2, fp);
40     if (feof(fp))
41     return(0);
42     return(magic == AMBMAGIC);
43     }
44    
45    
46 greg 2.1 writambval(av, fp) /* write ambient value to stream */
47     register AMBVAL *av;
48     FILE *fp;
49     {
50     COLR col;
51    
52     putint((long)av->lvl, 1, fp);
53     putflt(av->weight, fp);
54     putvec(av->pos, fp);
55     putvec(av->dir, fp);
56     setcolr(col, colval(av->val,RED),
57     colval(av->val,GRN), colval(av->val,BLU));
58     fwrite((char *)col, sizeof(col), 1, fp);
59     putflt(av->rad, fp);
60     putvec(av->gpos, fp);
61     putvec(av->gdir, fp);
62     return(ferror(fp) ? -1 : 0);
63     }
64    
65    
66     readambval(av, fp) /* read ambient value from stream */
67     register AMBVAL *av;
68     FILE *fp;
69     {
70     COLR col;
71    
72     av->lvl = getint(1, fp);
73     if (feof(fp))
74     return(0);
75     av->weight = getflt(fp);
76     getvec(av->pos, fp);
77     getvec(av->dir, fp);
78     if (fread((char *)col, sizeof(col), 1, fp) != 1)
79     return(0);
80     colr_color(av->val, col);
81     av->rad = getflt(fp);
82     getvec(av->gpos, fp);
83     getvec(av->gdir, fp);
84     return(feof(fp) ? 0 : 1);
85     }