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 |
< |
#include "color.h" |
10 |
> |
#include "ray.h" |
11 |
|
|
12 |
|
#include "ambient.h" |
13 |
|
|
14 |
|
|
15 |
|
int dataonly = 0; |
16 |
< |
|
16 |
> |
int header = 1; |
17 |
|
int reverse = 0; |
18 |
|
|
19 |
|
AMBVAL av; |
20 |
|
|
21 |
|
|
22 |
|
main(argc, argv) /* load ambient values from a file */ |
23 |
+ |
int argc; |
24 |
|
char *argv[]; |
25 |
|
{ |
26 |
|
FILE *fp; |
35 |
|
case 'r': |
36 |
|
reverse = 1; |
37 |
|
break; |
38 |
+ |
case 'h': |
39 |
+ |
header = 0; |
40 |
+ |
break; |
41 |
|
default: |
42 |
|
fprintf(stderr, "%s: unknown option '%s'\n", |
43 |
|
argv[0], argv[i]); |
52 |
|
fprintf(stderr, "%s: file not found\n", argv[i]); |
53 |
|
return(1); |
54 |
|
} |
55 |
< |
if (reverse) |
55 |
> |
if (reverse) { |
56 |
> |
if (header) { |
57 |
> |
if (checkheader(fp, "ascii", stdout) < 0) |
58 |
> |
goto formaterr; |
59 |
> |
} else { |
60 |
> |
newheader("RADIANCE", stdout); |
61 |
> |
printargs(argc, argv, stdout); |
62 |
> |
} |
63 |
> |
fputformat(AMBFMT, stdout); |
64 |
> |
putchar('\n'); |
65 |
> |
#ifdef MSDOS |
66 |
> |
setmode(fileno(stdout), O_BINARY); |
67 |
> |
#endif |
68 |
> |
putambmagic(stdout); |
69 |
|
writamb(fp); |
70 |
< |
else |
70 |
> |
} else { |
71 |
> |
#ifdef MSDOS |
72 |
> |
setmode(fileno(fp), O_BINARY); |
73 |
> |
#endif |
74 |
> |
if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0) |
75 |
> |
goto formaterr; |
76 |
> |
if (!hasambmagic(fp)) |
77 |
> |
goto formaterr; |
78 |
> |
if (header) { |
79 |
> |
fputformat("ascii", stdout); |
80 |
> |
putchar('\n'); |
81 |
> |
} |
82 |
|
lookamb(fp); |
83 |
+ |
} |
84 |
|
fclose(fp); |
85 |
|
return(0); |
86 |
+ |
formaterr: |
87 |
+ |
fprintf(stderr, "%s: format error on input\n", argv[0]); |
88 |
+ |
exit(1); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
+ |
void |
93 |
|
lookamb(fp) /* get ambient values from a file */ |
94 |
|
FILE *fp; |
95 |
|
{ |
96 |
< |
while (fread((char *)&av, sizeof(AMBVAL), 1, fp) == 1) { |
96 |
> |
while (readambval(&av, fp)) { |
97 |
|
if (dataonly) { |
98 |
|
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
99 |
|
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
+ |
void |
129 |
|
writamb(fp) /* write binary ambient values */ |
130 |
|
FILE *fp; |
131 |
|
{ |
161 |
|
&av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) |
162 |
|
return; |
163 |
|
av.next = NULL; |
164 |
< |
fwrite((char *)&av, sizeof(AMBVAL), 1, stdout); |
164 |
> |
writambval(&av, stdout); |
165 |
|
if (ferror(stdout)) |
166 |
|
exit(1); |
167 |
|
} |