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

📄 macroblock.c

📁 avs-s最新代码,包括编码器和解码器源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		img->coded_mb_nr= 0;
	}


	if(*end_of_picture == TRUE && img->cod_counter)
	{
		currSE->value1 = img->cod_counter;
		currSE->mapping = ue_linfo;
		currSE->type = SE_MBTYPE;
		writeSyntaxElement_UVLC(  currSE, currBitStream);
		rlc_bits=currSE->len;
		currMB->bitcounter[BITS_MB_MODE]+=rlc_bits;
		img->cod_counter = 0;
	}

}

/*
*************************************************************************
* Function: Checks the availability of neighboring macroblocks of
the current macroblock for prediction and context determination;
marks the unavailable MBs for intra prediction in the
ipredmode-array by -1. Only neighboring MBs in the causal
past of the current MB are checked.
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void CheckAvailabilityOfNeighbors()
{
	int i,j;

	//const int mb_width = input->img_width/MB_BLOCK_SIZE;
	const int mb_width = img->width/MB_BLOCK_SIZE; //add by wuzhongmou 0610
	const int mb_nr    = img->current_mb_nr;
	Macroblock *currMB = &img->mb_data[mb_nr];
	int   pix_x   = img->pix_x;  
	int   tmp_x   = img->block_x;
	int   tmp_y   = img->block_y;
	int   block_x = img->block_x/2;
	int   pix_y   = img->pix_y;   
	int   block_y = img->block_y/2;
	int   remove_prediction;

	img->block_x = block_x;
	img->block_y = block_y;

	// mark all neighbors as unavailable
	for (i=0; i<3; i++)
		for (j=0; j<3; j++)
		{
			img->mb_data[mb_nr].mb_available[i][j]=NULL;
		}

		img->mb_data[mb_nr].mb_available[1][1]=currMB; // current MB

		// Check MB to the left
		if(pix_x >= MB_BLOCK_SIZE)
		{
			if(!input->slice_set_enable)  //added by mz, 2008.04
				remove_prediction = currMB->slice_nr != img->mb_data[mb_nr-1].slice_nr;
			else
				remove_prediction = currMB->slice_set_index != img->mb_data[mb_nr-1].slice_set_index;
			// upper blocks
			if (remove_prediction)
			{
				img->ipredmode[img->block_x][img->block_y+1] = -1;
				img->ipredmode[img->block_x][img->block_y+2] = -1; 
			}

			// lower blocks
			if (remove_prediction)
			{
				img->ipredmode[img->block_x][img->block_y+3] = -1;
				img->ipredmode[img->block_x][img->block_y+4] = -1;
			}

			if (!remove_prediction)
			{
				currMB->mb_available[1][0]=&(img->mb_data[mb_nr-1]);
			}
		}

		// Check MB above
		if(pix_y >= MB_BLOCK_SIZE) 
		{
			if(!input->slice_set_enable)   //added by mz, 2008.04
				remove_prediction = currMB->slice_nr != img->mb_data[mb_nr-mb_width].slice_nr;
			else
				remove_prediction = currMB->slice_set_index != img->mb_data[mb_nr-mb_width].slice_set_index;

			// upper blocks
			if (remove_prediction)
			{
				img->ipredmode[img->block_x+1][img->block_y] = -1;
				img->ipredmode[img->block_x+2][img->block_y] = -1;
			}

			if (!remove_prediction)
			{  
				currMB->mb_available[0][1]=&(img->mb_data[mb_nr-mb_width]);
			}
		}

		// Check MB left above
		if(pix_x >= MB_BLOCK_SIZE && pix_y >= MB_BLOCK_SIZE )
		{
			if(!input->slice_set_enable)   //added by mz, 2008.04
				remove_prediction = currMB->slice_nr != img->mb_data[mb_nr-mb_width-1].slice_nr;
			else
				remove_prediction = currMB->slice_set_index != img->mb_data[mb_nr-mb_width-1].slice_set_index;

			if (remove_prediction)
			{ 

				img->ipredmode[img->block_x][img->block_y] = -1;
			}

			if (!remove_prediction)
			{
				currMB->mb_available[0][0]=&(img->mb_data[mb_nr-mb_width-1]);
			}
		}

		// Check MB right above
		if(pix_y >= MB_BLOCK_SIZE && img->pix_x < (img->width-MB_BLOCK_SIZE ))
		{
			if(!input->slice_set_enable)   //added by mz, 2008.04
			{
				if(currMB->slice_nr == img->mb_data[mb_nr-mb_width+1].slice_nr)
					currMB->mb_available[0][2]=&(img->mb_data[mb_nr-mb_width+1]);
			}
			else
			{
				if(currMB->slice_set_index == img->mb_data[mb_nr-mb_width+1].slice_set_index)
					currMB->mb_available[0][2]=&(img->mb_data[mb_nr-mb_width+1]);
			}
		}

		img->block_x = tmp_x;
		img->block_y = tmp_y;
}

/*
*************************************************************************
* Function:Predict one component of a 4x4 Luma block
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
void
OneComponentLumaPrediction4x4 (int*   mpred,      //  --> array of prediction values (row by row)
							   int    pic_pix_x,  // <--  absolute horizontal coordinate of 4x4 block
							   int    pic_pix_y,  // <--  absolute vertical   coordinate of 4x4 block
							   int*   mv,         // <--  motion vector
							   int    ref)        // <--  reference frame (0.. / -1:backward)
{
	int incr=0;/*lgp*13*/
	pel_t** ref_pic;
	int     pix_add = 4;
	int     j0      = (pic_pix_y << 2) + mv[1], j1=j0+pix_add, j2=j1+pix_add, j3=j2+pix_add;
	int     i0      = (pic_pix_x << 2) + mv[0], i1=i0+pix_add, i2=i1+pix_add, i3=i2+pix_add;
	int     i,j;

	pel_t (*get_pel) (pel_t**, int, int) = UMVPelY_14;


	//////cjw 20060321  for MV limit//////////////////////// 
	//MAX_V_SEARCH_RANGE	[-256, +255.75]
	//MAX_V_SEARCH_RANGE_FIELD	[-128, +127.75]
	//MAX_H_SEARCH_RANGE  [-2048, +2047.75]
	// MaxMVHRange= MAX_H_SEARCH_RANGE;
	//  MaxMVVRange= MAX_V_SEARCH_RANGE;
	//  	if(!img->picture_structure) //field coding
	//	{
	//		MaxMVVRange=MAX_V_SEARCH_RANGE_FIELD;
	//	}
	//
	//	if ( mv[0] < -MaxMVHRange || mv[0] > MaxMVHRange-1 
	//		|| mv[1] < -MaxMVVRange || mv[1] > MaxMVVRange-1 )
	//	{
	//		mv_out_of_range = 1;
	//	}
	//////////end cjw //////////////////////////////////////

	incr = 1;
	if(!img->picture_structure) //field coding
	{
		incr =2;
	}

	ref_pic   = img->type==B_IMG? mref [ref+incr] : mref [ref];

#ifdef BACKGROUND
	if(img->typeb == BP_IMG)
		ref_pic  = mref_background;
#endif

	for(j=0;j<4;j++)
	{
		for(i=0;i<4;i++)
		{
			*mpred++ = get_pel (ref_pic, j0+pix_add*j, i0+pix_add*i);
		}
	}
}

/*
*************************************************************************
* Function:Predict one 4x4 Luma block
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/

void
LumaPrediction4x4 (int  block_x,    // <--  relative horizontal block coordinate of 4x4 block
				   int  block_y,    // <--  relative vertical   block coordinate of 4x4 block
				   int  fw_mode,    // <--  forward  prediction mode (1-7, 0=DIRECT if bw_mode=0)
				   int  bw_mode,    // <--  backward prediction mode (1-7, 0=DIRECT if fw_mode=0)
				   int  fw_ref,      // <--  reference frame for forward prediction (-1: Intra4x4 pred. with fw_mode)
				   int  bw_ref  )    
{
	static int fw_pred[16];
	static int bw_pred[16];
	int  i, j;
	int  block_x4  = block_x+4;
	int  block_y4  = block_y+4;
	int  pic_pix_x = img->pix_x + block_x;
	int  pic_pix_y = img->pix_y + block_y;
	int  bx        = block_x >> 3;
	int  by        = block_y >> 3;
	int* fpred     = fw_pred;
	int* bpred     = bw_pred;
	int  direct    = (fw_mode == 0 && bw_mode == 0 && (img->type==B_IMG));
	int  skipped   = (fw_mode == 0 && bw_mode == 0 && (img->type!=B_IMG));
	//int  *****fmv_array = img->all_mv;    // For MB level frame/field coding
	int scale_frame;
	int  *****fmv_array = (fw_mode && bw_mode)?img->all_omv:img->all_mv;    // For MB level frame/field coding
	int  *****bmv_array = img->all_bmv;   // For MB level frame/field coding
	//cjw 20060112 for weighted prediction
	int fw_lum_scale , fw_lum_shift ;
	int bw_lum_scale , bw_lum_shift ;
	int bw_ref_num ;
	int fw_ref_num ;
	int  DistanceIndexRef = 0; //zj
	int  DistanceIndexCur = 0;
	int  DistanceIndexFw0 = 0;

	//cjw weighted prediction parameter map 20060112
	/*///frame coding/////////
	P		img->lum_scale[0]  fw[0] 
	img->lum_scale[1]  fw[1]			
	B	    img->lum_scale[0]  fw[0]
	img->lum_scale[1]  bw[0]
	///field coding////////
	P		img->lum_scale[0]  fw[0] ; img->lum_scale[1]  fw[1] 
	img->lum_scale[2]  fw[2] ; img->lum_scale[3]  fw[3] 			
	B		img->lum_scale[0]  fw[0] ; img->lum_scale[1]  bw[0] 
	img->lum_scale[2]  fw[1] ; img->lum_scale[3]  bw[1] 
	*/			

#ifndef COREFRAME	
	if (direct)    
	{
		fw_ref= 0;//max(refFrArr[ipdirect_y][ipdirect_x],0);
		bw_ref= 0;//min(refFrArr[ipdirect_y][ipdirect_x],0);
		if(!img->picture_structure) //field coding
		{
			scale_frame = refFrArr[img->block8_y + by][img->block8_x+bx];
			bw_ref = 0;//-1; xyji 11.25
			if (img->current_mb_nr_fld < img->total_number_mb) //top field
			{
				fw_ref =  scale_frame >= 1 ? 1 : 0;
				bw_ref = scale_frame >= 0 ?1 :0; 
			}
			else
			{
				fw_ref =(scale_frame == 1 || scale_frame < 0)? 0 : 1; 
				bw_ref = 0;
			}

			if(scale_frame < 0)
				bw_ref = 1;
		}
	}
#else
	if (direct)    
	{
		fw_ref= 0;//max(refFrArr[ipdirect_y][ipdirect_x],0);
		bw_ref= 0;//min(refFrArr[ipdirect_y][ipdirect_x],0);
		if(!img->picture_structure) //field coding
		{
			scale_frame = refFrArr[img->block8_y + by][img->block8_x+bx];
			bw_ref = 0;//-1; xyji 11.25


			if(img->current_mb_nr_fld < img->total_number_mb) //top field
			{
				//DistanceIndexCur
				DistanceIndexCur = 2*picture_distance;
				//DistanceIndexRef
				if (scale_frame==0)
				{
					DistanceIndexRef = 2*img->imgtr_last_P_frm+1;
					//核心帧
					if(img->img_next_is_core_frame==1)
						DistanceIndexRef = 2*img->img_next_core_frame_ref_distance+1;
				}
				else if (scale_frame==1)
				{
					DistanceIndexRef = 2*img->imgtr_last_P_frm;
					//核心帧
					if(img->img_next_is_core_frame==1)
						DistanceIndexRef = 2*img->img_next_core_frame_ref_distance;
				}
				else if (scale_frame==2)
				{
					DistanceIndexRef = 2*img->imgtr_last_last_P_frm+1;
				}
				else if (scale_frame==3)
				{
					DistanceIndexRef = 2*img->imgtr_last_last_P_frm;
				}
				DistanceIndexFw0 = 2*img->imgtr_last_P_frm+1;
				//DistanceIndexFw
				if (DistanceIndexRef == DistanceIndexFw0)
				{
					fw_ref = 0;//fw reference               
				}
				else
				{
					fw_ref = 1;                 
				}
				//DistanceIndexBw
				bw_ref = 1;//bw reference        

			}
			else
			{
				//DistanceIndexCur
				DistanceIndexCur = 2*picture_distance+1;
				//DistanceIndexRef
				if (scale_frame==0)
				{
					DistanceIndexRef = 2*img->imgtr_next_P_frm;
				}
				else if (scale_frame==1)
				{
					DistanceIndexRef = 2*img->imgtr_last_P_frm+1;
					//核心帧
					if(img->img_next_is_core_frame==1)
						DistanceIndexRef = 2*img->img_next_core_frame_ref_distance+1;
				}
				else if (scale_frame==2)
				{
					DistanceIndexRef = 2*img->imgtr_last_P_frm;
					//核心帧
					if(img->img_next_is_core_frame==1)
						DistanceIndexRef = 2*img->img_next_core_frame_ref_distance;
				}
				else if (scale_frame==3)
				{
					DistanceIndexRef = 2*img->imgtr_last_last_P_frm+1;
				}
				DistanceIndexFw0 = 2*img->imgtr_last_P_frm+1;

				if (DistanceIndexRef == DistanceIndexFw0)
				{
					fw_ref = 0;//fw reference

				}
				else
				{
					fw_ref = 1;

				}
				//DistanceIndexBw
				bw_ref = 0;//bw reference

			}



			if(scale_frame < 0)
			{
				fw_ref = 0;
				bw_ref = 1;
			}

		}
	}
#endif


	direct_mode = direct;

	if (fw_mode ||(direct && (fw_ref !=-1) )|| skipped)
	{
		if(!img->picture_structure)  // !! field shenyanfei 
			OneComponentLumaPrediction4x4 (fw_pred, pic_pix_x, pic_pix_y, fmv_array [bx][by][fw_ref][fw_mode], fw_ref);
		else						// !! frame shenyanfei 
			OneComponentLumaPrediction4x4 (fw_pred, pic_pix_x, pic_pix_y, fmv_array [bx][by][fw_ref][fw_mode], (direct ?0:fw_ref));
	}
	if (bw_mode || (direct && (bw_ref !=-1) ) ||(direct && !img->picture_structure && (bw_ref ==-1) ) )
	{
		int delta_P,TRp,DistanceIndexFw,DistanceIndexBw,refframe,delta_PB;

⌨️ 快捷键说明

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