Hi Hannes, I am really confused now. I tried to isolate the problem,
so I created a small C test program (it is attached to this mail). It
simulates the interpolation between frames 0 and 71 for only 2 frames
(#2 which works fine and #3 which shows the rounding error). The main
problem seems to come from this:

double next_scale_prev_scale = next_scale * prev_scale;

...but then, interestingly (next_scale_prev_scale != next_scale *
prev_scale). Can someone explain that? Maybe I am missing something
obvious here.

For interpolating the vertical variable, look at these 2 lines in the output:

FRAME #2:
intp_vert=1.00000000000000000000000000000000000000000000000000e+00
(int)intp_vert=1

FRAME #3:
intp_vert=1.00000000000000000000000000000000000000000000000000e+00
(int)intp_vert=0

...the same thing happens for the horizontal variable, so frame 3 will
have no blurring effect applied.

Here is the full output of the compiled test:

blur: frame=2 p.vert=1 n.vert=1 p.hori=1 n.hori=1 psc=0.971831 nsc=0.028169
prev_frame=0 next_frame=71
intp_vert=1.00000000000000000000000000000000000000000000000000e+00
(int)intp_vert=1
(prev.vertical * prev_scale + next.vertical * next_scale) > 0
(prev.vertical * prev_scale + next.vertical * next_scale) > 1
intp_vert_double > 0
intp_vert_double == 1
next_scale_prev_scale   =
2.7375520730013886555598290328816801775246858596801757812500000000000000000000000000000000000000000000e-02
next_scale * prev_scale =
2.7375520730013886555598290328816801775246858596801757812500000000000000000000000000000000000000000000e-02
next_scale_prev_scale < next_scale * prev_scale
typeid(next_scale_prev_scale) = d
typeid(next_scale * prev_scale) = d


blur: frame=3 p.vert=1 n.vert=1 p.hori=1 n.hori=1 psc=0.957746 nsc=0.0422535
prev_frame=0 next_frame=71
intp_vert=1.00000000000000000000000000000000000000000000000000e+00
(int)intp_vert=0
(prev.vertical * prev_scale + next.vertical * next_scale) > 0
(prev.vertical * prev_scale + next.vertical * next_scale) < 1
intp_vert_double > 0
intp_vert_double == 1
next_scale_prev_scale   =
4.0468161079150959114070218447523075155913829803466796875000000000000000000000000000000000000000000000e-02
next_scale * prev_scale =
4.0468161079150959114070218447523075155913829803466796875000000000000000000000000000000000000000000000e-02
next_scale_prev_scale > next_scale * prev_scale
typeid(next_scale_prev_scale) = d
typeid(next_scale * prev_scale) = d

I hope someone can explain that magic to me :o)
Michal

On 20 November 2011 10:47, Johannes Sixt <[email protected]> wrote:
> Am 19.11.2011 23:46, schrieb Michal Fapso:
>> I had one keyframe at 0 sec (0 blur radius) and another one at 3
>> seconds (30 blur radius) at 24fps. I added few printf commands to the
>> blur.C to see what is going on there. The radius variable was
>> interpolated correctly and increased steadily towards 30, but the
>> horizontal and vertical were in about half of the frames 0 and in
>> another frames 1 (quite randomly). When both were 0, blurring was
>> actually turned off for those frames.
>
> Interesting. Could you repeat the printf test and dump all variables
> used in the expression, like so:
>
> printf("blur: p.vert=%d n.vert=%d psc=%g nsc=%g intp=%g\n",
>       prev.vertical,next.vertical,prev_scale,next_scale,
>       prev.vertical * prev_scale + next.vertical * next_scale);
>
> -- Hannes
>
#include <stdio.h>
#include <math.h>
#include <typeinfo>
using namespace std;

struct BlurConfig {
	int vertical;
	int horizontal;
};

#define PRINT_IF(expr) if (expr) { printf("%s\n", #expr); }

int main() {
	BlurConfig prev;
	BlurConfig next;
	prev.vertical = prev.horizontal = next.vertical = next.horizontal = 1;

	int prev_frame = 0;
	int next_frame = 71;
	for (int current_frame=2; current_frame<=3; current_frame++) {
		double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
		double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);

		double intp_vert_double = prev.vertical * prev_scale + next.vertical * next_scale;
		double intp_hori_double = prev.horizontal * prev_scale + next.horizontal * next_scale;
		double next_scale_prev_scale = next_scale * prev_scale;

		printf("\n\nblur: frame=%d p.vert=%d n.vert=%d p.hori=%d n.hori=%d psc=%g nsc=%g\n", 
					  (int)current_frame,
					  prev.vertical,next.vertical,
					  prev.horizontal,next.horizontal,
					  prev_scale,next_scale);
		printf("prev_frame=%d next_frame=%d\n", 	
					  (int)prev_frame, (int)next_frame);
		printf("intp_vert=%.50e\n", 	
					  (prev.vertical * prev_scale + next.vertical * next_scale));
		printf("(int)intp_vert=%d\n", (int)(prev.vertical * prev_scale + next.vertical * next_scale));

		PRINT_IF ((prev.vertical * prev_scale + next.vertical * next_scale) == 0);
		PRINT_IF ((prev.vertical * prev_scale + next.vertical * next_scale) > 0);
		PRINT_IF ((prev.vertical * prev_scale + next.vertical * next_scale) < 1);
		PRINT_IF ((prev.vertical * prev_scale + next.vertical * next_scale) == 1);
		PRINT_IF ((prev.vertical * prev_scale + next.vertical * next_scale) > 1);

		PRINT_IF (intp_vert_double == 0);
		PRINT_IF (intp_vert_double > 0);
		PRINT_IF (intp_vert_double < 1);
		PRINT_IF (intp_vert_double == 1);
		PRINT_IF (intp_vert_double > 1);

		printf ("next_scale_prev_scale   = %.100e\n", next_scale_prev_scale);
		printf ("next_scale * prev_scale = %.100e\n", next_scale * prev_scale);
		PRINT_IF (next_scale_prev_scale == next_scale * prev_scale);
		PRINT_IF (next_scale_prev_scale >  next_scale * prev_scale);
		PRINT_IF (next_scale_prev_scale <  next_scale * prev_scale);

		printf("typeid(next_scale_prev_scale) = %s\n", typeid(next_scale_prev_scale).name());
		printf("typeid(next_scale * prev_scale) = %s\n", typeid(next_scale * prev_scale).name());
	}
	return 0;
}

Reply via email to