| 1 |
< |
/* Copyright (c) 1987 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 18 |
|
|
| 19 |
|
#include "rpaint.h" |
| 20 |
|
|
| 21 |
+ |
#include "resolu.h" |
| 22 |
+ |
|
| 23 |
|
#include <ctype.h> |
| 24 |
|
|
| 25 |
< |
#define CTRL(c) ('c'-'@') |
| 25 |
> |
#define CTRL(c) ((c)-'@') |
| 26 |
|
|
| 27 |
+ |
#ifdef SMLFLT |
| 28 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
| 29 |
+ |
#else |
| 30 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
| 31 |
+ |
#endif |
| 32 |
+ |
|
| 33 |
+ |
extern char *atos(); |
| 34 |
+ |
|
| 35 |
+ |
extern FILE *popen(); |
| 36 |
+ |
|
| 37 |
+ |
extern char rifname[128]; /* rad input file name */ |
| 38 |
+ |
|
| 39 |
+ |
extern char VersionID[]; |
| 40 |
|
extern char *progname; |
| 41 |
+ |
extern char *octname; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
getframe(s) /* get a new frame */ |
| 45 |
|
char *s; |
| 46 |
|
{ |
| 47 |
< |
int x0, y0, x1, y1; |
| 32 |
< |
|
| 33 |
< |
if (!strcmp("all", s)) { |
| 34 |
< |
pframe.l = pframe.d = 0; |
| 35 |
< |
pframe.r = ourview.hresolu; |
| 36 |
< |
pframe.u = ourview.vresolu; |
| 37 |
< |
pdepth = 0; |
| 47 |
> |
if (getrect(s, &pframe) < 0) |
| 48 |
|
return; |
| 39 |
– |
} |
| 40 |
– |
if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) { |
| 41 |
– |
if (dev->getcur == NULL) |
| 42 |
– |
return; |
| 43 |
– |
(*dev->comout)("Pick first corner\n"); |
| 44 |
– |
if ((*dev->getcur)(&x0, &y0) == ABORT) |
| 45 |
– |
return; |
| 46 |
– |
(*dev->comout)("Pick second corner\n"); |
| 47 |
– |
if ((*dev->getcur)(&x1, &y1) == ABORT) |
| 48 |
– |
return; |
| 49 |
– |
} |
| 50 |
– |
if (x0 < x1) { |
| 51 |
– |
pframe.l = x0; |
| 52 |
– |
pframe.r = x1; |
| 53 |
– |
} else { |
| 54 |
– |
pframe.l = x1; |
| 55 |
– |
pframe.r = x0; |
| 56 |
– |
} |
| 57 |
– |
if (y0 < y1) { |
| 58 |
– |
pframe.d = y0; |
| 59 |
– |
pframe.u = y1; |
| 60 |
– |
} else { |
| 61 |
– |
pframe.d = y1; |
| 62 |
– |
pframe.u = y0; |
| 63 |
– |
} |
| 64 |
– |
if (pframe.l < 0) pframe.l = 0; |
| 65 |
– |
if (pframe.d < 0) pframe.d = 0; |
| 66 |
– |
if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu; |
| 67 |
– |
if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu; |
| 49 |
|
pdepth = 0; |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
|
| 53 |
+ |
getrepaint(s) /* get area and repaint */ |
| 54 |
+ |
char *s; |
| 55 |
+ |
{ |
| 56 |
+ |
RECT box; |
| 57 |
+ |
|
| 58 |
+ |
if (getrect(s, &box) < 0) |
| 59 |
+ |
return; |
| 60 |
+ |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); |
| 61 |
+ |
} |
| 62 |
+ |
|
| 63 |
+ |
|
| 64 |
|
getview(s) /* get/show view parameters */ |
| 65 |
|
char *s; |
| 66 |
|
{ |
| 67 |
|
FILE *fp; |
| 68 |
|
char buf[128]; |
| 69 |
< |
char *fname, *getpath(); |
| 69 |
> |
char *fname; |
| 70 |
|
int change = 0; |
| 71 |
|
VIEW nv; |
| 72 |
|
|
| 73 |
+ |
while (isspace(*s)) |
| 74 |
+ |
s++; |
| 75 |
+ |
if (*s == '-') { /* command line parameters */ |
| 76 |
+ |
copystruct(&nv, &ourview); |
| 77 |
+ |
if (sscanview(&nv, s)) |
| 78 |
+ |
newview(&nv); |
| 79 |
+ |
else |
| 80 |
+ |
error(COMMAND, "bad view option(s)"); |
| 81 |
+ |
return; |
| 82 |
+ |
} |
| 83 |
|
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
| 84 |
< |
if ((fname = getpath(buf, NULL)) == NULL || |
| 84 |
> |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
| 85 |
|
(fp = fopen(fname, "a")) == NULL) { |
| 86 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
| 87 |
|
error(COMMAND, errmsg); |
| 89 |
|
} |
| 90 |
|
fputs(progname, fp); |
| 91 |
|
fprintview(&ourview, fp); |
| 92 |
< |
fputs("\n", fp); |
| 92 |
> |
fputs(sskip(s), fp); |
| 93 |
> |
putc('\n', fp); |
| 94 |
|
fclose(fp); |
| 95 |
|
return; |
| 96 |
|
} |
| 97 |
|
sprintf(buf, "view type (%c): ", ourview.type); |
| 98 |
|
(*dev->comout)(buf); |
| 99 |
< |
(*dev->comin)(buf); |
| 100 |
< |
if (buf[0] == CTRL(C)) return; |
| 99 |
> |
(*dev->comin)(buf, NULL); |
| 100 |
> |
if (buf[0] == CTRL('C')) return; |
| 101 |
|
if (buf[0] && buf[0] != ourview.type) { |
| 102 |
|
nv.type = buf[0]; |
| 103 |
|
change++; |
| 106 |
|
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
| 107 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
| 108 |
|
(*dev->comout)(buf); |
| 109 |
< |
(*dev->comin)(buf); |
| 110 |
< |
if (buf[0] == CTRL(C)) return; |
| 111 |
< |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) |
| 109 |
> |
(*dev->comin)(buf, NULL); |
| 110 |
> |
if (buf[0] == CTRL('C')) return; |
| 111 |
> |
if (sscanvec(buf, nv.vp)) |
| 112 |
|
change++; |
| 113 |
|
else |
| 114 |
|
VCOPY(nv.vp, ourview.vp); |
| 115 |
|
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
| 116 |
|
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
| 117 |
|
(*dev->comout)(buf); |
| 118 |
< |
(*dev->comin)(buf); |
| 119 |
< |
if (buf[0] == CTRL(C)) return; |
| 120 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) |
| 118 |
> |
(*dev->comin)(buf, NULL); |
| 119 |
> |
if (buf[0] == CTRL('C')) return; |
| 120 |
> |
if (sscanvec(buf, nv.vdir)) |
| 121 |
|
change++; |
| 122 |
|
else |
| 123 |
|
VCOPY(nv.vdir, ourview.vdir); |
| 124 |
|
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
| 125 |
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
| 126 |
|
(*dev->comout)(buf); |
| 127 |
< |
(*dev->comin)(buf); |
| 128 |
< |
if (buf[0] == CTRL(C)) return; |
| 129 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) |
| 127 |
> |
(*dev->comin)(buf, NULL); |
| 128 |
> |
if (buf[0] == CTRL('C')) return; |
| 129 |
> |
if (sscanvec(buf, nv.vup)) |
| 130 |
|
change++; |
| 131 |
|
else |
| 132 |
|
VCOPY(nv.vup, ourview.vup); |
| 133 |
|
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
| 134 |
|
ourview.horiz, ourview.vert); |
| 135 |
|
(*dev->comout)(buf); |
| 136 |
< |
(*dev->comin)(buf); |
| 137 |
< |
if (buf[0] == CTRL(C)) return; |
| 136 |
> |
(*dev->comin)(buf, NULL); |
| 137 |
> |
if (buf[0] == CTRL('C')) return; |
| 138 |
|
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
| 139 |
|
change++; |
| 140 |
|
else { |
| 141 |
|
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
| 142 |
|
} |
| 143 |
< |
sprintf(buf, "x and y resolution (%d %d): ", |
| 144 |
< |
ourview.hresolu, ourview.vresolu); |
| 143 |
> |
sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ", |
| 144 |
> |
ourview.vfore, ourview.vaft); |
| 145 |
|
(*dev->comout)(buf); |
| 146 |
< |
(*dev->comin)(buf); |
| 147 |
< |
if (buf[0] == CTRL(C)) return; |
| 148 |
< |
if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2) |
| 146 |
> |
(*dev->comin)(buf, NULL); |
| 147 |
> |
if (buf[0] == CTRL('C')) return; |
| 148 |
> |
if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2) |
| 149 |
|
change++; |
| 150 |
|
else { |
| 151 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 151 |
> |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
| 152 |
|
} |
| 153 |
+ |
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
| 154 |
+ |
ourview.hoff, ourview.voff); |
| 155 |
+ |
(*dev->comout)(buf); |
| 156 |
+ |
(*dev->comin)(buf, NULL); |
| 157 |
+ |
if (buf[0] == CTRL('C')) return; |
| 158 |
+ |
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
| 159 |
+ |
change++; |
| 160 |
+ |
else { |
| 161 |
+ |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 162 |
+ |
} |
| 163 |
|
if (change) |
| 164 |
|
newview(&nv); |
| 165 |
|
} |
| 169 |
|
char *s; |
| 170 |
|
{ |
| 171 |
|
char buf[128]; |
| 172 |
< |
char *fname, *getpath(); |
| 172 |
> |
char *fname; |
| 173 |
|
int success; |
| 174 |
|
VIEW nv; |
| 175 |
|
|
| 176 |
|
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
| 177 |
< |
bcopy(&stdview, &nv, sizeof(VIEW)); |
| 178 |
< |
if ((fname = getpath(buf, NULL)) == NULL || |
| 179 |
< |
(success = viewfile(fname, &nv)) == -1) { |
| 177 |
> |
copystruct(&nv, &stdview); |
| 178 |
> |
if ((fname = getpath(buf, "", R_OK)) == NULL || |
| 179 |
> |
(success = viewfile(fname, &nv, NULL)) == -1) { |
| 180 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
| 181 |
|
error(COMMAND, errmsg); |
| 182 |
|
return; |
| 187 |
|
newview(&nv); |
| 188 |
|
return; |
| 189 |
|
} |
| 190 |
< |
if (oldview.hresolu == 0) { /* no old view! */ |
| 190 |
> |
if (oldview.type == 0) { /* no old view! */ |
| 191 |
|
error(COMMAND, "no previous view"); |
| 192 |
|
return; |
| 193 |
|
} |
| 194 |
< |
bcopy(&ourview, &nv, sizeof(VIEW)); |
| 195 |
< |
bcopy(&oldview, &ourview, sizeof(VIEW)); |
| 196 |
< |
bcopy(&nv, &oldview, sizeof(VIEW)); |
| 194 |
> |
copystruct(&nv, &ourview); |
| 195 |
> |
copystruct(&ourview, &oldview); |
| 196 |
> |
copystruct(&oldview, &nv); |
| 197 |
|
newimage(); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
|
| 201 |
< |
getinterest(s, direc, vec, mp) /* get area of interest */ |
| 201 |
> |
saveview(s) /* save view to rad file */ |
| 202 |
|
char *s; |
| 190 |
– |
int direc; |
| 191 |
– |
FVECT vec; |
| 192 |
– |
double *mp; |
| 203 |
|
{ |
| 204 |
< |
int x, y; |
| 205 |
< |
RAY thisray; |
| 206 |
< |
register int i; |
| 204 |
> |
char view[64]; |
| 205 |
> |
char *fname; |
| 206 |
> |
FILE *fp; |
| 207 |
|
|
| 208 |
< |
if (sscanf(s, "%lf", mp) != 1) |
| 209 |
< |
*mp = 1.0; |
| 210 |
< |
else if (*mp < -FTINY) /* negative zoom is reduction */ |
| 211 |
< |
*mp = -1.0 / *mp; |
| 202 |
< |
else if (*mp <= FTINY) { /* too small */ |
| 203 |
< |
error(COMMAND, "illegal magnification"); |
| 204 |
< |
return(-1); |
| 205 |
< |
} |
| 206 |
< |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
| 207 |
< |
if (dev->getcur == NULL) |
| 208 |
< |
return(-1); |
| 209 |
< |
(*dev->comout)("Pick view center\n"); |
| 210 |
< |
if ((*dev->getcur)(&x, &y) == ABORT) |
| 211 |
< |
return(-1); |
| 212 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
| 213 |
< |
if (!direc || ourview.type == VT_PAR) { |
| 214 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 215 |
< |
if (!localhit(&thisray, &thescene)) { |
| 216 |
< |
error(COMMAND, "not a local object"); |
| 217 |
< |
return(-1); |
| 218 |
< |
} |
| 208 |
> |
if (*atos(view, sizeof(view), s)) { |
| 209 |
> |
if (isint(view)) { |
| 210 |
> |
error(COMMAND, "cannot write view by number"); |
| 211 |
> |
return; |
| 212 |
|
} |
| 213 |
< |
if (direc) |
| 214 |
< |
if (ourview.type == VT_PAR) |
| 215 |
< |
for (i = 0; i < 3; i++) |
| 216 |
< |
vec[i] = thisray.rop[i] - ourview.vp[i]; |
| 217 |
< |
else |
| 218 |
< |
VCOPY(vec, thisray.rdir); |
| 219 |
< |
else |
| 220 |
< |
VCOPY(vec, thisray.rop); |
| 221 |
< |
} else if (direc) |
| 222 |
< |
for (i = 0; i < 3; i++) |
| 223 |
< |
vec[i] -= ourview.vp[i]; |
| 224 |
< |
return(0); |
| 213 |
> |
s = sskip(s); |
| 214 |
> |
} |
| 215 |
> |
while (isspace(*s)) |
| 216 |
> |
s++; |
| 217 |
> |
if (*s) |
| 218 |
> |
atos(rifname, sizeof(rifname), s); |
| 219 |
> |
else if (rifname[0] == '\0') { |
| 220 |
> |
error(COMMAND, "no previous rad file"); |
| 221 |
> |
return; |
| 222 |
> |
} |
| 223 |
> |
if ((fname = getpath(rifname, NULL, 0)) == NULL || |
| 224 |
> |
(fp = fopen(fname, "a")) == NULL) { |
| 225 |
> |
sprintf(errmsg, "cannot open \"%s\"", rifname); |
| 226 |
> |
error(COMMAND, errmsg); |
| 227 |
> |
return; |
| 228 |
> |
} |
| 229 |
> |
fputs("view= ", fp); |
| 230 |
> |
fputs(view, fp); |
| 231 |
> |
fprintview(&ourview, fp); |
| 232 |
> |
putc('\n', fp); |
| 233 |
> |
fclose(fp); |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
|
| 237 |
+ |
loadview(s) /* load view from rad file */ |
| 238 |
+ |
char *s; |
| 239 |
+ |
{ |
| 240 |
+ |
char buf[512]; |
| 241 |
+ |
char *fname; |
| 242 |
+ |
FILE *fp; |
| 243 |
+ |
VIEW nv; |
| 244 |
+ |
|
| 245 |
+ |
strcpy(buf, "rad -n -s -V -v "); |
| 246 |
+ |
if (sscanf(s, "%s", buf+strlen(buf)) == 1) |
| 247 |
+ |
s = sskip(s); |
| 248 |
+ |
else |
| 249 |
+ |
strcat(buf, "1"); |
| 250 |
+ |
if (*s) |
| 251 |
+ |
atos(rifname, sizeof(rifname), s); |
| 252 |
+ |
else if (rifname[0] == '\0') { |
| 253 |
+ |
error(COMMAND, "no previous rad file"); |
| 254 |
+ |
return; |
| 255 |
+ |
} |
| 256 |
+ |
if ((fname = getpath(rifname, "", R_OK)) == NULL) { |
| 257 |
+ |
sprintf(errmsg, "cannot access \"%s\"", rifname); |
| 258 |
+ |
error(COMMAND, errmsg); |
| 259 |
+ |
return; |
| 260 |
+ |
} |
| 261 |
+ |
sprintf(buf+strlen(buf), " %s", fname); |
| 262 |
+ |
if ((fp = popen(buf, "r")) == NULL) { |
| 263 |
+ |
error(COMMAND, "cannot run rad"); |
| 264 |
+ |
return; |
| 265 |
+ |
} |
| 266 |
+ |
buf[0] = '\0'; |
| 267 |
+ |
fgets(buf, sizeof(buf), fp); |
| 268 |
+ |
pclose(fp); |
| 269 |
+ |
copystruct(&nv, &stdview); |
| 270 |
+ |
if (!sscanview(&nv, buf)) { |
| 271 |
+ |
error(COMMAND, "rad error -- no such view?"); |
| 272 |
+ |
return; |
| 273 |
+ |
} |
| 274 |
+ |
newview(&nv); |
| 275 |
+ |
} |
| 276 |
+ |
|
| 277 |
+ |
|
| 278 |
|
getaim(s) /* aim camera */ |
| 279 |
|
char *s; |
| 280 |
|
{ |
| 238 |
– |
extern double tan(), atan(); |
| 281 |
|
double zfact; |
| 282 |
|
VIEW nv; |
| 283 |
|
|
| 284 |
|
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
| 285 |
|
return; |
| 286 |
+ |
nv.type = ourview.type; |
| 287 |
|
VCOPY(nv.vp, ourview.vp); |
| 288 |
|
VCOPY(nv.vup, ourview.vup); |
| 289 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 290 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
| 291 |
< |
nv.horiz = ourview.horiz / zfact; |
| 292 |
< |
nv.vert = ourview.vert / zfact; |
| 250 |
< |
} else { |
| 251 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
| 252 |
< |
(PI/180./2.); |
| 253 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
| 254 |
< |
(PI/180./2.); |
| 255 |
< |
} |
| 289 |
> |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
| 290 |
> |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
| 291 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 292 |
> |
zoomview(&nv, zfact); |
| 293 |
|
newview(&nv); |
| 294 |
|
} |
| 295 |
|
|
| 309 |
|
getrotate(s) /* rotate camera */ |
| 310 |
|
char *s; |
| 311 |
|
{ |
| 275 |
– |
extern double normalize(), tan(), atan(); |
| 312 |
|
VIEW nv; |
| 313 |
|
FVECT v1; |
| 314 |
|
double angle, elev, zfact; |
| 318 |
|
error(COMMAND, "missing angle"); |
| 319 |
|
return; |
| 320 |
|
} |
| 321 |
+ |
nv.type = ourview.type; |
| 322 |
|
VCOPY(nv.vp, ourview.vp); |
| 323 |
|
VCOPY(nv.vup, ourview.vup); |
| 324 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 324 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 325 |
> |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
| 326 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 327 |
|
if (elev != 0.0) { |
| 328 |
|
fcross(v1, nv.vdir, ourview.vup); |
| 329 |
|
normalize(v1); |
| 330 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 331 |
|
} |
| 332 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
| 333 |
< |
nv.horiz = ourview.horiz / zfact; |
| 296 |
< |
nv.vert = ourview.vert / zfact; |
| 297 |
< |
} else { |
| 298 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
| 299 |
< |
(PI/180./2.); |
| 300 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
| 301 |
< |
(PI/180./2.); |
| 302 |
< |
} |
| 332 |
> |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
| 333 |
> |
zoomview(&nv, zfact); |
| 334 |
|
newview(&nv); |
| 335 |
|
} |
| 336 |
|
|
| 355 |
|
getexposure(s) /* get new exposure */ |
| 356 |
|
char *s; |
| 357 |
|
{ |
| 327 |
– |
double atof(), pow(), fabs(); |
| 358 |
|
char buf[128]; |
| 359 |
|
register char *cp; |
| 330 |
– |
register PNODE *p; |
| 360 |
|
RECT r; |
| 361 |
|
int x, y; |
| 362 |
< |
double e; |
| 362 |
> |
register PNODE *p = &ptrunk; |
| 363 |
> |
int adapt = 0; |
| 364 |
> |
double e = 1.0; |
| 365 |
|
|
| 366 |
|
for (cp = s; isspace(*cp); cp++) |
| 367 |
|
; |
| 368 |
+ |
if (*cp == '@') { |
| 369 |
+ |
adapt++; |
| 370 |
+ |
while (isspace(*++cp)) |
| 371 |
+ |
; |
| 372 |
+ |
} |
| 373 |
|
if (*cp == '\0') { /* normalize to point */ |
| 374 |
|
if (dev->getcur == NULL) |
| 375 |
|
return; |
| 377 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
| 378 |
|
return; |
| 379 |
|
r.l = r.d = 0; |
| 380 |
< |
r.r = ourview.hresolu; r.u = ourview.vresolu; |
| 380 |
> |
r.r = hresolu; r.u = vresolu; |
| 381 |
|
p = findrect(x, y, &ptrunk, &r, -1); |
| 346 |
– |
e = 1.0; |
| 382 |
|
} else { |
| 383 |
|
if (*cp == '=') { /* absolute setting */ |
| 384 |
|
p = NULL; |
| 386 |
|
for (cp++; isspace(*cp); cp++) |
| 387 |
|
; |
| 388 |
|
if (*cp == '\0') { /* interactive */ |
| 389 |
< |
sprintf(buf, "exposure (%lf): ", exposure); |
| 389 |
> |
sprintf(buf, "exposure (%f): ", exposure); |
| 390 |
|
(*dev->comout)(buf); |
| 391 |
< |
(*dev->comin)(buf); |
| 391 |
> |
(*dev->comin)(buf, NULL); |
| 392 |
|
for (cp = buf; isspace(*cp); cp++) |
| 393 |
|
; |
| 394 |
|
if (*cp == '\0') |
| 395 |
|
return; |
| 396 |
|
} |
| 362 |
– |
} else { /* normalize to average */ |
| 363 |
– |
p = &ptrunk; |
| 364 |
– |
e = 1.0; |
| 397 |
|
} |
| 398 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
| 399 |
|
e *= pow(2.0, atof(cp)); |
| 401 |
|
e *= atof(cp); |
| 402 |
|
} |
| 403 |
|
if (p != NULL) { /* relative setting */ |
| 404 |
< |
if (intens(p->v) <= FTINY) { |
| 404 |
> |
if (bright(p->v) < 1e-15) { |
| 405 |
|
error(COMMAND, "cannot normalize to zero"); |
| 406 |
|
return; |
| 407 |
|
} |
| 408 |
< |
e *= 0.5 / intens(p->v); |
| 408 |
> |
if (adapt) |
| 409 |
> |
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
| 410 |
> |
else |
| 411 |
> |
e *= 0.5 / bright(p->v); |
| 412 |
|
} |
| 413 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
| 414 |
|
return; |
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
|
| 421 |
+ |
getparam(str, dsc, typ, ptr) /* get variable from user */ |
| 422 |
+ |
char *str, *dsc; |
| 423 |
+ |
int typ; |
| 424 |
+ |
register union {int i; double d; COLOR C;} *ptr; |
| 425 |
+ |
{ |
| 426 |
+ |
extern char *index(); |
| 427 |
+ |
int i0; |
| 428 |
+ |
double d0, d1, d2; |
| 429 |
+ |
char buf[48]; |
| 430 |
+ |
|
| 431 |
+ |
switch (typ) { |
| 432 |
+ |
case 'i': /* integer */ |
| 433 |
+ |
if (sscanf(str, "%d", &i0) != 1) { |
| 434 |
+ |
(*dev->comout)(dsc); |
| 435 |
+ |
sprintf(buf, " (%d): ", ptr->i); |
| 436 |
+ |
(*dev->comout)(buf); |
| 437 |
+ |
(*dev->comin)(buf, NULL); |
| 438 |
+ |
if (sscanf(buf, "%d", &i0) != 1) |
| 439 |
+ |
return(0); |
| 440 |
+ |
} |
| 441 |
+ |
ptr->i = i0; |
| 442 |
+ |
return(1); |
| 443 |
+ |
case 'r': /* real */ |
| 444 |
+ |
if (sscanf(str, "%lf", &d0) != 1) { |
| 445 |
+ |
(*dev->comout)(dsc); |
| 446 |
+ |
sprintf(buf, " (%.6g): ", ptr->d); |
| 447 |
+ |
(*dev->comout)(buf); |
| 448 |
+ |
(*dev->comin)(buf, NULL); |
| 449 |
+ |
if (sscanf(buf, "%lf", &d0) != 1) |
| 450 |
+ |
return(0); |
| 451 |
+ |
} |
| 452 |
+ |
ptr->d = d0; |
| 453 |
+ |
return(1); |
| 454 |
+ |
case 'b': /* boolean */ |
| 455 |
+ |
if (sscanf(str, "%1s", buf) != 1) { |
| 456 |
+ |
(*dev->comout)(dsc); |
| 457 |
+ |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
| 458 |
+ |
(*dev->comout)(buf); |
| 459 |
+ |
(*dev->comin)(buf, NULL); |
| 460 |
+ |
if (buf[0] == '\0' || |
| 461 |
+ |
index("yY+1tTnN-0fF", buf[0]) == NULL) |
| 462 |
+ |
return(0); |
| 463 |
+ |
} |
| 464 |
+ |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
| 465 |
+ |
return(1); |
| 466 |
+ |
case 'C': /* color */ |
| 467 |
+ |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
| 468 |
+ |
(*dev->comout)(dsc); |
| 469 |
+ |
sprintf(buf, " (%.6g %.6g %.6g): ", |
| 470 |
+ |
colval(ptr->C,RED), |
| 471 |
+ |
colval(ptr->C,GRN), |
| 472 |
+ |
colval(ptr->C,BLU)); |
| 473 |
+ |
(*dev->comout)(buf); |
| 474 |
+ |
(*dev->comin)(buf, NULL); |
| 475 |
+ |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
| 476 |
+ |
return(0); |
| 477 |
+ |
} |
| 478 |
+ |
setcolor(ptr->C, d0, d1, d2); |
| 479 |
+ |
return(1); |
| 480 |
+ |
} |
| 481 |
+ |
} |
| 482 |
+ |
|
| 483 |
+ |
|
| 484 |
|
setparam(s) /* get/set program parameter */ |
| 485 |
|
register char *s; |
| 486 |
|
{ |
| 489 |
|
extern double minweight; |
| 490 |
|
extern int maxdepth; |
| 491 |
|
extern double dstrsrc; |
| 492 |
+ |
extern double shadthresh; |
| 493 |
+ |
extern double shadcert; |
| 494 |
|
extern COLOR ambval; |
| 495 |
|
extern double ambacc; |
| 396 |
– |
extern double minarad; |
| 496 |
|
extern int ambres; |
| 497 |
|
extern int ambdiv; |
| 498 |
|
extern int ambssamp; |
| 499 |
|
extern int ambounce; |
| 500 |
< |
int i0; |
| 501 |
< |
double d0, d1, d2; |
| 500 |
> |
extern int directvis; |
| 501 |
> |
extern double srcsizerat; |
| 502 |
> |
extern int do_irrad; |
| 503 |
> |
extern double specjitter; |
| 504 |
> |
extern double specthresh; |
| 505 |
> |
extern int backvis; |
| 506 |
|
char buf[128]; |
| 507 |
|
|
| 508 |
|
if (s[0] == '\0') { |
| 509 |
< |
(*dev->comout)("aa ab ad ar as av ds lr lw sd sp: "); |
| 510 |
< |
(*dev->comin)(buf); |
| 509 |
> |
(*dev->comout)( |
| 510 |
> |
"aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st bv: "); |
| 511 |
> |
(*dev->comin)(buf, NULL); |
| 512 |
|
s = buf; |
| 513 |
|
} |
| 514 |
|
switch (s[0]) { |
| 515 |
|
case 'l': /* limit */ |
| 516 |
|
switch (s[1]) { |
| 517 |
|
case 'w': /* weight */ |
| 518 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 415 |
< |
sprintf(buf, "limit weight (%.6g): ", |
| 416 |
< |
minweight); |
| 417 |
< |
(*dev->comout)(buf); |
| 418 |
< |
(*dev->comin)(buf); |
| 419 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
| 420 |
< |
break; |
| 421 |
< |
} |
| 422 |
< |
minweight = d0; |
| 518 |
> |
getparam(s+2, "limit weight", 'r', &minweight); |
| 519 |
|
break; |
| 520 |
|
case 'r': /* reflection */ |
| 521 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
| 426 |
< |
sprintf(buf, "limit reflection (%d): ", |
| 427 |
< |
maxdepth); |
| 428 |
< |
(*dev->comout)(buf); |
| 429 |
< |
(*dev->comin)(buf); |
| 430 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
| 431 |
< |
break; |
| 432 |
< |
} |
| 433 |
< |
maxdepth = i0; |
| 521 |
> |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
| 522 |
|
break; |
| 523 |
|
default: |
| 524 |
|
goto badparam; |
| 525 |
|
} |
| 526 |
|
break; |
| 527 |
< |
case 'd': /* distribute source */ |
| 528 |
< |
if (s[1] != 's') |
| 527 |
> |
case 'd': /* direct */ |
| 528 |
> |
switch (s[1]) { |
| 529 |
> |
case 'j': /* jitter */ |
| 530 |
> |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
| 531 |
> |
break; |
| 532 |
> |
case 'c': /* certainty */ |
| 533 |
> |
getparam(s+2, "direct certainty", 'r', &shadcert); |
| 534 |
> |
break; |
| 535 |
> |
case 't': /* threshold */ |
| 536 |
> |
getparam(s+2, "direct threshold", 'r', &shadthresh); |
| 537 |
> |
break; |
| 538 |
> |
case 'v': /* visibility */ |
| 539 |
> |
getparam(s+2, "direct visibility", |
| 540 |
> |
'b', &directvis); |
| 541 |
> |
break; |
| 542 |
> |
case 's': /* sampling */ |
| 543 |
> |
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
| 544 |
> |
break; |
| 545 |
> |
default: |
| 546 |
|
goto badparam; |
| 442 |
– |
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 443 |
– |
sprintf(buf, "distribute source (%.6g): ", dstrsrc); |
| 444 |
– |
(*dev->comout)(buf); |
| 445 |
– |
(*dev->comin)(buf); |
| 446 |
– |
if (sscanf(buf, "%lf", &d0) != 1) |
| 447 |
– |
break; |
| 547 |
|
} |
| 449 |
– |
dstrsrc = d0; |
| 548 |
|
break; |
| 549 |
+ |
case 'b': /* back faces or black and white */ |
| 550 |
+ |
switch (s[1]) { |
| 551 |
+ |
case 'v': /* back face visibility */ |
| 552 |
+ |
getparam(s+2, "back face visibility", 'b', &backvis); |
| 553 |
+ |
break; |
| 554 |
+ |
case '\0': /* black and white */ |
| 555 |
+ |
case ' ': |
| 556 |
+ |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
| 557 |
+ |
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
| 558 |
+ |
getparam(s+1, "black and white", 'b', &greyscale); |
| 559 |
+ |
break; |
| 560 |
+ |
default: |
| 561 |
+ |
goto badparam; |
| 562 |
+ |
} |
| 563 |
+ |
break; |
| 564 |
+ |
case 'i': /* irradiance */ |
| 565 |
+ |
getparam(s+1, "irradiance", 'b', &do_irrad); |
| 566 |
+ |
break; |
| 567 |
|
case 'a': /* ambient */ |
| 568 |
|
switch (s[1]) { |
| 569 |
|
case 'v': /* value */ |
| 570 |
< |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
| 455 |
< |
sprintf(buf, |
| 456 |
< |
"ambient value (%.6g %.6g %.6g): ", |
| 457 |
< |
colval(ambval,RED), |
| 458 |
< |
colval(ambval,GRN), |
| 459 |
< |
colval(ambval,BLU)); |
| 460 |
< |
(*dev->comout)(buf); |
| 461 |
< |
(*dev->comin)(buf); |
| 462 |
< |
if (sscanf(buf, "%lf %lf %lf", |
| 463 |
< |
&d0, &d1, &d2) != 3) |
| 464 |
< |
break; |
| 465 |
< |
} |
| 466 |
< |
setcolor(ambval, d0, d1, d2); |
| 570 |
> |
getparam(s+2, "ambient value", 'C', (COLOR *)ambval); |
| 571 |
|
break; |
| 572 |
|
case 'a': /* accuracy */ |
| 573 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 574 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
| 471 |
< |
ambacc); |
| 472 |
< |
(*dev->comout)(buf); |
| 473 |
< |
(*dev->comin)(buf); |
| 474 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
| 475 |
< |
break; |
| 476 |
< |
} |
| 477 |
< |
ambacc = d0; |
| 573 |
> |
if (getparam(s+2, "ambient accuracy", 'r', &ambacc)) |
| 574 |
> |
setambacc(ambacc); |
| 575 |
|
break; |
| 576 |
|
case 'd': /* divisions */ |
| 577 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
| 481 |
< |
sprintf(buf, "ambient divisions (%d): ", |
| 482 |
< |
ambdiv); |
| 483 |
< |
(*dev->comout)(buf); |
| 484 |
< |
(*dev->comin)(buf); |
| 485 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
| 486 |
< |
break; |
| 487 |
< |
} |
| 488 |
< |
ambdiv = i0; |
| 577 |
> |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
| 578 |
|
break; |
| 579 |
|
case 's': /* samples */ |
| 580 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
| 492 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
| 493 |
< |
ambssamp); |
| 494 |
< |
(*dev->comout)(buf); |
| 495 |
< |
(*dev->comin)(buf); |
| 496 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
| 497 |
< |
break; |
| 498 |
< |
} |
| 499 |
< |
ambssamp = i0; |
| 580 |
> |
getparam(s+2, "ambient super-samples", 'i', &ambssamp); |
| 581 |
|
break; |
| 582 |
|
case 'b': /* bounces */ |
| 583 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
| 503 |
< |
sprintf(buf, "ambient bounces (%d): ", |
| 504 |
< |
ambounce); |
| 505 |
< |
(*dev->comout)(buf); |
| 506 |
< |
(*dev->comin)(buf); |
| 507 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
| 508 |
< |
break; |
| 509 |
< |
} |
| 510 |
< |
ambounce = i0; |
| 583 |
> |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
| 584 |
|
break; |
| 585 |
|
case 'r': |
| 586 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
| 587 |
< |
sprintf(buf, "ambient resolution (%d): ", |
| 515 |
< |
ambres); |
| 516 |
< |
(*dev->comout)(buf); |
| 517 |
< |
(*dev->comin)(buf); |
| 518 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
| 519 |
< |
break; |
| 520 |
< |
} |
| 521 |
< |
ambres = i0; |
| 522 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
| 586 |
> |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
| 587 |
> |
setambres(ambres); |
| 588 |
|
break; |
| 589 |
|
default: |
| 590 |
|
goto badparam; |
| 591 |
|
} |
| 592 |
|
break; |
| 593 |
< |
case 's': /* sample */ |
| 593 |
> |
case 'p': /* pixel */ |
| 594 |
|
switch (s[1]) { |
| 595 |
< |
case 'p': /* pixel */ |
| 596 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
| 597 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
| 533 |
< |
(*dev->comout)(buf); |
| 534 |
< |
(*dev->comin)(buf); |
| 535 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
| 536 |
< |
break; |
| 537 |
< |
} |
| 538 |
< |
psample = i0; |
| 539 |
< |
pdepth = 0; |
| 595 |
> |
case 's': /* sample */ |
| 596 |
> |
if (getparam(s+2, "pixel sample", 'i', &psample)) |
| 597 |
> |
pdepth = 0; |
| 598 |
|
break; |
| 599 |
< |
case 'd': /* difference */ |
| 600 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 601 |
< |
sprintf(buf, "sample difference (%.6g): ", |
| 544 |
< |
maxdiff); |
| 545 |
< |
(*dev->comout)(buf); |
| 546 |
< |
(*dev->comin)(buf); |
| 547 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
| 548 |
< |
break; |
| 549 |
< |
} |
| 550 |
< |
maxdiff = d0; |
| 551 |
< |
pdepth = 0; |
| 599 |
> |
case 't': /* threshold */ |
| 600 |
> |
if (getparam(s+2, "pixel threshold", 'r', &maxdiff)) |
| 601 |
> |
pdepth = 0; |
| 602 |
|
break; |
| 603 |
|
default: |
| 604 |
|
goto badparam; |
| 605 |
|
} |
| 606 |
|
break; |
| 607 |
+ |
case 's': /* specular */ |
| 608 |
+ |
switch (s[1]) { |
| 609 |
+ |
case 'j': /* jitter */ |
| 610 |
+ |
getparam(s+2, "specular jitter", 'r', &specjitter); |
| 611 |
+ |
break; |
| 612 |
+ |
case 't': /* threshold */ |
| 613 |
+ |
getparam(s+2, "specular threshold", 'r', &specthresh); |
| 614 |
+ |
break; |
| 615 |
+ |
default: |
| 616 |
+ |
goto badparam; |
| 617 |
+ |
} |
| 618 |
+ |
break; |
| 619 |
|
case '\0': /* nothing */ |
| 620 |
|
break; |
| 621 |
|
default:; |
| 622 |
|
badparam: |
| 623 |
+ |
*sskip(s) = '\0'; |
| 624 |
|
sprintf(errmsg, "%s: unknown variable", s); |
| 625 |
|
error(COMMAND, errmsg); |
| 626 |
|
break; |
| 635 |
|
int x, y; |
| 636 |
|
RAY thisray; |
| 637 |
|
|
| 638 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
| 576 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
| 577 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
| 638 |
> |
thisray.rmax = 0.0; |
| 639 |
|
|
| 640 |
+ |
if (!sscanvec(s, thisray.rorg) || |
| 641 |
+ |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
| 642 |
+ |
|
| 643 |
|
if (dev->getcur == NULL) |
| 644 |
|
return; |
| 645 |
|
(*dev->comout)("Pick ray\n"); |
| 646 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
| 647 |
|
return; |
| 648 |
|
|
| 649 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
| 650 |
< |
|
| 649 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
| 650 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
| 651 |
> |
error(COMMAND, "not on image"); |
| 652 |
> |
return; |
| 653 |
> |
} |
| 654 |
> |
|
| 655 |
|
} else if (normalize(thisray.rdir) == 0.0) { |
| 656 |
|
error(COMMAND, "zero ray direction"); |
| 657 |
|
return; |
| 664 |
|
if (thisray.ro == NULL) |
| 665 |
|
(*dev->comout)("ray hit nothing"); |
| 666 |
|
else { |
| 667 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
| 668 |
< |
objptr(thisray.ro->omod)->oname, |
| 667 |
> |
sprintf(buf, "ray hit %s%s %s \"%s\"", |
| 668 |
> |
thisray.rod < 0.0 ? "back of " : "", |
| 669 |
> |
thisray.ro->omod == OVOID ? VOIDID : |
| 670 |
> |
objptr(thisray.ro->omod)->oname, |
| 671 |
|
ofun[thisray.ro->otype].funame, |
| 672 |
|
thisray.ro->oname); |
| 673 |
|
(*dev->comout)(buf); |
| 674 |
< |
(*dev->comin)(buf); |
| 674 |
> |
(*dev->comin)(buf, NULL); |
| 675 |
|
if (thisray.rot >= FHUGE) |
| 676 |
|
(*dev->comout)("at infinity"); |
| 677 |
|
else { |
| 679 |
|
thisray.rop[1], thisray.rop[2]); |
| 680 |
|
(*dev->comout)(buf); |
| 681 |
|
} |
| 682 |
< |
(*dev->comin)(buf); |
| 683 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
| 682 |
> |
(*dev->comin)(buf, NULL); |
| 683 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", |
| 684 |
|
colval(thisray.rcol,RED), |
| 685 |
|
colval(thisray.rcol,GRN), |
| 686 |
< |
colval(thisray.rcol,BLU)); |
| 686 |
> |
colval(thisray.rcol,BLU), |
| 687 |
> |
luminance(thisray.rcol)); |
| 688 |
|
(*dev->comout)(buf); |
| 689 |
|
} |
| 690 |
< |
(*dev->comin)(buf); |
| 690 |
> |
(*dev->comin)(buf, NULL); |
| 691 |
|
} |
| 692 |
|
|
| 693 |
|
|
| 695 |
|
char *s; |
| 696 |
|
{ |
| 697 |
|
static char buf[128]; |
| 698 |
< |
char *fname, *getpath(); |
| 698 |
> |
char *fname; |
| 699 |
|
FILE *fp; |
| 700 |
|
COLR *scanline; |
| 701 |
|
int y; |
| 702 |
|
|
| 703 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
| 703 |
> |
while (isspace(*s)) |
| 704 |
> |
s++; |
| 705 |
> |
if (*s) |
| 706 |
> |
atos(buf, sizeof(buf), s); |
| 707 |
> |
else if (buf[0] == '\0') { |
| 708 |
|
error(COMMAND, "no file"); |
| 709 |
|
return; |
| 710 |
|
} |
| 711 |
< |
if ((fname = getpath(buf, NULL)) == NULL || |
| 711 |
> |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
| 712 |
|
(fp = fopen(fname, "w")) == NULL) { |
| 713 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
| 714 |
|
error(COMMAND, errmsg); |
| 715 |
|
return; |
| 716 |
|
} |
| 717 |
+ |
#ifdef MSDOS |
| 718 |
+ |
setmode(fileno(fp), O_BINARY); |
| 719 |
+ |
#endif |
| 720 |
|
(*dev->comout)("writing \""); |
| 721 |
|
(*dev->comout)(fname); |
| 722 |
|
(*dev->comout)("\"...\n"); |
| 723 |
|
/* write header */ |
| 724 |
+ |
newheader("RADIANCE", fp); |
| 725 |
|
fputs(progname, fp); |
| 726 |
|
fprintview(&ourview, fp); |
| 727 |
< |
fputs("\n", fp); |
| 727 |
> |
if (octname != NULL) |
| 728 |
> |
fprintf(fp, " %s\n", octname); |
| 729 |
> |
else |
| 730 |
> |
putc('\n', fp); |
| 731 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
| 732 |
|
if (exposure != 1.0) |
| 733 |
< |
fprintf(fp, "EXPOSURE=%e\n", exposure); |
| 734 |
< |
fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu); |
| 733 |
> |
fputexpos(exposure, fp); |
| 734 |
> |
if (dev->pixaspect != 1.0) |
| 735 |
> |
fputaspect(dev->pixaspect, fp); |
| 736 |
> |
fputformat(COLRFMT, fp); |
| 737 |
> |
putc('\n', fp); |
| 738 |
> |
fprtresolu(hresolu, vresolu, fp); |
| 739 |
|
|
| 740 |
< |
scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR)); |
| 741 |
< |
if (scanline == NULL) |
| 742 |
< |
error(SYSTEM, "out of memory in writepict"); |
| 743 |
< |
for (y = ourview.vresolu-1; y >= 0; y--) { |
| 744 |
< |
getpictcolrs(y, scanline, &ptrunk, |
| 745 |
< |
ourview.hresolu, ourview.vresolu); |
| 746 |
< |
if (fwritecolrs(scanline, ourview.hresolu, fp) < 0) |
| 740 |
> |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
| 741 |
> |
if (scanline == NULL) { |
| 742 |
> |
error(COMMAND, "not enough memory!"); |
| 743 |
> |
fclose(fp); |
| 744 |
> |
unlink(fname); |
| 745 |
> |
return; |
| 746 |
> |
} |
| 747 |
> |
for (y = vresolu-1; y >= 0; y--) { |
| 748 |
> |
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
| 749 |
> |
if (fwritecolrs(scanline, hresolu, fp) < 0) |
| 750 |
|
break; |
| 751 |
|
} |
| 752 |
+ |
free((char *)scanline); |
| 753 |
|
if (fclose(fp) < 0) |
| 754 |
|
error(COMMAND, "write error"); |
| 664 |
– |
free((char *)scanline); |
| 755 |
|
} |