--- ray/src/util/ranimove1.c 2003/07/27 22:12:03 3.6 +++ ray/src/util/ranimove1.c 2008/04/17 14:44:25 3.13 @@ -1,10 +1,10 @@ #ifndef lint -static const char RCSid[] = "$Id: ranimove1.c,v 3.6 2003/07/27 22:12:03 schorsch Exp $"; +static const char RCSid[] = "$Id: ranimove1.c,v 3.13 2008/04/17 14:44:25 greg Exp $"; #endif /* * ranimove1.c * - * Basic frame rendering routines for ranimate(1). + * Basic frame rendering routines for ranimove(1). * * Created by Gregory Ward on Wed Jan 08 2003. */ @@ -16,6 +16,7 @@ static const char RCSid[] = "$Id: ranimove1.c,v 3.6 20 #include "platform.h" #include "ranimove.h" #include "otypes.h" +#include "source.h" #include "random.h" double acctab[256]; /* accuracy value table */ @@ -46,10 +47,18 @@ double frm_stop; /* when to stop rendering this frame double hlsmax; /* maximum high-level saliency this frame */ -void -write_map(mp, fn) /* write out float map (debugging) */ -float *mp; -char *fn; +static void next_frame(void); +static int sample_here(int x, int y); +static int offset_cmp(const void *p1, const void *p2); +static void setmotion(int n, FVECT wpos); +static void init_frame_sample(void); + + +extern void +write_map( /* write out float map (debugging) */ + float *mp, + char *fn +) { FILE *fp = fopen(fn, "w"); COLOR scanbuf[2048]; @@ -73,7 +82,7 @@ char *fn; static void -next_frame() /* prepare next frame buffer */ +next_frame(void) /* prepare next frame buffer */ { VIEW *fv; char *err; @@ -155,8 +164,10 @@ next_frame() /* prepare next frame buffer */ static int -sample_here(x, y) /* 4x4 quincunx sample at this pixel? */ -register int x, y; +sample_here( /* 4x4 quincunx sample at this pixel? */ + register int x, + register int y +) { if (y & 0x1) /* every other row has samples */ return(0); @@ -166,11 +177,13 @@ register int x, y; } -void -sample_pos(hv, x, y, sn) /* compute jittered sample position */ -double hv[2]; -int x, y; -int sn; +extern void +sample_pos( /* compute jittered sample position */ + double hv[2], + int x, + int y, + int sn +) { int hl[2]; @@ -181,12 +194,16 @@ int sn; } -double -sample_wt(xo, yo) /* compute interpolant sample weight */ -int xo, yo; +extern double +sample_wt( /* compute interpolant sample weight */ + int xo, + int yo +) { static double etab[400]; - int rad2 = xo*xo + yo*yo; + /* we can't use the name rad2 here, for some reason Visual C + thinks that is a constant (compiler bug?) */ + int rad_2 = xo*xo + yo*yo; int i; if (etab[0] <= FTINY) /* initialize exponent table */ @@ -194,7 +211,7 @@ int xo, yo; etab[i] = exp(-0.1*i); /* look up Gaussian */ - i = (int)((10.*3./(double)SAMPDIST2)*rad2 + .5); + i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5); if (i >= 400) return(0.0); return(etab[i]); @@ -202,18 +219,22 @@ int xo, yo; static int -offset_cmp(p1, p2) /* compare offset distances */ -const void *p1, *p2; +offset_cmp( /* compare offset distances */ + const void *p1, + const void *p2 +) { return(*(const int *)p1 - *(const int *)p2); } -int -getclosest(iarr, nc, x, y) /* get nc closest neighbors on same object */ -int *iarr; -int nc; -int x, y; +extern int +getclosest( /* get nc closest neighbors on same object */ + int *iarr, + int nc, + int x, + int y +) { #define NSCHECK ((2*SAMPDIST+1)*(2*SAMPDIST+1)) static int hro, vro; @@ -283,13 +304,12 @@ int x, y; static void -setmotion(n, wpos) /* compute motion vector for this pixel */ -register int n; -FVECT wpos; +setmotion( /* compute motion vector for this pixel */ + register int n, + FVECT wpos +) { FVECT ovp; - MAT4 xfm; - double d; int moi; int xp, yp; /* ID object and update maximum HLS */ @@ -320,7 +340,7 @@ FVECT wpos; static void -init_frame_sample() /* sample our initial frame */ +init_frame_sample(void) /* sample our initial frame */ { RAY ir; int x, y; @@ -347,7 +367,7 @@ init_frame_sample() /* sample our initial frame */ continue; } if (!sample_here(x, y)) { /* just cast */ - rayorigin(&ir, NULL, PRIMARY, 1.0); + rayorigin(&ir, PRIMARY, NULL, NULL); if (!localhit(&ir, &thescene)) { if (ir.ro != &Aftplane) sourcehit(&ir); @@ -365,7 +385,7 @@ init_frame_sample() /* sample our initial frame */ } if (nprocs > 1) { /* get sample */ int rval; - rayorigin(&ir, NULL, PRIMARY, 1.0); + rayorigin(&ir, PRIMARY, NULL, NULL); ir.rno = n; rval = ray_pqueue(&ir); if (!rval) @@ -422,10 +442,11 @@ init_frame_sample() /* sample our initial frame */ } -int -getambcolor(clr, obj) /* get ambient color for object if we can */ -COLOR clr; -int obj; +extern int +getambcolor( /* get ambient color for object if we can */ + COLOR clr, + int obj +) { register OBJREC *op; @@ -492,10 +513,13 @@ int obj; } -double -estimaterr(cs, cs2, ns, ns0) /* estimate relative error from samples */ -COLOR cs, cs2; -int ns; +extern double +estimaterr( /* estimate relative error from samples */ + COLOR cs, + COLOR cs2, + int ns, + int ns0 +) { double d, d2, brt; @@ -515,11 +539,12 @@ int ns; } -double -comperr(neigh, nc, ns0) /* estimate relative error in neighborhood */ -int *neigh; -int nc; -int ns0; +extern double +comperr( /* estimate relative error in neighborhood */ + int *neigh, + int nc, + int ns0 +) { COLOR csum, csum2; COLOR ctmp; @@ -550,15 +575,15 @@ int ns0; } -void -comp_frame_error() /* initialize frame error values */ +extern void +comp_frame_error(void) /* initialize frame error values */ { BYTE *edone = NULL; COLOR objamb; double eest; int neigh[NSAMPOK]; int nc; - int x, y, i, j; + int x, y, i; register int n; if (!silent) { @@ -629,11 +654,10 @@ comp_frame_error() /* initialize frame error values * } -void -init_frame() /* render base (low quality) frame */ +extern void +init_frame(void) /* render base (low quality) frame */ { int restart; - /* allocate/swap buffers */ next_frame(); /* check rendering status */ @@ -642,9 +666,9 @@ init_frame() /* render base (low quality) frame */ restart = -1; if (restart > 0) { if (nprocs > 1) - ray_pdone(1); + ray_pdone(0); else - ray_done(1); + ray_done(0); } /* post low quality parameters */ if (curparams != &lorendparams) @@ -692,8 +716,8 @@ return; } -void -filter_frame() /* interpolation, motion-blur, and exposure */ +extern void +filter_frame(void) /* interpolation, motion-blur, and exposure */ { double expval = expspec_val(getexp(fcur)); int x, y; @@ -704,16 +728,16 @@ filter_frame() /* interpolation, motion-blur, and ex register int n; #if 0 -/* XXX TEMPORARY!! */ -conspicuity(); -write_map(cerrmap, "outcmap.pic"); -{ - float *ebuf = (float *)malloc(sizeof(float)*hres*vres); - for (n = hres*vres; n--; ) - ebuf[n] = acctab[abuffer[n]]; - write_map(ebuf, "outerr.pic"); - free((void *)ebuf); -} + /* XXX TEMPORARY!! */ + conspicuity(); + write_map(cerrmap, "outcmap.pic"); + { + float *ebuf = (float *)malloc(sizeof(float)*hres*vres); + for (n = hres*vres; n--; ) + ebuf[n] = acctab[abuffer[n]]; + write_map(ebuf, "outerr.pic"); + free((void *)ebuf); + } #endif if (!silent) { @@ -737,6 +761,16 @@ write_map(cerrmap, "outcmap.pic"); continue; nc = getclosest(neigh, NPINTERP, x, y); setcolor(cbuffer[n], 0., 0., 0.); + if (nc <= 0) { /* no acceptable neighbors */ + if (y < vres-1) + nc = fndx(x, y+1); + else if (x < hres-1) + nc = fndx(x+1, y); + else + continue; + copycolor(cbuffer[n], cbuffer[nc]); + continue; + } wsum = 0.; while (nc-- > 0) { copycolor(cval, cbuffer[neigh[nc]]); @@ -746,14 +780,11 @@ write_map(cerrmap, "outcmap.pic"); addcolor(cbuffer[n], cval); wsum += w; } - if (wsum > FTINY) { - w = 1.0/wsum; - scalecolor(cbuffer[n], w); - } + w = 1.0/wsum; + scalecolor(cbuffer[n], w); } /* motion blur if requested */ if (mblur > .02) { - int len; int xs, ys, xl, yl; int rise, run; long rise2, run2; @@ -791,7 +822,7 @@ write_map(cerrmap, "outcmap.pic"); while (cnt) if (rise2 >= run2) { if ((xl >= 0) & (xl < hres) & - (yl >= 0) & (yl < vres)) { + (yl >= 0) & (yl < vres)) { n2 = fndx(xl, yl); addcolor(outbuffer[n2], cval); @@ -812,7 +843,7 @@ write_map(cerrmap, "outcmap.pic"); while (cnt) if (run2 >= rise2) { if ((xl >= 0) & (xl < hres) & - (yl >= 0) & (yl < vres)) { + (yl >= 0) & (yl < vres)) { n2 = fndx(xl, yl); addcolor(outbuffer[n2], cval); @@ -839,31 +870,32 @@ write_map(cerrmap, "outcmap.pic"); } else for (n = hres*vres; n--; ) copycolor(outbuffer[n], cbuffer[n]); -/* -for (n = hres*vres; n--; ) - if (!sbuffer[n]) - setcolor(outbuffer[n], 0., 0., 0.); -*/ - /* adjust exposure */ + /* + for (n = hres*vres; n--; ) + if (!sbuffer[n]) + setcolor(outbuffer[n], 0., 0., 0.); + */ + /* adjust exposure */ if ((expval < 0.99) | (expval > 1.01)) for (n = hres*vres; n--; ) scalecolor(outbuffer[n], expval); -return; -{ - float *sbuf = (float *)malloc(sizeof(float)*hres*vres); - char fnm[256]; - sprintf(fnm, vval(BASENAME), fcur); - strcat(fnm, "_outsamp.pic"); - for (n = hres*vres; n--; ) - sbuf[n] = (float)sbuffer[n]; - write_map(sbuf, fnm); - free((void *)sbuf); +#if 0 + { + float *sbuf = (float *)malloc(sizeof(float)*hres*vres); + char fnm[256]; + sprintf(fnm, vval(BASENAME), fcur); + strcat(fnm, "_outsamp.pic"); + for (n = hres*vres; n--; ) + sbuf[n] = (float)sbuffer[n]; + write_map(sbuf, fnm); + free((void *)sbuf); + } +#endif } -} -void -send_frame() /* send frame to destination */ +extern void +send_frame(void) /* send frame to destination */ { char pfname[1024]; double d; @@ -915,8 +947,8 @@ writerr: } -void -free_frame() /* free frame allocation */ +extern void +free_frame(void) /* free frame allocation */ { if (cbuffer == NULL) return;