1 |
– |
/* Copyright (c) 1992 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 |
|
* rpict.c - routines and variables for picture generation. |
9 |
– |
* |
10 |
– |
* 8/14/85 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
+ |
#include <sys/types.h> |
13 |
+ |
|
14 |
|
#ifndef NIX |
15 |
|
#ifdef BSD |
16 |
|
#include <sys/time.h> |
17 |
|
#include <sys/resource.h> |
18 |
|
#else |
20 |
– |
#include <sys/types.h> |
19 |
|
#include <sys/times.h> |
20 |
< |
#include <limits.h> |
23 |
< |
extern time_t time(); |
20 |
> |
#include <unistd.h> |
21 |
|
#endif |
25 |
– |
#else |
26 |
– |
extern unsigned long time(); |
22 |
|
#endif |
23 |
|
|
24 |
+ |
#include <time.h> |
25 |
|
#include <signal.h> |
26 |
|
|
27 |
+ |
#include "platform.h" |
28 |
|
#include "view.h" |
32 |
– |
|
33 |
– |
#include "resolu.h" |
34 |
– |
|
29 |
|
#include "random.h" |
36 |
– |
|
30 |
|
#include "paths.h" |
31 |
|
|
32 |
+ |
|
33 |
|
#define RFTEMPLATE "rfXXXXXX" |
34 |
|
|
35 |
|
#ifndef SIGCONT |
36 |
|
#define SIGCONT SIGIO |
37 |
|
#endif |
38 |
|
|
39 |
+ |
CUBE thescene; /* our scene */ |
40 |
+ |
OBJECT nsceneobjs; /* number of objects in our scene */ |
41 |
+ |
|
42 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
43 |
|
int ndims = 0; /* number of sampling dimensions */ |
44 |
|
int samplendx; /* sample index number */ |
45 |
|
|
46 |
+ |
extern void ambnotify(); |
47 |
+ |
void (*addobjnotify[])() = {ambnotify, NULL}; |
48 |
+ |
|
49 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
50 |
|
int hresolu = 512; /* horizontal resolution */ |
51 |
|
int vresolu = 512; /* vertical resolution */ |
55 |
|
double maxdiff = .05; /* max. difference for interpolation */ |
56 |
|
double dstrpix = 0.67; /* square pixel distribution */ |
57 |
|
|
58 |
+ |
double mblur = 0.; /* motion blur parameter */ |
59 |
+ |
|
60 |
+ |
void (*trace)() = NULL; /* trace call */ |
61 |
+ |
|
62 |
+ |
int do_irrad = 0; /* compute irradiance? */ |
63 |
+ |
|
64 |
|
double dstrsrc = 0.0; /* square source distribution */ |
65 |
|
double shadthresh = .05; /* shadow threshold */ |
66 |
|
double shadcert = .5; /* shadow certainty */ |
69 |
|
int directvis = 1; /* sources visible? */ |
70 |
|
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
71 |
|
|
72 |
+ |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
73 |
+ |
COLOR salbedo = BLKCOLOR; /* global scattering albedo */ |
74 |
+ |
double seccg = 0.; /* global scattering eccentricity */ |
75 |
+ |
double ssampdist = 0.; /* scatter sampling distance */ |
76 |
+ |
|
77 |
|
double specthresh = .15; /* specular sampling threshold */ |
78 |
|
double specjitter = 1.; /* specular sampling jitter */ |
79 |
|
|
80 |
+ |
int backvis = 1; /* back face visibility */ |
81 |
+ |
|
82 |
|
int maxdepth = 6; /* maximum recursion depth */ |
83 |
|
double minweight = 5e-3; /* minimum ray weight */ |
84 |
|
|
85 |
+ |
char *ambfile = NULL; /* ambient file name */ |
86 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
87 |
+ |
int ambvwt = 0; /* initial weight for ambient value */ |
88 |
|
double ambacc = 0.2; /* ambient accuracy */ |
89 |
|
int ambres = 32; /* ambient resolution */ |
90 |
|
int ambdiv = 128; /* ambient divisions */ |
93 |
|
char *amblist[128]; /* ambient include/exclude list */ |
94 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
95 |
|
|
81 |
– |
#ifdef MSDOS |
82 |
– |
int ralrm = 60; /* seconds between reports */ |
83 |
– |
#else |
96 |
|
int ralrm = 0; /* seconds between reports */ |
85 |
– |
#endif |
97 |
|
|
98 |
|
double pctdone = 0.0; /* percentage done */ |
99 |
+ |
time_t tlastrept = 0L; /* time at last report */ |
100 |
+ |
time_t tstart; /* starting time */ |
101 |
|
|
89 |
– |
unsigned long tlastrept = 0L; /* time at last report */ |
90 |
– |
|
91 |
– |
extern unsigned long tstart; /* starting time */ |
92 |
– |
|
93 |
– |
extern unsigned long nrays; /* number of rays traced */ |
94 |
– |
|
102 |
|
#define MAXDIV 16 /* maximum sample size */ |
103 |
|
|
104 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
105 |
|
|
106 |
< |
static int hres, vres; /* resolution for this frame */ |
106 |
> |
int hres, vres; /* resolution for this frame */ |
107 |
|
|
108 |
< |
extern char *mktemp(); |
108 |
> |
static VIEW lastview; /* the previous view input */ |
109 |
|
|
110 |
+ |
extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ |
111 |
+ |
|
112 |
+ |
void report(); |
113 |
+ |
|
114 |
|
double pixvalue(); |
115 |
|
|
116 |
|
#ifdef NIX |
129 |
|
#endif |
130 |
|
|
131 |
|
|
132 |
+ |
void |
133 |
|
quit(code) /* quit program */ |
134 |
|
int code; |
135 |
|
{ |
136 |
|
if (code) /* report status */ |
137 |
|
report(); |
138 |
+ |
#ifndef NIX |
139 |
|
headclean(); /* delete header file */ |
140 |
|
pfclean(); /* clean up persist files */ |
141 |
+ |
#endif |
142 |
|
exit(code); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
#ifndef NIX |
147 |
+ |
void |
148 |
|
report() /* report progress */ |
149 |
|
{ |
150 |
< |
char hostname[128]; |
150 |
> |
extern char *myhostname(); |
151 |
|
double u, s; |
152 |
|
#ifdef BSD |
153 |
|
struct rusage rubuf; |
154 |
|
#else |
155 |
|
struct tms tbuf; |
156 |
+ |
double period; |
157 |
|
#endif |
158 |
|
|
159 |
< |
tlastrept = time((unsigned long *)NULL); |
159 |
> |
tlastrept = time((time_t *)NULL); |
160 |
|
#ifdef BSD |
161 |
|
getrusage(RUSAGE_SELF, &rubuf); |
162 |
|
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
166 |
|
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
167 |
|
#else |
168 |
|
times(&tbuf); |
169 |
< |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) / CLK_TCK; |
170 |
< |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) / CLK_TCK; |
169 |
> |
#ifdef _SC_CLK_TCK |
170 |
> |
period = 1.0 / sysconf(_SC_CLK_TCK); |
171 |
> |
#else |
172 |
> |
period = 1.0 / 60.0; |
173 |
|
#endif |
174 |
< |
gethostname(hostname, sizeof(hostname)); |
174 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
175 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
176 |
> |
#endif |
177 |
|
|
178 |
|
sprintf(errmsg, |
179 |
|
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
180 |
|
nrays, pctdone, u/3600., s/3600., |
181 |
< |
(tlastrept-tstart)/3600., hostname); |
181 |
> |
(tlastrept-tstart)/3600., myhostname()); |
182 |
|
eputs(errmsg); |
183 |
+ |
#ifndef BSD |
184 |
+ |
signal(SIGCONT, report); |
185 |
+ |
#endif |
186 |
|
} |
187 |
|
#else |
188 |
+ |
void |
189 |
|
report() /* report progress */ |
190 |
|
{ |
191 |
< |
tlastrept = time((unsigned long *)NULL); |
191 |
> |
tlastrept = time((time_t *)NULL); |
192 |
|
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
193 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
194 |
|
eputs(errmsg); |
171 |
– |
signal(SIGCONT, report); |
195 |
|
} |
196 |
|
#endif |
197 |
|
|
198 |
|
|
199 |
+ |
void |
200 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
201 |
|
int seq; |
202 |
|
char *pout, *zout, *prvr; |
212 |
|
* sequenced file naming. |
213 |
|
*/ |
214 |
|
{ |
191 |
– |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
215 |
|
char fbuf[128], fbuf2[128]; |
216 |
|
int npicts; |
217 |
|
register char *cp; |
238 |
|
for ( ; seq < rn; seq++) |
239 |
|
if (nextview(stdin) == EOF) |
240 |
|
error(USER, "unexpected EOF on view input"); |
241 |
+ |
setview(&ourview); |
242 |
|
prvr = fbuf; /* mark for renaming */ |
243 |
|
} |
244 |
|
if (pout != NULL & prvr != NULL) { |
280 |
|
fbuf); |
281 |
|
error(USER, errmsg); |
282 |
|
} |
283 |
+ |
setview(&ourview); |
284 |
|
continue; /* don't clobber */ |
285 |
|
} |
286 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
288 |
|
"cannot open output file \"%s\"", fbuf); |
289 |
|
error(SYSTEM, errmsg); |
290 |
|
} |
291 |
< |
#ifdef MSDOS |
267 |
< |
setmode(fileno(stdout), O_BINARY); |
268 |
< |
#endif |
291 |
> |
SET_FILE_BINARY(stdout); |
292 |
|
dupheader(); |
293 |
|
} |
294 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
295 |
|
if (prvr != NULL) |
296 |
|
if (viewfile(prvr, &ourview, &rs) <= 0 |
297 |
< |
|| rs.or != PIXSTANDARD) { |
297 |
> |
|| rs.rt != PIXSTANDARD) { |
298 |
|
sprintf(errmsg, |
299 |
|
"cannot recover view parameters from \"%s\"", prvr); |
300 |
|
error(WARNING, errmsg); |
341 |
|
{ |
342 |
|
char linebuf[256]; |
343 |
|
|
344 |
+ |
copystruct(&lastview, &ourview); |
345 |
|
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
346 |
|
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
347 |
|
return(0); |
352 |
|
render(zfile, oldfile) /* render the scene */ |
353 |
|
char *zfile, *oldfile; |
354 |
|
{ |
331 |
– |
extern long lseek(); |
355 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
356 |
|
float *zbar[MAXDIV+1]; /* z values */ |
357 |
|
char *sampdens; /* previous sample density */ |
362 |
|
COLOR *colptr; |
363 |
|
float *zptr; |
364 |
|
register int i; |
365 |
+ |
/* check for empty image */ |
366 |
+ |
if (hres <= 0 || vres <= 0) { |
367 |
+ |
error(WARNING, "empty output picture"); |
368 |
+ |
fprtresolu(0, 0, stdout); |
369 |
+ |
return; |
370 |
+ |
} |
371 |
|
/* allocate scanlines */ |
372 |
|
for (i = 0; i <= psample; i++) { |
373 |
|
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
378 |
|
ystep = (psample*99+70)/140; |
379 |
|
if (hstep > 2) { |
380 |
|
i = hres/hstep + 2; |
381 |
< |
if ((sampdens = malloc(i)) == NULL) |
381 |
> |
if ((sampdens = (char *)malloc(i)) == NULL) |
382 |
|
goto memerr; |
383 |
|
while (i--) |
384 |
|
sampdens[i] = hstep; |
390 |
|
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
391 |
|
error(SYSTEM, errmsg); |
392 |
|
} |
393 |
< |
#ifdef MSDOS |
365 |
< |
setmode(zfd, O_BINARY); |
366 |
< |
#endif |
393 |
> |
SET_FD_BINARY(zfd); |
394 |
|
for (i = 0; i <= psample; i++) { |
395 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
396 |
|
if (zbar[i] == NULL) |
405 |
|
fprtresolu(hres, vres, stdout); |
406 |
|
/* recover file and compute first */ |
407 |
|
i = salvage(oldfile); |
408 |
+ |
if (i >= vres) |
409 |
+ |
goto alldone; |
410 |
|
if (zfd != -1 && i > 0 && |
411 |
< |
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
411 |
> |
lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) |
412 |
|
error(SYSTEM, "z-file seek error in render"); |
413 |
|
pctdone = 100.0*i/vres; |
414 |
|
if (ralrm > 0) /* report init stats */ |
417 |
|
else |
418 |
|
#endif |
419 |
|
signal(SIGCONT, report); |
420 |
< |
ypos = vres-1 - i; |
420 |
> |
ypos = vres-1 - i; /* initialize sampling */ |
421 |
> |
if (directvis) |
422 |
> |
init_drawsources(psample); |
423 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
424 |
|
/* compute scanlines */ |
425 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
439 |
|
hres, ypos, hstep); |
440 |
|
/* fill bar */ |
441 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
442 |
+ |
if (directvis) /* add bitty sources */ |
443 |
+ |
drawsources(scanbar, zbar, 0, hres, ypos, ystep); |
444 |
|
/* write it out */ |
445 |
|
#ifndef BSD |
446 |
|
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
457 |
|
goto writerr; |
458 |
|
/* record progress */ |
459 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
460 |
< |
if (ralrm > 0 && time((unsigned long *)NULL) >= tlastrept+ralrm) |
460 |
> |
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
461 |
|
report(); |
462 |
|
#ifndef BSD |
463 |
|
else |
466 |
|
} |
467 |
|
/* clean up */ |
468 |
|
signal(SIGCONT, SIG_IGN); |
469 |
< |
if (zfd != -1) { |
437 |
< |
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
469 |
> |
if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float)) |
470 |
|
< hres*sizeof(float)) |
471 |
< |
goto writerr; |
471 |
> |
goto writerr; |
472 |
> |
fwritescan(scanbar[0], hres, stdout); |
473 |
> |
if (fflush(stdout) == EOF) |
474 |
> |
goto writerr; |
475 |
> |
alldone: |
476 |
> |
if (zfd != -1) { |
477 |
|
if (close(zfd) == -1) |
478 |
|
goto writerr; |
479 |
|
for (i = 0; i <= psample; i++) |
480 |
< |
free((char *)zbar[i]); |
480 |
> |
free((void *)zbar[i]); |
481 |
|
} |
445 |
– |
fwritescan(scanbar[0], hres, stdout); |
446 |
– |
if (fflush(stdout) == EOF) |
447 |
– |
goto writerr; |
482 |
|
for (i = 0; i <= psample; i++) |
483 |
< |
free((char *)scanbar[i]); |
483 |
> |
free((void *)scanbar[i]); |
484 |
|
if (sampdens != NULL) |
485 |
|
free(sampdens); |
486 |
|
pctdone = 100.0; |
505 |
|
int bl = xstep, b = xstep; |
506 |
|
double z; |
507 |
|
register int i; |
508 |
< |
|
508 |
> |
|
509 |
|
z = pixvalue(scanline[0], 0, y); |
510 |
|
if (zline) zline[0] = z; |
511 |
|
/* zig-zag start for quincunx pattern */ |
521 |
|
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
522 |
|
else |
523 |
|
b = fillsample(scanline+i-xstep, |
524 |
< |
zline ? zline+i-xstep : NULL, |
524 |
> |
zline ? zline+i-xstep : (float *)NULL, |
525 |
|
i-xstep, y, xstep, 0, b/2); |
526 |
|
if (sd) *sd++ = nc & 1 ? bl : b; |
527 |
|
bl = b; |
539 |
|
float zline[MAXDIV+1]; |
540 |
|
int b = ysize; |
541 |
|
register int i, j; |
542 |
< |
|
542 |
> |
|
543 |
|
for (i = 0; i < xres; i++) { |
510 |
– |
|
544 |
|
copycolor(vline[0], scanbar[0][i]); |
545 |
|
copycolor(vline[ysize], scanbar[ysize][i]); |
546 |
|
if (zbar[0]) { |
547 |
|
zline[0] = zbar[0][i]; |
548 |
|
zline[ysize] = zbar[ysize][i]; |
549 |
|
} |
550 |
< |
|
518 |
< |
b = fillsample(vline, zbar[0] ? zline : NULL, |
550 |
> |
b = fillsample(vline, zbar[0] ? zline : (float *)NULL, |
551 |
|
i, y, 0, ysize, b/2); |
552 |
< |
|
552 |
> |
|
553 |
|
for (j = 1; j < ysize; j++) |
554 |
|
copycolor(scanbar[j][i], vline[j]); |
555 |
|
if (zbar[0]) |
572 |
|
COLOR ctmp; |
573 |
|
int ncut; |
574 |
|
register int len; |
575 |
< |
|
575 |
> |
|
576 |
|
if (xlen > 0) /* x or y length is zero */ |
577 |
|
len = xlen; |
578 |
|
else |
579 |
|
len = ylen; |
580 |
< |
|
580 |
> |
|
581 |
|
if (len <= 1) /* limit recursion */ |
582 |
|
return(0); |
583 |
< |
|
584 |
< |
if (b > 0 |
585 |
< |
|| (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len])) |
583 |
> |
|
584 |
> |
if (b > 0 || |
585 |
> |
(zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len])) |
586 |
|
|| bigdiff(colline[0], colline[len], maxdiff)) { |
587 |
< |
|
587 |
> |
|
588 |
|
z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1)); |
589 |
|
if (zline) zline[len>>1] = z; |
590 |
|
ncut = 1; |
559 |
– |
|
591 |
|
} else { /* interpolate */ |
561 |
– |
|
592 |
|
copycolor(colline[len>>1], colline[len]); |
593 |
|
ratio = (double)(len>>1) / len; |
594 |
|
scalecolor(colline[len>>1], ratio); |
602 |
|
} |
603 |
|
/* recurse */ |
604 |
|
ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2); |
605 |
< |
|
606 |
< |
ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL, |
605 |
> |
|
606 |
> |
ncut += fillsample(colline+(len>>1), |
607 |
> |
zline ? zline+(len>>1) : (float *)NULL, |
608 |
|
x+(xlen>>1), y+(ylen>>1), |
609 |
|
xlen-(xlen>>1), ylen-(ylen>>1), b/2); |
610 |
|
|
617 |
|
COLOR col; /* returned color */ |
618 |
|
int x, y; /* pixel position */ |
619 |
|
{ |
620 |
< |
static RAY thisray; |
621 |
< |
|
622 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
623 |
< |
(x+pixjitter())/hres, (y+pixjitter())/vres) < 0) { |
620 |
> |
RAY thisray; |
621 |
> |
FVECT lorg, ldir; |
622 |
> |
double hpos, vpos, lmax, d; |
623 |
> |
/* compute view ray */ |
624 |
> |
hpos = (x+pixjitter())/hres; |
625 |
> |
vpos = (y+pixjitter())/vres; |
626 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
627 |
> |
&ourview, hpos, vpos)) < -FTINY) { |
628 |
|
setcolor(col, 0.0, 0.0, 0.0); |
629 |
|
return(0.0); |
630 |
|
} |
631 |
|
|
597 |
– |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
598 |
– |
|
632 |
|
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ |
633 |
|
|
634 |
+ |
/* optional motion blur */ |
635 |
+ |
if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir, |
636 |
+ |
&lastview, hpos, vpos)) >= -FTINY) { |
637 |
+ |
register int i; |
638 |
+ |
register double d = mblur*(.5-urand(281+samplendx)); |
639 |
+ |
|
640 |
+ |
thisray.rmax = (1.-d)*thisray.rmax + d*lmax; |
641 |
+ |
for (i = 3; i--; ) { |
642 |
+ |
thisray.rorg[i] = (1.-d)*thisray.rorg[i] + d*lorg[i]; |
643 |
+ |
thisray.rdir[i] = (1.-d)*thisray.rdir[i] + d*ldir[i]; |
644 |
+ |
} |
645 |
+ |
if (normalize(thisray.rdir) == 0.0) |
646 |
+ |
return(0.0); |
647 |
+ |
} |
648 |
+ |
|
649 |
+ |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
650 |
+ |
|
651 |
|
rayvalue(&thisray); /* trace ray */ |
652 |
|
|
653 |
|
copycolor(col, thisray.rcol); /* return color */ |
654 |
< |
|
654 |
> |
|
655 |
|
return(thisray.rt); /* return distance */ |
656 |
|
} |
657 |
|
|
665 |
|
int x, y; |
666 |
|
|
667 |
|
if (oldfile == NULL) |
668 |
< |
return(0); |
669 |
< |
|
668 |
> |
goto gotzip; |
669 |
> |
|
670 |
|
if ((fp = fopen(oldfile, "r")) == NULL) { |
671 |
|
sprintf(errmsg, "cannot open recover file \"%s\"", oldfile); |
672 |
|
error(WARNING, errmsg); |
673 |
< |
return(0); |
673 |
> |
goto gotzip; |
674 |
|
} |
675 |
< |
#ifdef MSDOS |
626 |
< |
setmode(fileno(fp), O_BINARY); |
627 |
< |
#endif |
675 |
> |
SET_FILE_BINARY(fp); |
676 |
|
/* discard header */ |
677 |
|
getheader(fp, NULL, NULL); |
678 |
|
/* get picture size */ |
681 |
|
oldfile); |
682 |
|
error(WARNING, errmsg); |
683 |
|
fclose(fp); |
684 |
< |
return(0); |
684 |
> |
goto gotzip; |
685 |
|
} |
686 |
|
|
687 |
|
if (x != hres || y != vres) { |
701 |
|
} |
702 |
|
if (fflush(stdout) == EOF) |
703 |
|
goto writerr; |
704 |
< |
free((char *)scanline); |
704 |
> |
free((void *)scanline); |
705 |
|
fclose(fp); |
706 |
|
unlink(oldfile); |
707 |
|
return(y); |
708 |
+ |
gotzip: |
709 |
+ |
if (fflush(stdout) == EOF) |
710 |
+ |
error(SYSTEM, "error writing picture header"); |
711 |
+ |
return(0); |
712 |
|
writerr: |
713 |
|
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
714 |
|
error(SYSTEM, errmsg); |