--- ray/src/px/pmblur2.c 2012/10/05 02:07:10 2.2 +++ ray/src/px/pmblur2.c 2012/10/13 05:18:18 2.5 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pmblur2.c,v 2.2 2012/10/05 02:07:10 greg Exp $"; +static const char RCSid[] = "$Id: pmblur2.c,v 2.5 2012/10/13 05:18:18 greg Exp $"; #endif /* * pmblur2.c - program to computer better motion blur from ranimove frames. @@ -111,6 +111,10 @@ loadprev(int fno) exprev = ih.ev; if (!fgetsresolu(&rs, fp)) goto readerr; + if (rs.rt != PIXSTANDARD) { + sprintf(errmsg, "unsupported orientation in picture \"%s\"", fname); + error(USER, errmsg); + } if (!imres.xr) { /* allocate buffers */ imres = rs; imsum = (COLOR *)ecalloc(imres.xr*imres.yr, sizeof(COLOR)); @@ -146,15 +150,15 @@ readerr: /* Interpolate between two image pixels */ /* XXX skipping expensive ray vector calculations for now */ static void -interp_pixel(COLOR con, const VIEW *vwn, int xn, int yn, double zn, - double pos, int xp, int yp) +interp_pixel(COLOR con, const VIEW *vwn, int xn, int yn, double zval, + double pos, int xp, int yp, int interpOK) { const int hres = scanlen(&imres); RREAL ipos; FVECT wprev, wcoor, rdir; int np, xd, yd, nd; COLOR cpr; - double sf, zval; + double sf; /* check if off image */ if ((xp < 0) | (xp >= hres)) return; @@ -164,17 +168,20 @@ interp_pixel(COLOR con, const VIEW *vwn, int xn, int y xd = (1.-pos)*xp + pos*xn + .5; yd = (1.-pos)*yp + pos*yn + .5; nd = yd*hres + xd; - /* check interpolated depth */ - zval = (1.-pos)*zprev[np] + pos*zn; + /* check depth */ + if (interpOK) + zval = (1.-pos)*zprev[np] + pos*zval; if (zval >= zbuf[nd]) return; - copycolor(imbuf[nd], con); /* assign interpolated color */ + zbuf[nd] = zval; /* assign new depth */ + copycolor(imbuf[nd], con); /* assign new color */ + if (!interpOK) + return; scalecolor(imbuf[nd], pos); sf = (1.-pos)/exprev; colr_color(cpr, imprev[np]); scalecolor(cpr, sf); addcolor(imbuf[nd], cpr); - zbuf[nd] = zval; /* assign new depth */ } @@ -200,15 +207,14 @@ neigh_zmin(const float *zb, int n) } -/* Fill in missing pixels from immediate neighbors */ +/* Expand foreground pixels to mitigate aliasing/fill errors */ static void fill_missing(void) { int n, m; for (n = imres.xr*imres.yr; n--; ) - if (zbuf[n] >= .9*FHUGE && - zbuf[m = neigh_zmin(zbuf,n)] < .9*FHUGE) + if (zbuf[n] > 1.25*zbuf[m = neigh_zmin(zbuf,n)]) copycolor(imbuf[n], imbuf[m]); } @@ -258,6 +264,10 @@ addframe(double fpos) error(USER, err); if (!fgetsresolu(&rs, fpimg)) goto readerr; + if (rs.rt != PIXSTANDARD) { + sprintf(errmsg, "unsupported orientation in picture \"%s\"", fname); + error(USER, errmsg); + } if ((rs.xr != imres.xr) | (rs.yr != imres.yr)) { sprintf(errmsg, "resolution mismatch for picture \"%s\"", fname); error(USER, errmsg); @@ -311,7 +321,8 @@ addframe(double fpos) scalecolor(cval, sf); interp_pixel(cval, &fvw, h, n, zscan[h], fpos, h + (int)mscan[3*h] - 32768, - n - (int)mscan[3*h+1] + 32768); + n - (int)mscan[3*h+1] + 32768, + mscan[3*h+2]); } } /* fill in missing pixels */ @@ -387,8 +398,8 @@ main(int argc, char *argv[]) /* get frame range & sampling */ switch (sscanf(argv[1], "%lf,%lf/%d", &fstart, &fend, &nsamps)) { case 1: - nsamps = 0; fend = fstart; + nsamps = 0; break; case 2: nsamps = 0; @@ -396,6 +407,8 @@ main(int argc, char *argv[]) case 3: if (fend < fstart) goto userr; + if (fend <= fstart+FTINY) + nsamps = 0; break; default: goto userr; @@ -426,6 +439,6 @@ main(int argc, char *argv[]) write_average(stdout); return(fflush(stdout) == EOF); userr: - fprintf(stderr, "Usage: %s f0,f1 HDRspec ZBUFspec MVOspec\n", progname); + fprintf(stderr, "Usage: %s f0,f1[/n] HDRspec ZBUFspec MVOspec\n", progname); return(1); }