--- ray/src/util/ranimove1.c 2003/02/22 02:07:30 3.1
+++ ray/src/util/ranimove1.c 2008/11/10 19:08:20 3.15
@@ -1,73 +1,22 @@
#ifndef lint
-static const char RCSid[] = "$Id: ranimove1.c,v 3.1 2003/02/22 02:07:30 greg Exp $";
+static const char RCSid[] = "$Id: ranimove1.c,v 3.15 2008/11/10 19:08:20 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.
*/
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * Copyright (c) 1990 - 2002 The Regents of the University of California,
- * through Lawrence Berkeley National Laboratory. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes Radiance software
- * (http://radsite.lbl.gov/)
- * developed by the Lawrence Berkeley National Laboratory
- * (http://www.lbl.gov/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
- * and "The Regents of the University of California" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact radiance@radsite.lbl.gov.
- *
- * 5. Products derived from this software may not be called "Radiance",
- * nor may "Radiance" appear in their name, without prior written
- * permission of Lawrence Berkeley National Laboratory.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of Lawrence Berkeley National Laboratory. For more
- * information on Lawrence Berkeley National Laboratory, please see
- * .
- */
+#include "copyright.h"
+#include
+
+#include "platform.h"
#include "ranimove.h"
#include "otypes.h"
+#include "source.h"
#include "random.h"
double acctab[256]; /* accuracy value table */
@@ -98,10 +47,19 @@ 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);
+
+
+#if 0
+extern void
+write_map( /* write out float map (debugging) */
+ float *mp,
+ char *fn
+)
{
FILE *fp = fopen(fn, "w");
COLOR scanbuf[2048];
@@ -122,18 +80,19 @@ char *fn;
}
fclose(fp);
}
+#endif
static void
-next_frame() /* prepare next frame buffer */
+next_frame(void) /* prepare next frame buffer */
{
VIEW *fv;
char *err;
/* get previous view */
if (vw.type != 0)
- copystruct(&vwprev, &vw);
+ vwprev = vw;
else if (fcur > 1 && (fv = getview(fcur-1)) != NULL) {
- copystruct(&vwprev, fv);
+ vwprev = *fv;
if (setview(&vwprev) != NULL)
vwprev.type = 0;
}
@@ -142,7 +101,7 @@ next_frame() /* prepare next frame buffer */
sprintf(errmsg, "cannot get view for frame %d", fcur);
error(USER, errmsg);
}
- copystruct(&vw, fv);
+ vw = *fv;
if ((err = setview(&vw)) != NULL) {
sprintf(errmsg, "view error at frame %d: %s", fcur, err);
error(USER, errmsg);
@@ -158,7 +117,7 @@ next_frame() /* prepare next frame buffer */
pixaspect = 1.;
/* fall through */
case 3:
- if ((hres > 0 & vres > 0))
+ if ((hres > 0) & (vres > 0))
break;
/* fall through */
default:
@@ -177,11 +136,11 @@ next_frame() /* prepare next frame buffer */
zprev = (float *)malloc(sizeof(float)*hres*vres);
oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres);
aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres);
- if ((cbuffer==NULL | zbuffer==NULL | obuffer==NULL |
- xmbuffer==NULL | ymbuffer==NULL |
- abuffer==NULL | sbuffer==NULL |
- cprev==NULL | zprev == NULL |
- oprev==NULL | aprev==NULL))
+ if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) |
+ (xmbuffer==NULL) | (ymbuffer==NULL) |
+ (abuffer==NULL) | (sbuffer==NULL) |
+ (cprev==NULL) | (zprev == NULL) |
+ (oprev==NULL) | (aprev==NULL))
error(SYSTEM, "out of memory in init_frame");
frm_stop = getTime() + rtperfrm;
} else {
@@ -193,8 +152,8 @@ next_frame() /* prepare next frame buffer */
fp = zprev; zprev = zbuffer; zbuffer = fp;
op = oprev; oprev = obuffer; obuffer = op;
bp = aprev; aprev = abuffer; abuffer = bp;
- bzero(abuffer, sizeof(BYTE)*hres*vres);
- bzero(sbuffer, sizeof(BYTE)*hres*vres);
+ memset(abuffer, '\0', sizeof(BYTE)*hres*vres);
+ memset(sbuffer, '\0', sizeof(BYTE)*hres*vres);
frm_stop += rtperfrm;
}
cerrmap = NULL;
@@ -207,8 +166,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);
@@ -218,11 +179,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];
@@ -233,12 +196,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 */
@@ -246,7 +213,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]);
@@ -254,18 +221,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;
@@ -276,8 +247,8 @@ int x, y;
/* get our object number */
myobj = obuffer[fndx(x, y)];
/* special case for borders */
- if ((x < SAMPDIST | x >= hres-SAMPDIST |
- y < SAMPDIST | y >= vres-SAMPDIST)) {
+ if ((x < SAMPDIST) | (x >= hres-SAMPDIST) |
+ (y < SAMPDIST) | (y >= vres-SAMPDIST)) {
int tndx[NSCHECK][2];
nf = 0;
for (j = y - SAMPDIST; j <= y + SAMPDIST; j++) {
@@ -289,7 +260,7 @@ int x, y;
i0 = fndx(i, j);
if (!sbuffer[i0])
continue;
- if ((myobj != OVOID & obuffer[i0] != myobj))
+ if ((myobj != OVOID) & (obuffer[i0] != myobj))
continue;
tndx[nf][0] = (i-x)*(i-x) + (j-y)*(j-y);
tndx[nf][1] = i0;
@@ -304,7 +275,7 @@ int x, y;
return(nf);
}
/* initialize offset array */
- if ((hres != hro | vres != vro)) {
+ if ((hres != hro) | (vres != vro)) {
int toffs[NSCHECK][2];
i0 = fndx(SAMPDIST, SAMPDIST);
nf = 0;
@@ -323,9 +294,9 @@ int x, y;
}
/* find up to nc neighbors */
i0 = fndx(x, y);
- for (j = 0, nf = 0; (j < NSCHECK & nf < nc); j++) {
+ for (j = 0, nf = 0; (j < NSCHECK) & (nf < nc); j++) {
i = i0 + ioffs[j];
- if (sbuffer[i] && (myobj == OVOID | obuffer[i] == myobj))
+ if (sbuffer[i] && (myobj == OVOID) | (obuffer[i] == myobj))
iarr[nf++] = i;
}
/* return number found */
@@ -335,13 +306,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 */
@@ -361,18 +331,18 @@ FVECT wpos;
yp = (int)(ovp[1]*vres);
xmbuffer[n] = xp - (n % hres);
ymbuffer[n] = yp - (n / hres);
- if ((xp < 0 | xp >= hres))
+ if ((xp < 0) | (xp >= hres))
return;
- if ((yp < 0 | yp >= vres))
+ if ((yp < 0) | (yp >= vres))
return;
n = fndx(xp, yp);
- if ((zprev[n] < 0.97*ovp[2] | zprev[n] > 1.03*ovp[2]))
+ if ((zprev[n] < 0.97*ovp[2]) | (zprev[n] > 1.03*ovp[2]))
oprev[n] = OVOID; /* assume it's a bad match */
}
static void
-init_frame_sample() /* sample our initial frame */
+init_frame_sample(void) /* sample our initial frame */
{
RAY ir;
int x, y;
@@ -399,7 +369,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);
@@ -417,7 +387,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)
@@ -459,11 +429,11 @@ init_frame_sample() /* sample our initial frame */
n = fndx(x, y);
if ((obj = obuffer[n]) == OVOID)
continue;
- if ((obuffer[n+1] != OVOID & obuffer[n+1] != obj)) {
+ if ((obuffer[n+1] != OVOID) & (obuffer[n+1] != obj)) {
obuffer[n] = OVOID;
obuffer[n+1] = OVOID;
}
- if ((obuffer[n+hres] != OVOID & obuffer[n+hres] != obj)) {
+ if ((obuffer[n+hres] != OVOID) & (obuffer[n+hres] != obj)) {
obuffer[n] = OVOID;
obuffer[n+hres] = OVOID;
}
@@ -474,17 +444,18 @@ 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;
if (obj == OVOID)
return(0);
op = objptr(obj);
- if ((op->otype == OBJ_INSTANCE & op->omod == OVOID))
+ if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID))
return(0);
/* search for material */
do {
@@ -544,10 +515,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;
@@ -567,11 +541,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;
@@ -581,7 +556,7 @@ int ns0;
/* add together samples */
setcolor(csum, 0., 0., 0.);
setcolor(csum2, 0., 0., 0.);
- for (i = 0, ns = 0; (i < nc & ns < NSAMPOK); i++) {
+ for (i = 0, ns = 0; (i < nc) & (ns < NSAMPOK); i++) {
n = neigh[i];
addcolor(csum, cbuffer[n]);
if (val2map != NULL) {
@@ -602,15 +577,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) {
@@ -633,7 +608,7 @@ comp_frame_error() /* initialize frame error values *
for (y = vres; y--; )
for (x = hres; x--; ) {
n = fndx(x, y);
- if ((abuffer[n] != ALOWQ | obuffer[n] == OVOID))
+ if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
continue;
if (!getambcolor(objamb, obuffer[n]))
continue;
@@ -681,22 +656,16 @@ 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 */
restart = (!nobjects || vdef(MOVE));
if (!restart && curparams != &lorendparams && nprocs > 1)
restart = -1;
- if (restart > 0)
- if (nprocs > 1)
- ray_pdone(1);
- else
- ray_done(1);
/* post low quality parameters */
if (curparams != &lorendparams)
ray_restore(curparams = &lorendparams);
@@ -728,7 +697,7 @@ init_frame() /* render base (low quality) frame */
init_frame_sample();
/* initialize frame error */
comp_frame_error();
-return;
+#if 0
{
float *ebuf = (float *)malloc(sizeof(float)*hres*vres);
char fnm[256];
@@ -740,11 +709,12 @@ return;
write_map(ebuf, fnm);
free((void *)ebuf);
}
+#endif
}
-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;
@@ -755,16 +725,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) {
@@ -788,6 +758,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]]);
@@ -797,22 +777,19 @@ 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;
int n2;
int cnt;
/* sum in motion streaks */
- bzero(outbuffer, sizeof(COLOR)*hres*vres);
- bzero(wbuffer, sizeof(float)*hres*vres);
+ memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
+ memset(wbuffer, '\0', sizeof(float)*hres*vres);
for (y = vres; y--; )
for (x = hres; x--; ) {
n = fndx(x, y);
@@ -841,8 +818,8 @@ write_map(cerrmap, "outcmap.pic");
scalecolor(cval, w);
while (cnt)
if (rise2 >= run2) {
- if ((xl >= 0 & xl < hres &
- yl >= 0 & yl < vres)) {
+ if ((xl >= 0) & (xl < hres) &
+ (yl >= 0) & (yl < vres)) {
n2 = fndx(xl, yl);
addcolor(outbuffer[n2],
cval);
@@ -862,8 +839,8 @@ write_map(cerrmap, "outcmap.pic");
scalecolor(cval, w);
while (cnt)
if (run2 >= rise2) {
- if ((xl >= 0 & xl < hres &
- yl >= 0 & yl < vres)) {
+ if ((xl >= 0) & (xl < hres) &
+ (yl >= 0) & (yl < vres)) {
n2 = fndx(xl, yl);
addcolor(outbuffer[n2],
cval);
@@ -890,31 +867,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 */
- if ((expval < 0.99 | expval > 1.01))
+ /*
+ 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;
@@ -922,15 +900,13 @@ send_frame() /* send frame to destination */
int y;
/* open output picture */
sprintf(pfname, vval(BASENAME), fcur);
- strcat(pfname, ".pic");
+ strcat(pfname, ".hdr");
fp = fopen(pfname, "w");
if (fp == NULL) {
sprintf(errmsg, "cannot open output frame \"%s\"", pfname);
error(SYSTEM, errmsg);
}
-#ifdef MSDOS
- setmode(fileno(fp), O_BINARY);
-#endif
+ SET_FILE_BINARY(fp);
if (!silent) {
printf("\tWriting to \"%s\"\n", pfname);
fflush(stdout);
@@ -943,10 +919,10 @@ send_frame() /* send frame to destination */
fputnow(fp);
fputs(VIEWSTR, fp); fprintview(&vw, fp); fputc('\n', fp);
d = expspec_val(getexp(fcur));
- if ((d < 0.99 | d > 1.01))
+ if ((d < 0.99) | (d > 1.01))
fputexpos(d, fp);
d = viewaspect(&vw) * hres / vres;
- if ((d < 0.99 | d > 1.01))
+ if ((d < 0.99) | (d > 1.01))
fputaspect(d, fp);
fputformat(COLRFMT, fp);
fputc('\n', fp); /* end header */
@@ -968,8 +944,8 @@ writerr:
}
-void
-free_frame() /* free frame allocation */
+extern void
+free_frame(void) /* free frame allocation */
{
if (cbuffer == NULL)
return;