| 10 |
|
#include "platform.h" |
| 11 |
|
#include "ray.h" |
| 12 |
|
#include "ambient.h" |
| 13 |
– |
#include "resolu.h" |
| 13 |
|
|
| 14 |
|
|
| 15 |
|
int dataonly = 0; |
| 18 |
|
|
| 19 |
|
AMBVAL av; |
| 20 |
|
|
| 22 |
– |
#ifdef NEWAMB |
| 21 |
|
|
| 24 |
– |
|
| 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(av.val,RED), |
| 41 |
< |
colval(av.val,GRN), |
| 42 |
< |
colval(av.val,BLU)); |
| 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); |
| 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(av.val,RED), |
| 56 |
< |
colval(av.val,GRN), colval(av.val,BLU)); |
| 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); |
| 70 |
|
) |
| 71 |
|
{ |
| 72 |
|
FVECT norm; |
| 73 |
+ |
COLOR avcol; |
| 74 |
|
|
| 75 |
|
for ( ; ; ) { |
| 76 |
|
if (!dataonly) |
| 80 |
|
return; |
| 81 |
|
if (!dataonly) |
| 82 |
|
fscanf(fp, "%*s"); |
| 83 |
< |
if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3) |
| 83 |
> |
if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3 || |
| 84 |
> |
normalize(norm) == 0) |
| 85 |
|
return; |
| 86 |
|
av.ndir = encodedir(norm); |
| 87 |
|
if (!dataonly) |
| 88 |
|
fscanf(fp, "%*s"); |
| 89 |
< |
if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3) |
| 89 |
> |
if (fscanf(fp, FVFORMAT, &norm[0], &norm[1], &norm[2]) != 3 || |
| 90 |
> |
normalize(norm) == 0) |
| 91 |
|
return; |
| 92 |
|
av.udir = encodedir(norm); |
| 93 |
|
if (!dataonly) |
| 94 |
|
fscanf(fp, "%*s"); |
| 95 |
< |
if (fscanf(fp, "%d %f %f %f", &av.lvl, &av.weight, |
| 95 |
> |
if (fscanf(fp, "%hd %f %f %f", &av.lvl, &av.weight, |
| 96 |
|
&av.rad[0], &av.rad[1]) != 4) |
| 97 |
|
return; |
| 98 |
|
if (!dataonly) |
| 99 |
|
fscanf(fp, "%*s"); |
| 100 |
|
if (fscanf(fp, "%f %f %f", |
| 101 |
< |
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
| 101 |
> |
&avcol[RED], &avcol[GRN], &avcol[BLU]) != 3) |
| 102 |
|
return; |
| 103 |
+ |
setscolor(av.val, avcol[RED], avcol[GRN], avcol[BLU]); |
| 104 |
|
if (!dataonly) |
| 105 |
|
fscanf(fp, "%*s"); |
| 106 |
|
if (fscanf(fp, "%f %f", &av.gpos[0], &av.gpos[1]) != 2) |
| 115 |
|
} else if (fscanf(fp, "%*s %X", &av.corral) != 1) |
| 116 |
|
return; |
| 117 |
|
av.next = NULL; |
| 118 |
< |
writambval(&av, stdout); |
| 116 |
< |
if (ferror(stdout)) |
| 118 |
> |
if (writambval(&av, stdout) < 0) |
| 119 |
|
exit(1); |
| 120 |
|
} |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 122 |
– |
#else /* ! NEWAMB */ |
| 123 |
– |
|
| 124 |
– |
|
| 125 |
– |
static void |
| 126 |
– |
lookamb( /* get ambient values from a file */ |
| 127 |
– |
FILE *fp |
| 128 |
– |
) |
| 129 |
– |
{ |
| 130 |
– |
while (readambval(&av, fp)) { |
| 131 |
– |
if (dataonly) { |
| 132 |
– |
printf("%f\t%f\t%f\t", av.pos[0], av.pos[1], av.pos[2]); |
| 133 |
– |
printf("%f\t%f\t%f\t", av.dir[0], av.dir[1], av.dir[2]); |
| 134 |
– |
printf("%d\t%f\t%f\t", av.lvl, av.weight, av.rad); |
| 135 |
– |
printf("%e\t%e\t%e\t", colval(av.val,RED), |
| 136 |
– |
colval(av.val,GRN), |
| 137 |
– |
colval(av.val,BLU)); |
| 138 |
– |
printf("%f\t%f\t%f\t", av.gpos[0], |
| 139 |
– |
av.gpos[1], av.gpos[2]); |
| 140 |
– |
printf("%f\t%f\t%f\n", av.gdir[0], |
| 141 |
– |
av.gdir[1], av.gdir[2]); |
| 142 |
– |
} else { |
| 143 |
– |
printf("Position:\t%f\t%f\t%f\n", av.pos[0], |
| 144 |
– |
av.pos[1], av.pos[2]); |
| 145 |
– |
printf("Direction:\t%f\t%f\t%f\n", av.dir[0], |
| 146 |
– |
av.dir[1], av.dir[2]); |
| 147 |
– |
printf("Lvl,Wt,Rad:\t%d\t\t%f\t%f\n", av.lvl, |
| 148 |
– |
av.weight, av.rad); |
| 149 |
– |
printf("Value:\t\t%e\t%e\t%e\n", colval(av.val,RED), |
| 150 |
– |
colval(av.val,GRN), colval(av.val,BLU)); |
| 151 |
– |
printf("Pos.Grad:\t%f\t%f\t%f\n", av.gpos[0], |
| 152 |
– |
av.gpos[1], av.gpos[2]); |
| 153 |
– |
printf("Dir.Grad:\t%f\t%f\t%f\n\n", av.gdir[0], |
| 154 |
– |
av.gdir[1], av.gdir[2]); |
| 155 |
– |
} |
| 156 |
– |
if (ferror(stdout)) |
| 157 |
– |
exit(1); |
| 158 |
– |
} |
| 159 |
– |
} |
| 160 |
– |
|
| 161 |
– |
|
| 162 |
– |
static void |
| 163 |
– |
writamb( /* write binary ambient values */ |
| 164 |
– |
FILE *fp |
| 165 |
– |
) |
| 166 |
– |
{ |
| 167 |
– |
for ( ; ; ) { |
| 168 |
– |
if (!dataonly) |
| 169 |
– |
fscanf(fp, "%*s"); |
| 170 |
– |
if (fscanf(fp, "%f %f %f", |
| 171 |
– |
&av.pos[0], &av.pos[1], &av.pos[2]) != 3) |
| 172 |
– |
return; |
| 173 |
– |
if (!dataonly) |
| 174 |
– |
fscanf(fp, "%*s"); |
| 175 |
– |
if (fscanf(fp, "%f %f %f", |
| 176 |
– |
&av.dir[0], &av.dir[1], &av.dir[2]) != 3) |
| 177 |
– |
return; |
| 178 |
– |
if (!dataonly) |
| 179 |
– |
fscanf(fp, "%*s"); |
| 180 |
– |
if (fscanf(fp, "%d %f %f", |
| 181 |
– |
&av.lvl, &av.weight, &av.rad) != 3) |
| 182 |
– |
return; |
| 183 |
– |
if (!dataonly) |
| 184 |
– |
fscanf(fp, "%*s"); |
| 185 |
– |
if (fscanf(fp, "%f %f %f", |
| 186 |
– |
&av.val[RED], &av.val[GRN], &av.val[BLU]) != 3) |
| 187 |
– |
return; |
| 188 |
– |
if (!dataonly) |
| 189 |
– |
fscanf(fp, "%*s"); |
| 190 |
– |
if (fscanf(fp, "%f %f %f", |
| 191 |
– |
&av.gpos[0], &av.gpos[1], &av.gpos[2]) != 3) |
| 192 |
– |
return; |
| 193 |
– |
if (!dataonly) |
| 194 |
– |
fscanf(fp, "%*s"); |
| 195 |
– |
if (fscanf(fp, "%f %f %f", |
| 196 |
– |
&av.gdir[0], &av.gdir[1], &av.gdir[2]) != 3) |
| 197 |
– |
return; |
| 198 |
– |
av.next = NULL; |
| 199 |
– |
writambval(&av, stdout); |
| 200 |
– |
if (ferror(stdout)) |
| 201 |
– |
exit(1); |
| 202 |
– |
} |
| 203 |
– |
} |
| 204 |
– |
|
| 205 |
– |
|
| 206 |
– |
#endif /* ! NEWAMB */ |
| 207 |
– |
|
| 208 |
– |
|
| 124 |
|
int |
| 125 |
|
main( /* load ambient values from a file */ |
| 126 |
|
int argc, |
| 157 |
|
return(1); |
| 158 |
|
} |
| 159 |
|
if (reverse) { |
| 160 |
+ |
SET_FILE_BINARY(stdout); |
| 161 |
|
if (header) { |
| 162 |
|
if (checkheader(fp, "ascii", stdout) < 0) |
| 163 |
|
goto formaterr; |
| 165 |
|
newheader("RADIANCE", stdout); |
| 166 |
|
printargs(argc, argv, stdout); |
| 167 |
|
} |
| 168 |
+ |
fputncomp(3, stdout); |
| 169 |
|
fputformat(AMBFMT, stdout); |
| 170 |
< |
putchar('\n'); |
| 254 |
< |
SET_FILE_BINARY(stdout); |
| 170 |
> |
fputc('\n', stdout); |
| 171 |
|
putambmagic(stdout); |
| 172 |
|
writamb(fp); |
| 173 |
|
} else { |
| 174 |
|
SET_FILE_BINARY(fp); |
| 175 |
< |
if (checkheader(fp, AMBFMT, header ? stdout : (FILE *)NULL) < 0) |
| 175 |
> |
if (getheader(fp, amb_headline, header ? stdout : (FILE *)NULL) < 0) |
| 176 |
|
goto formaterr; |
| 177 |
|
if (!hasambmagic(fp)) |
| 178 |
|
goto formaterr; |
| 179 |
|
if (header) { |
| 180 |
|
fputformat("ascii", stdout); |
| 181 |
< |
putchar('\n'); |
| 181 |
> |
fputc('\n', stdout); |
| 182 |
|
} |
| 183 |
|
lookamb(fp); |
| 184 |
|
} |