⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mot_code.c

📁 mpeg4源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
	else
	{
		aux = ABS(diff_vector) + scale_factor - 1;
			*vlc_code_mag = aux>>r_size;

			if (diff_vector<0)
			*vlc_code_mag = -*vlc_code_mag;

			*residual = aux & (scale_factor-1);
	}
}


/***********************************************************CommentBegin******
 *
 * -- find_pmvs --
 *
 * Purpose :
 *      Makes the motion vectors prediction for block 'block' (0 = whole MB)
 *
 ***********************************************************CommentEnd********/

Void											  /* MVP/Noel */
find_pmvs(
Image  *mot_x,									  /* x-motion vector field                             */
Image  *mot_y,									  /* y-motion vector field                             */
Image  *MB_decisions,							  /* MB modes                                          */
Image  *B_decisions,							  /* field with number of vectors per MB               */
Int    x,										  /* xpos of the MB in multiples of 16 (hor coord)     */
Int    y,										  /* ypos of the MB in multiples of 16 (ver coord)     */
Int    block,									  /* block number (0 if one vector per MB, 1..4 else)  */
Int    transparent_value,						  /* value of the transparency (0=enc, 2=dec)     */
Int    quarter_pel,   /* MW QPEL 06-JUL-1998 */	  /* flag to indicate quarter pel mc                   */
Int    *error_flag,								  /* set if an error occured                      */
Int    *mvx,									  /* hor predicted motion vector [ in half-pixels units ]  */
Int    *mvy,									  /* ver predicted motion vector [ in half-pixels units ]  */
Int    newgob
)
{
	Float   p1x,p2x,p3x;
	Float   p1y,p2y,p3y;
	Int     xin1, xin2, xin3;
	Int     yin1, yin2, yin3;
	Int     vec1, vec2, vec3;
	Int     rule1, rule2, rule3;
	Int     subdim;								  /* MW QPEL 06-JUL-1998 */
	Float   *motxdata = (Float *) GetImageData(mot_x);
	Float   *motydata = (Float *) GetImageData(mot_y);
	Int     xM = GetImageSizeX(mot_x);
	Int xB = xM;
	Int     mb_mode, sum;

	/* MW QPEL 06-JUL-1998 >> */
	if (quarter_pel)
	{
		subdim=4;
	}
	else
	{
		subdim=2;
	}
	/* << MW QPEL 06-JUL-1998 */

	/* In a previous version, a MB vector (block = 0) was predicted the same way
	   as block 1, which is the most likely interpretation of the VM.

	   Therefore, if we have advanced pred. mode, and if all MBs around have
	   only one 16x16 vector each, we chose the appropiate block as if these
	   MBs have 4 vectors.

	   This different prediction affects only 16x16 vectors of MBs with
	   transparent blocks.

	   In the current version, we choose for the 16x16 mode the first
	non-transparent block in the surrounding MBs
	*/

	switch (block)
	{
		case 0:
			vec1 = 1 ; yin1 = y  ; xin1 = x-1;
			vec2 = 2 ; yin2 = y-1; xin2 = x;
			vec3 = 2 ; yin3 = y-1; xin3 = x+1;
			break;
		case 1:
			vec1 = 1 ; yin1 = y  ; xin1 = x-1;
			vec2 = 2 ; yin2 = y-1; xin2 = x;
			vec3 = 2 ; yin3 = y-1; xin3 = x+1;
			break;
		case 2:
			vec1 = 0 ; yin1 = y  ; xin1 = x;
			vec2 = 3 ; yin2 = y-1; xin2 = x;
			vec3 = 2 ; yin3 = y-1; xin3 = x+1;
			break;
		case 3:
			vec1 = 3 ; yin1 = y  ; xin1 = x-1;
			vec2 = 0 ; yin2 = y  ; xin2 = x;
			vec3 = 1 ; yin3 = y  ; xin3 = x;
			break;
		case 4:
			vec1 = 2 ; yin1 = y  ; xin1 = x;
			vec2 = 0 ; yin2 = y  ; xin2 = x;
			vec3 = 1 ; yin3 = y  ; xin3 = x;
			break;
		default:
			printf("Illegal block number in find_pmv (mot_decode.c)");
			*error_flag = 1;
			*mvx=*mvy=0;
			return ;
	}

	if (block==0)
	{
		/* according to the motion encoding, we must choose a first non-transparent
		   block in the surrounding MBs (16-mode)
		 */

		if (x>0 /*&& ValidCandidateMVP(x,y,xin1,yin1,vec1,xB,transparent_value,
			MB_decisions,dcsn_data)*/)
			rule1 = 0;
		else
			rule1 = 1;

		if ((y>0 && newgob==0) /*&& ValidCandidateMVP(x,y,xin2,yin2,vec2,xB,transparent_value,
			MB_decisions,dcsn_data)*/)
			rule2 = 0;
		else
			rule2 = 1;

		if ((x != xB/2 -1) &&
			((y>0 && newgob==0)) /*&& ValidCandidateMVP(x,y,xin3,yin3,vec3,xB,transparent_value,
			MB_decisions,dcsn_data)*/)
			rule3 = 0;
		else
			rule3 = 1;
	}

	else
	{
		/* check borders for single blocks (advanced mode) */
		/* rule 1 */
												  /* left border */
		if (((block == 1 || block == 3) && (x == 0))  /*||
			/* left block/MB is transparent *
			(!ValidCandidateMVP(x,y,xin1,yin1,vec1,xB,transparent_value,
			MB_decisions,dcsn_data))*/)
			rule1 = 1;
		else
			rule1 = 0;

		/* rule 2 */
												  /* top border */
		if (((block == 1 || block == 2) && (y == 0))  /*||
			/* top block/MB is transparent *
			(!ValidCandidateMVP(x,y,xin2,yin2,vec2,xB,transparent_value,
			MB_decisions,dcsn_data))*/)
			rule2 = 1;
		else
			rule2 = 0;

		/* rule 3 */
		if (((block == 1 || block == 2) && (x == xB/2 -1 || y == 0)) /*||
			/* right & top border *
			/* right block/MB is transparent *
			(!ValidCandidateMVP(x,y,xin3,yin3,vec3,xB,transparent_value,
			MB_decisions,dcsn_data))*/)
			rule3 = 1;
		else
			rule3 = 0;

	}

	if (rule1 )
	{
		p1x = p1y = 0;
	}
	else if (((mb_mode = ModeMB(MB_decisions,xin1,yin1)) >= MBM_FIELD00) && (mb_mode <= MBM_FIELD11))
	{
		/* MW QPEL 06-JUL-1998 */
		sum = subdim*(BV(motxdata, xM, xin1, yin1, 0, 0) + BV(motxdata, xM, xin1, yin1, 1, 0));
		p1x = (Float)((sum & 3) ? ((sum | 2) >> 1) : (sum >> 1))/(Float)subdim;
		sum = subdim*(BV(motydata, xM, xin1, yin1, 0, 0) + BV(motydata, xM, xin1, yin1, 1, 0));
		p1y = (Float)((sum & 3) ? ((sum | 2) >> 1) : (sum >> 1))/(Float)subdim;
	}
	else
	{
		p1x = BV(motxdata, xM, xin1, yin1, vec1&0x1, vec1>>1 );
		p1y = BV(motydata, xM, xin1, yin1, vec1&0x1, vec1>>1 );
	}

	if (rule2)
	{
		p2x = p2y = 0 ;
	}
	else if (((mb_mode = ModeMB(MB_decisions,xin2,yin2)) >= MBM_FIELD00) && (mb_mode <= MBM_FIELD11))
	{
		/* MW QPEL 06-JUL-1998 */
		sum = subdim*(BV(motxdata, xM, xin2, yin2, 0, 0) + BV(motxdata, xM, xin2, yin2, 1, 0));
		p2x = (Float)((sum & 3) ? ((sum | 2) >> 1) : (sum >> 1))/(Float)subdim;
		sum = subdim*(BV(motydata, xM, xin2, yin2, 0, 0) + BV(motydata, xM, xin2, yin2, 1, 0));
		p2y = (Float)((sum & 3) ? ((sum | 2) >> 1) : (sum >> 1))/(Float)subdim;
	}
	else
	{
		p2x = BV(motxdata, xM, xin2, yin2, vec2&0x1, vec2>>1 );
		p2y = BV(motydata, xM, xin2, yin2, vec2&0x1, vec2>>1 );
	}

	if (rule3 )
	{
		p3x = p3y =0;
	}
	else if (((mb_mode = ModeMB(MB_decisions,xin3,yin3)) >= MBM_FIELD00) && (mb_mode <= MBM_FIELD11))
	{
		/* MW QPEL 06-JUL-1998 */
		sum = subdim*(BV(motxdata, xM, xin3, yin3, 0, 0) + BV(motxdata, xM, xin3, yin3, 1, 0));
		p3x = (Float)((sum & 3) ? ((sum | 2) >> 1) : (sum >> 1))/(Float)subdim;
		sum = subdim*(BV(motydata, xM, xin3, yin3, 0, 0) + BV(motydata, xM, xin3, yin3, 1, 0));
		p3y = (Float)((sum & 3) ? ((sum | 2) >> 1) : (sum >> 1))/(Float)subdim;
	}
	else
	{
		p3x = BV(motxdata, xM, xin3, yin3, vec3&0x1, vec3>>1 );
		p3y = BV(motydata, xM, xin3, yin3, vec3&0x1, vec3>>1 );
	}

	if (rule1 && rule2 && rule3 )
	{
		/* all MBs are outside the VOP */
		*mvx=*mvy=0;
	}
	else if (rule1+rule2+rule3 == 2)
	{
		/* two of three are zero */
		/* MW QPEL 06-JUL-1998 */
		*mvx=(Int) subdim*(p1x+p2x+p3x);		  /* MW QPEL 06-JUL-1998 */
		*mvy=(Int) subdim*(p1y+p2y+p3y);		  /* MW QPEL 06-JUL-1998 */
	}
	else
	{
		/* MW QPEL 06-JUL-1998 */
												  /* MW QPEL 06-JUL-1998 */
		*mvx=(Int)(subdim*(p1x+p2x+p3x-MAX(p1x,MAX(p2x,p3x))-MIN(p1x,MIN(p2x,p3x))));
												  /* MW QPEL 06-JUL-1998 */
		*mvy=(Int)(subdim*(p1y+p2y+p3y-MAX(p1y,MAX(p2y,p3y))-MIN(p1y,MIN(p2y,p3y))));
	}

	#ifdef _DEBUG_PMVS_
	fprintf(stdout,"find_pmvs (%2d,%2d, rule %1d%1d%1d) :\np1 %6.2f / %6.2f\np2 %6.2f / %6.2f\np3 %6.2f / %6.2f\n",x,y,rule1,rule2,rule3,p1x,p1y,p2x,p2y,p3x,p3y);
	#endif

	return;
}


/***********************************************************CommentBegin******
 *
 * -- ModeMB -- Get the MB mode
 *
 * Purpose :
 *	Get the MB mode
 *
 ***********************************************************CommentEnd********/

SInt ModeMB (Image *MB_decision, Int i, Int j)
{
	Int   width = MB_decision->x;
	SInt  *p = (SInt *)GetImageData(MB_decision);

	return p[width*j+i];
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -