9 |
|
* Created by Gregory Ward on Wed Jan 08 2003. |
10 |
|
*/ |
11 |
|
|
12 |
< |
/* ==================================================================== |
13 |
< |
* The Radiance Software License, Version 1.0 |
14 |
< |
* |
15 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
16 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
17 |
< |
* |
18 |
< |
* Redistribution and use in source and binary forms, with or without |
19 |
< |
* modification, are permitted provided that the following conditions |
20 |
< |
* are met: |
21 |
< |
* |
22 |
< |
* 1. Redistributions of source code must retain the above copyright |
23 |
< |
* notice, this list of conditions and the following disclaimer. |
24 |
< |
* |
25 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
26 |
< |
* notice, this list of conditions and the following disclaimer in |
27 |
< |
* the documentation and/or other materials provided with the |
28 |
< |
* distribution. |
29 |
< |
* |
30 |
< |
* 3. The end-user documentation included with the redistribution, |
31 |
< |
* if any, must include the following acknowledgment: |
32 |
< |
* "This product includes Radiance software |
33 |
< |
* (http://radsite.lbl.gov/) |
34 |
< |
* developed by the Lawrence Berkeley National Laboratory |
35 |
< |
* (http://www.lbl.gov/)." |
36 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
37 |
< |
* if and wherever such third-party acknowledgments normally appear. |
38 |
< |
* |
39 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
40 |
< |
* and "The Regents of the University of California" must |
41 |
< |
* not be used to endorse or promote products derived from this |
42 |
< |
* software without prior written permission. For written |
43 |
< |
* permission, please contact [email protected]. |
44 |
< |
* |
45 |
< |
* 5. Products derived from this software may not be called "Radiance", |
46 |
< |
* nor may "Radiance" appear in their name, without prior written |
47 |
< |
* permission of Lawrence Berkeley National Laboratory. |
48 |
< |
* |
49 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
50 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
51 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
52 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
53 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
54 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
55 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
56 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
57 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
58 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
59 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
60 |
< |
* SUCH DAMAGE. |
61 |
< |
* ==================================================================== |
62 |
< |
* |
63 |
< |
* This software consists of voluntary contributions made by many |
64 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
65 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
66 |
< |
* <http://www.lbl.gov/>. |
67 |
< |
*/ |
12 |
> |
#include "copyright.h" |
13 |
|
|
14 |
+ |
#include <string.h> |
15 |
+ |
|
16 |
+ |
#include "platform.h" |
17 |
|
#include "ranimove.h" |
18 |
|
#include "otypes.h" |
19 |
|
#include "random.h" |
79 |
|
char *err; |
80 |
|
/* get previous view */ |
81 |
|
if (vw.type != 0) |
82 |
< |
copystruct(&vwprev, &vw); |
82 |
> |
vwprev = vw; |
83 |
|
else if (fcur > 1 && (fv = getview(fcur-1)) != NULL) { |
84 |
< |
copystruct(&vwprev, fv); |
84 |
> |
vwprev = *fv; |
85 |
|
if (setview(&vwprev) != NULL) |
86 |
|
vwprev.type = 0; |
87 |
|
} |
90 |
|
sprintf(errmsg, "cannot get view for frame %d", fcur); |
91 |
|
error(USER, errmsg); |
92 |
|
} |
93 |
< |
copystruct(&vw, fv); |
93 |
> |
vw = *fv; |
94 |
|
if ((err = setview(&vw)) != NULL) { |
95 |
|
sprintf(errmsg, "view error at frame %d: %s", fcur, err); |
96 |
|
error(USER, errmsg); |
106 |
|
pixaspect = 1.; |
107 |
|
/* fall through */ |
108 |
|
case 3: |
109 |
< |
if ((hres > 0 & vres > 0)) |
109 |
> |
if ((hres > 0) & (vres > 0)) |
110 |
|
break; |
111 |
|
/* fall through */ |
112 |
|
default: |
125 |
|
zprev = (float *)malloc(sizeof(float)*hres*vres); |
126 |
|
oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres); |
127 |
|
aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres); |
128 |
< |
if ((cbuffer==NULL | zbuffer==NULL | obuffer==NULL | |
129 |
< |
xmbuffer==NULL | ymbuffer==NULL | |
130 |
< |
abuffer==NULL | sbuffer==NULL | |
131 |
< |
cprev==NULL | zprev == NULL | |
132 |
< |
oprev==NULL | aprev==NULL)) |
128 |
> |
if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) | |
129 |
> |
(xmbuffer==NULL) | (ymbuffer==NULL) | |
130 |
> |
(abuffer==NULL) | (sbuffer==NULL) | |
131 |
> |
(cprev==NULL) | (zprev == NULL) | |
132 |
> |
(oprev==NULL) | (aprev==NULL)) |
133 |
|
error(SYSTEM, "out of memory in init_frame"); |
134 |
|
frm_stop = getTime() + rtperfrm; |
135 |
|
} else { |
141 |
|
fp = zprev; zprev = zbuffer; zbuffer = fp; |
142 |
|
op = oprev; oprev = obuffer; obuffer = op; |
143 |
|
bp = aprev; aprev = abuffer; abuffer = bp; |
144 |
< |
bzero(abuffer, sizeof(BYTE)*hres*vres); |
145 |
< |
bzero(sbuffer, sizeof(BYTE)*hres*vres); |
144 |
> |
memset(abuffer, '\0', sizeof(BYTE)*hres*vres); |
145 |
> |
memset(sbuffer, '\0', sizeof(BYTE)*hres*vres); |
146 |
|
frm_stop += rtperfrm; |
147 |
|
} |
148 |
|
cerrmap = NULL; |
186 |
|
int xo, yo; |
187 |
|
{ |
188 |
|
static double etab[400]; |
189 |
< |
int rad2 = xo*xo + yo*yo; |
189 |
> |
/* we can't use the name rad2 here, for some reason Visual C |
190 |
> |
thinks that is a constant (compiler bug?) */ |
191 |
> |
int rad_2 = xo*xo + yo*yo; |
192 |
|
int i; |
193 |
|
|
194 |
|
if (etab[0] <= FTINY) /* initialize exponent table */ |
196 |
|
etab[i] = exp(-0.1*i); |
197 |
|
|
198 |
|
/* look up Gaussian */ |
199 |
< |
i = (int)((10.*3./(double)SAMPDIST2)*rad2 + .5); |
199 |
> |
i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5); |
200 |
|
if (i >= 400) |
201 |
|
return(0.0); |
202 |
|
return(etab[i]); |
226 |
|
/* get our object number */ |
227 |
|
myobj = obuffer[fndx(x, y)]; |
228 |
|
/* special case for borders */ |
229 |
< |
if ((x < SAMPDIST | x >= hres-SAMPDIST | |
230 |
< |
y < SAMPDIST | y >= vres-SAMPDIST)) { |
229 |
> |
if ((x < SAMPDIST) | (x >= hres-SAMPDIST) | |
230 |
> |
(y < SAMPDIST) | (y >= vres-SAMPDIST)) { |
231 |
|
int tndx[NSCHECK][2]; |
232 |
|
nf = 0; |
233 |
|
for (j = y - SAMPDIST; j <= y + SAMPDIST; j++) { |
239 |
|
i0 = fndx(i, j); |
240 |
|
if (!sbuffer[i0]) |
241 |
|
continue; |
242 |
< |
if ((myobj != OVOID & obuffer[i0] != myobj)) |
242 |
> |
if ((myobj != OVOID) & (obuffer[i0] != myobj)) |
243 |
|
continue; |
244 |
|
tndx[nf][0] = (i-x)*(i-x) + (j-y)*(j-y); |
245 |
|
tndx[nf][1] = i0; |
254 |
|
return(nf); |
255 |
|
} |
256 |
|
/* initialize offset array */ |
257 |
< |
if ((hres != hro | vres != vro)) { |
257 |
> |
if ((hres != hro) | (vres != vro)) { |
258 |
|
int toffs[NSCHECK][2]; |
259 |
|
i0 = fndx(SAMPDIST, SAMPDIST); |
260 |
|
nf = 0; |
273 |
|
} |
274 |
|
/* find up to nc neighbors */ |
275 |
|
i0 = fndx(x, y); |
276 |
< |
for (j = 0, nf = 0; (j < NSCHECK & nf < nc); j++) { |
276 |
> |
for (j = 0, nf = 0; (j < NSCHECK) & (nf < nc); j++) { |
277 |
|
i = i0 + ioffs[j]; |
278 |
< |
if (sbuffer[i] && (myobj == OVOID | obuffer[i] == myobj)) |
278 |
> |
if (sbuffer[i] && (myobj == OVOID) | (obuffer[i] == myobj)) |
279 |
|
iarr[nf++] = i; |
280 |
|
} |
281 |
|
/* return number found */ |
311 |
|
yp = (int)(ovp[1]*vres); |
312 |
|
xmbuffer[n] = xp - (n % hres); |
313 |
|
ymbuffer[n] = yp - (n / hres); |
314 |
< |
if ((xp < 0 | xp >= hres)) |
314 |
> |
if ((xp < 0) | (xp >= hres)) |
315 |
|
return; |
316 |
< |
if ((yp < 0 | yp >= vres)) |
316 |
> |
if ((yp < 0) | (yp >= vres)) |
317 |
|
return; |
318 |
|
n = fndx(xp, yp); |
319 |
< |
if ((zprev[n] < 0.97*ovp[2] | zprev[n] > 1.03*ovp[2])) |
319 |
> |
if ((zprev[n] < 0.97*ovp[2]) | (zprev[n] > 1.03*ovp[2])) |
320 |
|
oprev[n] = OVOID; /* assume it's a bad match */ |
321 |
|
} |
322 |
|
|
409 |
|
n = fndx(x, y); |
410 |
|
if ((obj = obuffer[n]) == OVOID) |
411 |
|
continue; |
412 |
< |
if ((obuffer[n+1] != OVOID & obuffer[n+1] != obj)) { |
412 |
> |
if ((obuffer[n+1] != OVOID) & (obuffer[n+1] != obj)) { |
413 |
|
obuffer[n] = OVOID; |
414 |
|
obuffer[n+1] = OVOID; |
415 |
|
} |
416 |
< |
if ((obuffer[n+hres] != OVOID & obuffer[n+hres] != obj)) { |
416 |
> |
if ((obuffer[n+hres] != OVOID) & (obuffer[n+hres] != obj)) { |
417 |
|
obuffer[n] = OVOID; |
418 |
|
obuffer[n+hres] = OVOID; |
419 |
|
} |
434 |
|
if (obj == OVOID) |
435 |
|
return(0); |
436 |
|
op = objptr(obj); |
437 |
< |
if ((op->otype == OBJ_INSTANCE & op->omod == OVOID)) |
437 |
> |
if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID)) |
438 |
|
return(0); |
439 |
|
/* search for material */ |
440 |
|
do { |
531 |
|
/* add together samples */ |
532 |
|
setcolor(csum, 0., 0., 0.); |
533 |
|
setcolor(csum2, 0., 0., 0.); |
534 |
< |
for (i = 0, ns = 0; (i < nc & ns < NSAMPOK); i++) { |
534 |
> |
for (i = 0, ns = 0; (i < nc) & (ns < NSAMPOK); i++) { |
535 |
|
n = neigh[i]; |
536 |
|
addcolor(csum, cbuffer[n]); |
537 |
|
if (val2map != NULL) { |
583 |
|
for (y = vres; y--; ) |
584 |
|
for (x = hres; x--; ) { |
585 |
|
n = fndx(x, y); |
586 |
< |
if ((abuffer[n] != ALOWQ | obuffer[n] == OVOID)) |
586 |
> |
if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID)) |
587 |
|
continue; |
588 |
|
if (!getambcolor(objamb, obuffer[n])) |
589 |
|
continue; |
642 |
|
restart = (!nobjects || vdef(MOVE)); |
643 |
|
if (!restart && curparams != &lorendparams && nprocs > 1) |
644 |
|
restart = -1; |
645 |
< |
if (restart > 0) |
645 |
> |
if (restart > 0) { |
646 |
|
if (nprocs > 1) |
647 |
|
ray_pdone(1); |
648 |
|
else |
649 |
|
ray_done(1); |
650 |
+ |
} |
651 |
|
/* post low quality parameters */ |
652 |
|
if (curparams != &lorendparams) |
653 |
|
ray_restore(curparams = &lorendparams); |
762 |
|
int n2; |
763 |
|
int cnt; |
764 |
|
/* sum in motion streaks */ |
765 |
< |
bzero(outbuffer, sizeof(COLOR)*hres*vres); |
766 |
< |
bzero(wbuffer, sizeof(float)*hres*vres); |
765 |
> |
memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); |
766 |
> |
memset(wbuffer, '\0', sizeof(float)*hres*vres); |
767 |
|
for (y = vres; y--; ) |
768 |
|
for (x = hres; x--; ) { |
769 |
|
n = fndx(x, y); |
792 |
|
scalecolor(cval, w); |
793 |
|
while (cnt) |
794 |
|
if (rise2 >= run2) { |
795 |
< |
if ((xl >= 0 & xl < hres & |
796 |
< |
yl >= 0 & yl < vres)) { |
795 |
> |
if ((xl >= 0) & (xl < hres) & |
796 |
> |
(yl >= 0) & (yl < vres)) { |
797 |
|
n2 = fndx(xl, yl); |
798 |
|
addcolor(outbuffer[n2], |
799 |
|
cval); |
813 |
|
scalecolor(cval, w); |
814 |
|
while (cnt) |
815 |
|
if (run2 >= rise2) { |
816 |
< |
if ((xl >= 0 & xl < hres & |
817 |
< |
yl >= 0 & yl < vres)) { |
816 |
> |
if ((xl >= 0) & (xl < hres) & |
817 |
> |
(yl >= 0) & (yl < vres)) { |
818 |
|
n2 = fndx(xl, yl); |
819 |
|
addcolor(outbuffer[n2], |
820 |
|
cval); |
847 |
|
setcolor(outbuffer[n], 0., 0., 0.); |
848 |
|
*/ |
849 |
|
/* adjust exposure */ |
850 |
< |
if ((expval < 0.99 | expval > 1.01)) |
850 |
> |
if ((expval < 0.99) | (expval > 1.01)) |
851 |
|
for (n = hres*vres; n--; ) |
852 |
|
scalecolor(outbuffer[n], expval); |
853 |
|
return; |
879 |
|
sprintf(errmsg, "cannot open output frame \"%s\"", pfname); |
880 |
|
error(SYSTEM, errmsg); |
881 |
|
} |
882 |
< |
#ifdef MSDOS |
932 |
< |
setmode(fileno(fp), O_BINARY); |
933 |
< |
#endif |
882 |
> |
SET_FILE_BINARY(fp); |
883 |
|
if (!silent) { |
884 |
|
printf("\tWriting to \"%s\"\n", pfname); |
885 |
|
fflush(stdout); |
892 |
|
fputnow(fp); |
893 |
|
fputs(VIEWSTR, fp); fprintview(&vw, fp); fputc('\n', fp); |
894 |
|
d = expspec_val(getexp(fcur)); |
895 |
< |
if ((d < 0.99 | d > 1.01)) |
895 |
> |
if ((d < 0.99) | (d > 1.01)) |
896 |
|
fputexpos(d, fp); |
897 |
|
d = viewaspect(&vw) * hres / vres; |
898 |
< |
if ((d < 0.99 | d > 1.01)) |
898 |
> |
if ((d < 0.99) | (d > 1.01)) |
899 |
|
fputaspect(d, fp); |
900 |
|
fputformat(COLRFMT, fp); |
901 |
|
fputc('\n', fp); /* end header */ |