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

Comparing ray/src/rt/lookamb.c (file contents):
Revision 2.6 by greg, Sun Feb 27 10:17:33 1994 UTC vs.
Revision 2.18 by greg, Wed Nov 15 18:02:52 2023 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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   *  lookamb.c - program to examine ambient components.
9 *
10 *     10/8/86
6   */
7  
8 < #include  <stdio.h>
8 > #include "copyright.h"
9  
10 < #ifdef MSDOS
11 < #include  <fcntl.h>
17 < #endif
18 <
19 < #include  "color.h"
20 <
10 > #include  "platform.h"
11 > #include  "ray.h"
12   #include  "ambient.h"
13  
14  
# Line 28 | Line 19 | int  reverse = 0;
19   AMBVAL  av;
20  
21  
22 < main(argc, argv)                /* load ambient values from a file */
23 < int  argc;
24 < char  *argv[];
22 > static void
23 > lookamb(                        /* load & convert ambient values from a file */
24 >        FILE  *fp
25 > )
26   {
27 +        FVECT   norm, uvec;
28 +        COLOR   avcol;
29 +
30 +        while (readambval(&av, fp)) {
31 +                decodedir(norm, av.ndir);
32 +                decodedir(uvec, av.udir);
33 +                scolor2rgb(avcol, av.val, AMB_CNDX[3], AMB_WLPART);
34 +                if (dataonly) {
35 +                        printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
36 +                        printf("%f\t%f\t%f\t", norm[0], norm[1], norm[2]);
37 +                        printf("%f\t%f\t%f\t", uvec[0], uvec[1], uvec[2]);
38 +                        printf("%d\t%f\t%f\t%f\t", av.lvl, av.weight,
39 +                                        av.rad[0], av.rad[1]);
40 +                        printf("%e\t%e\t%e\t", colval(avcol,RED),
41 +                                                colval(avcol,GRN),
42 +                                                colval(avcol,BLU));
43 +                        printf("%f\t%f\t", av.gpos[0], av.gpos[1]);
44 +                        printf("%f\t%f\t", av.gdir[0], av.gdir[1]);
45 +                        printf("%u\n", av.corral);
46 +                } else {
47 +                        printf("Position:\t%f\t%f\t%f\n", av.pos[0],
48 +                                        av.pos[1], av.pos[2]);
49 +                        printf("Normal:\t\t%f\t%f\t%f\n",
50 +                                        norm[0], norm[1], norm[2]);
51 +                        printf("Uvector:\t%f\t%f\t%f\n",
52 +                                        uvec[0], uvec[1], uvec[2]);
53 +                        printf("Lvl,Wt,UVrad:\t%d\t\t%f\t%f\t%f\n", av.lvl,
54 +                                        av.weight, av.rad[0], av.rad[1]);
55 +                        printf("Value:\t\t%e\t%e\t%e\n", colval(avcol,RED),
56 +                                        colval(avcol,GRN), colval(avcol,BLU));
57 +                        printf("Pos.Grad:\t%f\t%f\n", av.gpos[0], av.gpos[1]);
58 +                        printf("Dir.Grad:\t%f\t%f\n", av.gdir[0], av.gdir[1]);
59 +                        printf("Corral:\t\t%8X\n\n", av.corral);
60 +                }
61 +                if (ferror(stdout))
62 +                        exit(1);
63 +        }
64 + }
65 +
66 +
67 + static void
68 + writamb(                        /* write binary ambient values to stdout */
69 +        FILE  *fp
70 + )
71 + {
72 +        FVECT   norm;
73 +        COLOR   avcol;
74 +
75 +        for ( ; ; ) {
76 +                if (!dataonly)
77 +                        fscanf(fp, "%*s");
78 +                if (fscanf(fp, "%f %f %f",
79 +                                &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
80 +                        return;
81 +                if (!dataonly)
82 +                        fscanf(fp, "%*s");
83 +                if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3)
84 +                        return;
85 +                av.ndir = encodedir(norm);
86 +                if (!dataonly)
87 +                        fscanf(fp, "%*s");
88 +                if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3)
89 +                        return;
90 +                av.udir = encodedir(norm);
91 +                if (!dataonly)
92 +                        fscanf(fp, "%*s");
93 +                if (fscanf(fp, "%hd %f %f %f", &av.lvl, &av.weight,
94 +                                &av.rad[0], &av.rad[1]) != 4)
95 +                        return;
96 +                if (!dataonly)
97 +                        fscanf(fp, "%*s");
98 +                if (fscanf(fp, "%f %f %f",
99 +                                &avcol[RED], &avcol[GRN], &avcol[BLU]) != 3)
100 +                        return;
101 +                setscolor(av.val, avcol[RED], avcol[GRN], avcol[BLU]);
102 +                if (!dataonly)
103 +                        fscanf(fp, "%*s");
104 +                if (fscanf(fp, "%f %f", &av.gpos[0], &av.gpos[1]) != 2)
105 +                        return;
106 +                if (!dataonly)
107 +                        fscanf(fp, "%*s");
108 +                if (fscanf(fp, "%f %f", &av.gdir[0], &av.gdir[1]) != 2)
109 +                        return;
110 +                if (dataonly) {
111 +                        if (fscanf(fp, "%u", &av.corral) != 1)
112 +                                return;
113 +                } else if (fscanf(fp, "%*s %X", &av.corral) != 1)
114 +                        return;
115 +                av.next = NULL;
116 +                if (writambval(&av, stdout) < 0)
117 +                        exit(1);
118 +        }
119 + }
120 +
121 +
122 + int
123 + main(           /* load ambient values from a file */
124 +        int  argc,
125 +        char  *argv[]
126 + )
127 + {
128          FILE  *fp;
129          int  i;
130  
# Line 62 | Line 155 | char  *argv[];
155                  return(1);
156          }
157          if (reverse) {
158 +                SET_FILE_BINARY(stdout);
159                  if (header) {
160                          if (checkheader(fp, "ascii", stdout) < 0)
161                                  goto formaterr;
# Line 69 | Line 163 | char  *argv[];
163                          newheader("RADIANCE", stdout);
164                          printargs(argc, argv, stdout);
165                  }
166 +                fputncomp(3, stdout);
167                  fputformat(AMBFMT, stdout);
168 <                putchar('\n');
74 < #ifdef MSDOS
75 <                setmode(fileno(stdout), O_BINARY);
76 < #endif
168 >                fputc('\n', stdout);
169                  putambmagic(stdout);
170                  writamb(fp);
171          } else {
172 < #ifdef MSDOS
173 <                setmode(fileno(fp), O_BINARY);
82 < #endif
83 <                if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0)
172 >                SET_FILE_BINARY(fp);
173 >                if (getheader(fp, amb_headline, header ? stdout : (FILE *)NULL) < 0)
174                          goto formaterr;
175                  if (!hasambmagic(fp))
176                          goto formaterr;
177                  if (header) {
178                          fputformat("ascii", stdout);
179 <                        putchar('\n');
179 >                        fputc('\n', stdout);
180                  }
181                  lookamb(fp);
182          }
# Line 95 | Line 185 | char  *argv[];
185   formaterr:
186          fprintf(stderr, "%s: format error on input\n", argv[0]);
187          exit(1);
98 }
99
100
101 lookamb(fp)                     /* get ambient values from a file */
102 FILE  *fp;
103 {
104        while (readambval(&av, fp)) {
105                if (dataonly) {
106                        printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]);
107                        printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]);
108                        printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad);
109                        printf("%e\t%e\t%e\t", colval(av.val,RED),
110                                                colval(av.val,GRN),
111                                                colval(av.val,BLU));
112                        printf("%f\t%f\t%f\t", av.gpos[0],
113                                        av.gpos[1], av.gpos[2]);
114                        printf("%f\t%f\t%f\n", av.gdir[0],
115                                        av.gdir[1], av.gdir[2]);
116                } else {
117                        printf("\nPosition:\t%f\t%f\t%f\n", av.pos[0],
118                                        av.pos[1], av.pos[2]);
119                        printf("Direction:\t%f\t%f\t%f\n", av.dir[0],
120                                        av.dir[1], av.dir[2]);
121                        printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl,
122                                        av.weight, av.rad);
123                        printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED),
124                                        colval(av.val,GRN), colval(av.val,BLU));
125                        printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0],
126                                        av.gpos[1], av.gpos[2]);
127                        printf("Dir.Grad:\t%f\t%f\t%f\n", av.gdir[0],
128                                        av.gdir[1], av.gdir[2]);
129                }
130                if (ferror(stdout))
131                        exit(1);
132        }
133 }
134
135
136 writamb(fp)                     /* write binary ambient values */
137 FILE  *fp;
138 {
139        for ( ; ; ) {
140                if (!dataonly)
141                        fscanf(fp, "%*s");
142                if (fscanf(fp, "%f %f %f",
143                                &av.pos[0], &av.pos[1], &av.pos[2]) != 3)
144                        return;
145                if (!dataonly)
146                        fscanf(fp, "%*s");
147                if (fscanf(fp, "%f %f %f",
148                                &av.dir[0], &av.dir[1], &av.dir[2]) != 3)
149                        return;
150                if (!dataonly)
151                        fscanf(fp, "%*s");
152                if (fscanf(fp, "%d %f %f",
153                                &av.lvl, &av.weight, &av.rad) != 3)
154                        return;
155                if (!dataonly)
156                        fscanf(fp, "%*s");
157                if (fscanf(fp, "%f %f %f",
158                                &av.val[RED], &av.val[GRN], &av.val[BLU]) != 3)
159                        return;
160                if (!dataonly)
161                        fscanf(fp, "%*s");
162                if (fscanf(fp, "%f %f %f",
163                                &av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3)
164                        return;
165                if (!dataonly)
166                        fscanf(fp, "%*s");
167                if (fscanf(fp, "%f %f %f",
168                                &av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3)
169                        return;
170                av.next = NULL;
171                writambval(&av, stdout);
172                if (ferror(stdout))
173                        exit(1);
174        }
188   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines