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