1 |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* rv2.c - command routines used in tracing a view. |
9 |
* |
10 |
* 3/24/87 |
11 |
*/ |
12 |
|
13 |
#include "ray.h" |
14 |
|
15 |
#include "octree.h" |
16 |
|
17 |
#include "otypes.h" |
18 |
|
19 |
#include "rpaint.h" |
20 |
|
21 |
#include <ctype.h> |
22 |
|
23 |
#define CTRL(c) ('c'-'@') |
24 |
|
25 |
extern char *progname; |
26 |
|
27 |
|
28 |
getframe(s) /* get a new frame */ |
29 |
char *s; |
30 |
{ |
31 |
if (getrect(s, &pframe) < 0) |
32 |
return; |
33 |
pdepth = 0; |
34 |
} |
35 |
|
36 |
|
37 |
getrepaint(s) /* get area and repaint */ |
38 |
char *s; |
39 |
{ |
40 |
RECT box; |
41 |
|
42 |
if (getrect(s, &box) < 0) |
43 |
return; |
44 |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); |
45 |
} |
46 |
|
47 |
|
48 |
getview(s) /* get/show view parameters */ |
49 |
char *s; |
50 |
{ |
51 |
FILE *fp; |
52 |
char buf[128]; |
53 |
char *fname; |
54 |
int change = 0; |
55 |
VIEW nv; |
56 |
|
57 |
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
58 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
59 |
(fp = fopen(fname, "a")) == NULL) { |
60 |
sprintf(errmsg, "cannot open \"%s\"", buf); |
61 |
error(COMMAND, errmsg); |
62 |
return; |
63 |
} |
64 |
fputs(progname, fp); |
65 |
fprintview(&ourview, fp); |
66 |
fputs(sskip(s), fp); |
67 |
fputs("\n", fp); |
68 |
fclose(fp); |
69 |
return; |
70 |
} |
71 |
sprintf(buf, "view type (%c): ", ourview.type); |
72 |
(*dev->comout)(buf); |
73 |
(*dev->comin)(buf, NULL); |
74 |
if (buf[0] == CTRL(C)) return; |
75 |
if (buf[0] && buf[0] != ourview.type) { |
76 |
nv.type = buf[0]; |
77 |
change++; |
78 |
} else |
79 |
nv.type = ourview.type; |
80 |
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
81 |
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
82 |
(*dev->comout)(buf); |
83 |
(*dev->comin)(buf, NULL); |
84 |
if (buf[0] == CTRL(C)) return; |
85 |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) |
86 |
change++; |
87 |
else |
88 |
VCOPY(nv.vp, ourview.vp); |
89 |
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
90 |
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
91 |
(*dev->comout)(buf); |
92 |
(*dev->comin)(buf, NULL); |
93 |
if (buf[0] == CTRL(C)) return; |
94 |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) |
95 |
change++; |
96 |
else |
97 |
VCOPY(nv.vdir, ourview.vdir); |
98 |
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
99 |
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
100 |
(*dev->comout)(buf); |
101 |
(*dev->comin)(buf, NULL); |
102 |
if (buf[0] == CTRL(C)) return; |
103 |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) |
104 |
change++; |
105 |
else |
106 |
VCOPY(nv.vup, ourview.vup); |
107 |
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
108 |
ourview.horiz, ourview.vert); |
109 |
(*dev->comout)(buf); |
110 |
(*dev->comin)(buf, NULL); |
111 |
if (buf[0] == CTRL(C)) return; |
112 |
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
113 |
change++; |
114 |
else { |
115 |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
116 |
} |
117 |
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
118 |
ourview.hoff, ourview.voff); |
119 |
(*dev->comout)(buf); |
120 |
(*dev->comin)(buf, NULL); |
121 |
if (buf[0] == CTRL(C)) return; |
122 |
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
123 |
change++; |
124 |
else { |
125 |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
126 |
} |
127 |
if (change) |
128 |
newview(&nv); |
129 |
} |
130 |
|
131 |
|
132 |
lastview(s) /* return to a previous view */ |
133 |
char *s; |
134 |
{ |
135 |
char buf[128]; |
136 |
char *fname; |
137 |
int success; |
138 |
VIEW nv; |
139 |
|
140 |
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
141 |
copystruct(&nv, &stdview); |
142 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
143 |
(success = viewfile(fname, &nv, 0, 0)) == -1) { |
144 |
sprintf(errmsg, "cannot open \"%s\"", buf); |
145 |
error(COMMAND, errmsg); |
146 |
return; |
147 |
} |
148 |
if (!success) |
149 |
error(COMMAND, "wrong file format"); |
150 |
else |
151 |
newview(&nv); |
152 |
return; |
153 |
} |
154 |
if (oldview.type == 0) { /* no old view! */ |
155 |
error(COMMAND, "no previous view"); |
156 |
return; |
157 |
} |
158 |
copystruct(&nv, &ourview); |
159 |
copystruct(&ourview, &oldview); |
160 |
copystruct(&oldview, &nv); |
161 |
newimage(); |
162 |
} |
163 |
|
164 |
|
165 |
getaim(s) /* aim camera */ |
166 |
char *s; |
167 |
{ |
168 |
extern double tan(), atan(); |
169 |
double zfact; |
170 |
VIEW nv; |
171 |
|
172 |
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
173 |
return; |
174 |
VCOPY(nv.vp, ourview.vp); |
175 |
VCOPY(nv.vup, ourview.vup); |
176 |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
177 |
if ((nv.type = ourview.type) == VT_PAR) { |
178 |
nv.horiz = ourview.horiz / zfact; |
179 |
nv.vert = ourview.vert / zfact; |
180 |
} else { |
181 |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
182 |
(PI/180./2.); |
183 |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
184 |
(PI/180./2.); |
185 |
} |
186 |
newview(&nv); |
187 |
} |
188 |
|
189 |
|
190 |
getmove(s) /* move camera */ |
191 |
char *s; |
192 |
{ |
193 |
FVECT vc; |
194 |
double mag; |
195 |
|
196 |
if (getinterest(s, 0, vc, &mag) < 0) |
197 |
return; |
198 |
moveview(0.0, 0.0, mag, vc); |
199 |
} |
200 |
|
201 |
|
202 |
getrotate(s) /* rotate camera */ |
203 |
char *s; |
204 |
{ |
205 |
extern double normalize(), tan(), atan(); |
206 |
VIEW nv; |
207 |
FVECT v1; |
208 |
double angle, elev, zfact; |
209 |
|
210 |
elev = 0.0; zfact = 1.0; |
211 |
if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) { |
212 |
error(COMMAND, "missing angle"); |
213 |
return; |
214 |
} |
215 |
VCOPY(nv.vp, ourview.vp); |
216 |
VCOPY(nv.vup, ourview.vup); |
217 |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
218 |
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
219 |
if (elev != 0.0) { |
220 |
fcross(v1, nv.vdir, ourview.vup); |
221 |
normalize(v1); |
222 |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
223 |
} |
224 |
if ((nv.type = ourview.type) == VT_PAR) { |
225 |
nv.horiz = ourview.horiz / zfact; |
226 |
nv.vert = ourview.vert / zfact; |
227 |
} else { |
228 |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
229 |
(PI/180./2.); |
230 |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
231 |
(PI/180./2.); |
232 |
} |
233 |
newview(&nv); |
234 |
} |
235 |
|
236 |
|
237 |
getpivot(s) /* pivot viewpoint */ |
238 |
register char *s; |
239 |
{ |
240 |
FVECT vc; |
241 |
double angle, elev, mag; |
242 |
|
243 |
elev = 0.0; |
244 |
if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { |
245 |
error(COMMAND, "missing angle"); |
246 |
return; |
247 |
} |
248 |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
249 |
return; |
250 |
moveview(angle, elev, mag, vc); |
251 |
} |
252 |
|
253 |
|
254 |
getexposure(s) /* get new exposure */ |
255 |
char *s; |
256 |
{ |
257 |
double atof(), pow(), fabs(); |
258 |
char buf[128]; |
259 |
register char *cp; |
260 |
register PNODE *p; |
261 |
RECT r; |
262 |
int x, y; |
263 |
double e; |
264 |
|
265 |
for (cp = s; isspace(*cp); cp++) |
266 |
; |
267 |
if (*cp == '\0') { /* normalize to point */ |
268 |
if (dev->getcur == NULL) |
269 |
return; |
270 |
(*dev->comout)("Pick point for exposure\n"); |
271 |
if ((*dev->getcur)(&x, &y) == ABORT) |
272 |
return; |
273 |
r.l = r.d = 0; |
274 |
r.r = hresolu; r.u = vresolu; |
275 |
p = findrect(x, y, &ptrunk, &r, -1); |
276 |
e = 1.0; |
277 |
} else { |
278 |
if (*cp == '=') { /* absolute setting */ |
279 |
p = NULL; |
280 |
e = 1.0/exposure; |
281 |
for (cp++; isspace(*cp); cp++) |
282 |
; |
283 |
if (*cp == '\0') { /* interactive */ |
284 |
sprintf(buf, "exposure (%lf): ", exposure); |
285 |
(*dev->comout)(buf); |
286 |
(*dev->comin)(buf, NULL); |
287 |
for (cp = buf; isspace(*cp); cp++) |
288 |
; |
289 |
if (*cp == '\0') |
290 |
return; |
291 |
} |
292 |
} else { /* normalize to average */ |
293 |
p = &ptrunk; |
294 |
e = 1.0; |
295 |
} |
296 |
if (*cp == '+' || *cp == '-') /* f-stops */ |
297 |
e *= pow(2.0, atof(cp)); |
298 |
else /* multiplier */ |
299 |
e *= atof(cp); |
300 |
} |
301 |
if (p != NULL) { /* relative setting */ |
302 |
if (bright(p->v) <= FTINY) { |
303 |
error(COMMAND, "cannot normalize to zero"); |
304 |
return; |
305 |
} |
306 |
e *= 0.5 / bright(p->v); |
307 |
} |
308 |
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
309 |
return; |
310 |
scalepict(&ptrunk, e); |
311 |
exposure *= e; |
312 |
redraw(); |
313 |
} |
314 |
|
315 |
|
316 |
setparam(s) /* get/set program parameter */ |
317 |
register char *s; |
318 |
{ |
319 |
extern int psample; |
320 |
extern double maxdiff; |
321 |
extern double minweight; |
322 |
extern int maxdepth; |
323 |
extern double dstrsrc; |
324 |
extern double shadthresh; |
325 |
extern double shadcert; |
326 |
extern COLOR ambval; |
327 |
extern double ambacc; |
328 |
extern double minarad; |
329 |
extern int ambres; |
330 |
extern int ambdiv; |
331 |
extern int ambssamp; |
332 |
extern int ambounce; |
333 |
int i0; |
334 |
double d0, d1, d2; |
335 |
char buf[128]; |
336 |
|
337 |
if (s[0] == '\0') { |
338 |
(*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); |
339 |
(*dev->comin)(buf, NULL); |
340 |
s = buf; |
341 |
} |
342 |
switch (s[0]) { |
343 |
case 'l': /* limit */ |
344 |
switch (s[1]) { |
345 |
case 'w': /* weight */ |
346 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
347 |
sprintf(buf, "limit weight (%.6g): ", |
348 |
minweight); |
349 |
(*dev->comout)(buf); |
350 |
(*dev->comin)(buf, NULL); |
351 |
if (sscanf(buf, "%lf", &d0) != 1) |
352 |
break; |
353 |
} |
354 |
minweight = d0; |
355 |
break; |
356 |
case 'r': /* reflection */ |
357 |
if (sscanf(s+2, "%d", &i0) != 1) { |
358 |
sprintf(buf, "limit reflection (%d): ", |
359 |
maxdepth); |
360 |
(*dev->comout)(buf); |
361 |
(*dev->comin)(buf, NULL); |
362 |
if (sscanf(buf, "%d", &i0) != 1) |
363 |
break; |
364 |
} |
365 |
maxdepth = i0; |
366 |
break; |
367 |
default: |
368 |
goto badparam; |
369 |
} |
370 |
break; |
371 |
case 'd': /* direct */ |
372 |
switch (s[1]) { |
373 |
case 'j': /* jitter */ |
374 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
375 |
sprintf(buf, "direct jitter (%.6g): ", |
376 |
dstrsrc); |
377 |
(*dev->comout)(buf); |
378 |
(*dev->comin)(buf, NULL); |
379 |
if (sscanf(buf, "%lf", &d0) != 1) |
380 |
break; |
381 |
} |
382 |
dstrsrc = d0; |
383 |
break; |
384 |
case 'c': /* certainty */ |
385 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
386 |
sprintf(buf, "direct certainty (%.6g): ", |
387 |
shadcert); |
388 |
(*dev->comout)(buf); |
389 |
(*dev->comin)(buf, NULL); |
390 |
if (sscanf(buf, "%lf", &d0) != 1) |
391 |
break; |
392 |
} |
393 |
shadcert = d0; |
394 |
break; |
395 |
case 't': /* threshold */ |
396 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
397 |
sprintf(buf, "direct threshold (%.6g): ", |
398 |
shadthresh); |
399 |
(*dev->comout)(buf); |
400 |
(*dev->comin)(buf, NULL); |
401 |
if (sscanf(buf, "%lf", &d0) != 1) |
402 |
break; |
403 |
} |
404 |
shadthresh = d0; |
405 |
break; |
406 |
default: |
407 |
goto badparam; |
408 |
} |
409 |
break; |
410 |
case 'a': /* ambient */ |
411 |
switch (s[1]) { |
412 |
case 'v': /* value */ |
413 |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
414 |
sprintf(buf, |
415 |
"ambient value (%.6g %.6g %.6g): ", |
416 |
colval(ambval,RED), |
417 |
colval(ambval,GRN), |
418 |
colval(ambval,BLU)); |
419 |
(*dev->comout)(buf); |
420 |
(*dev->comin)(buf, NULL); |
421 |
if (sscanf(buf, "%lf %lf %lf", |
422 |
&d0, &d1, &d2) != 3) |
423 |
break; |
424 |
} |
425 |
setcolor(ambval, d0, d1, d2); |
426 |
break; |
427 |
case 'a': /* accuracy */ |
428 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
429 |
sprintf(buf, "ambient accuracy (%.6g): ", |
430 |
ambacc); |
431 |
(*dev->comout)(buf); |
432 |
(*dev->comin)(buf, NULL); |
433 |
if (sscanf(buf, "%lf", &d0) != 1) |
434 |
break; |
435 |
} |
436 |
ambacc = d0; |
437 |
break; |
438 |
case 'd': /* divisions */ |
439 |
if (sscanf(s+2, "%d", &i0) != 1) { |
440 |
sprintf(buf, "ambient divisions (%d): ", |
441 |
ambdiv); |
442 |
(*dev->comout)(buf); |
443 |
(*dev->comin)(buf, NULL); |
444 |
if (sscanf(buf, "%d", &i0) != 1) |
445 |
break; |
446 |
} |
447 |
ambdiv = i0; |
448 |
break; |
449 |
case 's': /* samples */ |
450 |
if (sscanf(s+2, "%d", &i0) != 1) { |
451 |
sprintf(buf, "ambient super-samples (%d): ", |
452 |
ambssamp); |
453 |
(*dev->comout)(buf); |
454 |
(*dev->comin)(buf, NULL); |
455 |
if (sscanf(buf, "%d", &i0) != 1) |
456 |
break; |
457 |
} |
458 |
ambssamp = i0; |
459 |
break; |
460 |
case 'b': /* bounces */ |
461 |
if (sscanf(s+2, "%d", &i0) != 1) { |
462 |
sprintf(buf, "ambient bounces (%d): ", |
463 |
ambounce); |
464 |
(*dev->comout)(buf); |
465 |
(*dev->comin)(buf, NULL); |
466 |
if (sscanf(buf, "%d", &i0) != 1) |
467 |
break; |
468 |
} |
469 |
ambounce = i0; |
470 |
break; |
471 |
case 'r': |
472 |
if (sscanf(s+2, "%d", &i0) != 1) { |
473 |
sprintf(buf, "ambient resolution (%d): ", |
474 |
ambres); |
475 |
(*dev->comout)(buf); |
476 |
(*dev->comin)(buf, NULL); |
477 |
if (sscanf(buf, "%d", &i0) != 1) |
478 |
break; |
479 |
} |
480 |
ambres = i0; |
481 |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
482 |
break; |
483 |
default: |
484 |
goto badparam; |
485 |
} |
486 |
break; |
487 |
case 's': /* sample */ |
488 |
switch (s[1]) { |
489 |
case 'p': /* pixel */ |
490 |
if (sscanf(s+2, "%d", &i0) != 1) { |
491 |
sprintf(buf, "sample pixel (%d): ", psample); |
492 |
(*dev->comout)(buf); |
493 |
(*dev->comin)(buf, NULL); |
494 |
if (sscanf(buf, "%d", &i0) != 1) |
495 |
break; |
496 |
} |
497 |
psample = i0; |
498 |
pdepth = 0; |
499 |
break; |
500 |
case 't': /* threshold */ |
501 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
502 |
sprintf(buf, "sample threshold (%.6g): ", |
503 |
maxdiff); |
504 |
(*dev->comout)(buf); |
505 |
(*dev->comin)(buf, NULL); |
506 |
if (sscanf(buf, "%lf", &d0) != 1) |
507 |
break; |
508 |
} |
509 |
maxdiff = d0; |
510 |
pdepth = 0; |
511 |
break; |
512 |
default: |
513 |
goto badparam; |
514 |
} |
515 |
break; |
516 |
case '\0': /* nothing */ |
517 |
break; |
518 |
default:; |
519 |
badparam: |
520 |
sprintf(errmsg, "%s: unknown variable", s); |
521 |
error(COMMAND, errmsg); |
522 |
break; |
523 |
} |
524 |
} |
525 |
|
526 |
|
527 |
traceray(s) /* trace a single ray */ |
528 |
char *s; |
529 |
{ |
530 |
char buf[128]; |
531 |
int x, y; |
532 |
RAY thisray; |
533 |
|
534 |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
535 |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
536 |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
537 |
|
538 |
if (dev->getcur == NULL) |
539 |
return; |
540 |
(*dev->comout)("Pick ray\n"); |
541 |
if ((*dev->getcur)(&x, &y) == ABORT) |
542 |
return; |
543 |
|
544 |
viewray(thisray.rorg, thisray.rdir, &ourview, |
545 |
(x+.5)/hresolu, (y+.5)/vresolu); |
546 |
|
547 |
} else if (normalize(thisray.rdir) == 0.0) { |
548 |
error(COMMAND, "zero ray direction"); |
549 |
return; |
550 |
} |
551 |
|
552 |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
553 |
|
554 |
rayvalue(&thisray); |
555 |
|
556 |
if (thisray.ro == NULL) |
557 |
(*dev->comout)("ray hit nothing"); |
558 |
else { |
559 |
sprintf(buf, "ray hit %s %s \"%s\"", |
560 |
objptr(thisray.ro->omod)->oname, |
561 |
ofun[thisray.ro->otype].funame, |
562 |
thisray.ro->oname); |
563 |
(*dev->comout)(buf); |
564 |
(*dev->comin)(buf, NULL); |
565 |
if (thisray.rot >= FHUGE) |
566 |
(*dev->comout)("at infinity"); |
567 |
else { |
568 |
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
569 |
thisray.rop[1], thisray.rop[2]); |
570 |
(*dev->comout)(buf); |
571 |
} |
572 |
(*dev->comin)(buf, NULL); |
573 |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
574 |
colval(thisray.rcol,RED), |
575 |
colval(thisray.rcol,GRN), |
576 |
colval(thisray.rcol,BLU)); |
577 |
(*dev->comout)(buf); |
578 |
} |
579 |
(*dev->comin)(buf, NULL); |
580 |
} |
581 |
|
582 |
|
583 |
writepict(s) /* write the picture to a file */ |
584 |
char *s; |
585 |
{ |
586 |
static char buf[128]; |
587 |
char *fname; |
588 |
FILE *fp; |
589 |
COLR *scanline; |
590 |
int y; |
591 |
|
592 |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
593 |
error(COMMAND, "no file"); |
594 |
return; |
595 |
} |
596 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
597 |
(fp = fopen(fname, "w")) == NULL) { |
598 |
sprintf(errmsg, "cannot open \"%s\"", buf); |
599 |
error(COMMAND, errmsg); |
600 |
return; |
601 |
} |
602 |
(*dev->comout)("writing \""); |
603 |
(*dev->comout)(fname); |
604 |
(*dev->comout)("\"...\n"); |
605 |
/* write header */ |
606 |
fputs(progname, fp); |
607 |
fprintview(&ourview, fp); |
608 |
putc('\n', fp); |
609 |
if (exposure != 1.0) |
610 |
fputexpos(exposure, fp); |
611 |
if (dev->pixaspect != 1.0) |
612 |
fputaspect(dev->pixaspect, fp); |
613 |
putc('\n', fp); |
614 |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
615 |
|
616 |
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
617 |
if (scanline == NULL) |
618 |
error(SYSTEM, "out of memory in writepict"); |
619 |
for (y = vresolu-1; y >= 0; y--) { |
620 |
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
621 |
if (fwritecolrs(scanline, hresolu, fp) < 0) |
622 |
break; |
623 |
} |
624 |
if (fclose(fp) < 0) |
625 |
error(COMMAND, "write error"); |
626 |
free((char *)scanline); |
627 |
} |