[XviD-devel] gme code

Antonin Misek tonda.misek at post.cz
Thu Dec 4 12:20:49 CET 2003


Hi all, specially Gruel,
I perhaps found bug in estimation_gmc.c in GlobalMotionEstRefine. I followed
Gruel's description in source code:

> Start with some parameters. Calculate GlobalSAD. Change all parameter by
> +1 or -1. Everytime calculate GlobalSAD. Choose the best of all 7
> possibilites (no change, +-1 in 3 components). Update current best.
> Repeat, until the position doesn't change anymore.

So I think that there is redundant/buggy code:
		currwp = centerwp; currwp.duv[1].x++;
		gmcSAD = globalSAD(&currwp, pParam, pMBs, current, pRef, pCurr, GMCblock);
		if (gmcSAD < gmcminSAD)
		{	bestwp = currwp;
			gmcminSAD = gmcSAD;
			direction = 32;
		}
		currwp.duv[2].y++;
		gmcSAD = globalSAD(&currwp, pParam, pMBs, current, pRef, pCurr, GMCblock);
		if (gmcSAD < gmcminSAD)
		{	bestwp = currwp;
			gmcminSAD = gmcSAD;
			direction = 1024;
		}

My suggestion is little reformat the code. Use sequence:
{	bestwp = currwp;
	gmcminSAD = gmcSAD;
	direction = 32;
	continue;
}
So all "if (direction) continue;" can be eliminated.

Moreover some copying of WARPPOINTS structure can be eliminated by another
little code change (see end of mail).

TonyMi

P.S. Here is my modification (Attention, the code is not tested at all, use
it only as suggestion):

#define TEST_ONE_CHANGE(dir)\
	gmcSAD = globalSAD(&currwp, pParam, pMBs, current, pRef, pCurr, GMCblock);\
	if (gmcSAD < gmcminSAD)\
	{	bestwp = currwp;\
		gmcminSAD = gmcSAD;\
		direction = dir;\
		continue;\
	}

	do {
		direction = 0;
		currwp = bestwp;

		currwp.duv[0].x--;
		TEST_ONE_CHANGE(1);
		currwp.duv[0].x+=2;
		TEST_ONE_CHANGE(2);
		currwp.duv[0].x--;

		currwp.duv[0].y--;
		TEST_ONE_CHANGE(4);
		currwp.duv[0].y+=2;
		TEST_ONE_CHANGE(8);
		currwp.duv[0].y--;


		currwp.duv[1].x--;
		TEST_ONE_CHANGE(16);
		currwp.duv[1].x+=2;
		TEST_ONE_CHANGE(32);
		currwp.duv[1].x--;

		currwp.duv[1].y--;
		TEST_ONE_CHANGE(64);
		currwp.duv[1].y+=2;
		TEST_ONE_CHANGE(128);
		currwp.duv[1].y--;


		currwp.duv[2].x--;
		TEST_ONE_CHANGE(256);
		currwp.duv[2].x+=2;
		TEST_ONE_CHANGE(521);
		currwp.duv[2].x--;

		currwp.duv[2].y--;
		TEST_ONE_CHANGE(1024);
		currwp.duv[2].y+=2;
		TEST_ONE_CHANGE(2048);
		currwp.duv[2].y--;
	} while (direction);




More information about the XviD-devel mailing list