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

📄 macroblock.c

📁 这是最新的AVS代码中的视频部分。2006年9月份发布的。有需要的可能下载使用。
💻 C
📖 第 1 页 / 共 5 页
字号:
  strncpy(currSE.tracestring, "Ipred Mode", TRACESTRING_SIZE);
#endif
  
	if(b8<4)
	{		
		if( currMB->b8mode[b8]==IBLOCK )
		{
			IntraChromaPredModeFlag = 1;
			//get from stream
			readSyntaxElement_Intra8x8PredictionMode(&currSE);
			
			//get from array and decode
			bi = img->block_x + (b8&1);
			bj = img->block_y + (b8/2);
			
			upIntraPredMode            = img->ipredmode[bi+1][bj];
			leftIntraPredMode          = img->ipredmode[bi][bj+1];
			mostProbableIntraPredMode  = (upIntraPredMode < 0 || leftIntraPredMode < 0) ? DC_PRED : upIntraPredMode < leftIntraPredMode ? upIntraPredMode : leftIntraPredMode;
			
			dec = (currSE.value1 == -1) ? mostProbableIntraPredMode : currSE.value1 + (currSE.value1 >= mostProbableIntraPredMode);
			
			//set
			img->ipredmode[1+bi][1+bj]=dec;
			j2 = bj;
		}
	}	
	else if( b8==4&&currMB->b8mode[b8-3]==IBLOCK)
	{
		
	    currSE.type = SE_INTRAPREDMODE;
#if TRACE
    strncpy(currSE.tracestring, "Chroma intra pred mode", TRACESTRING_SIZE);
#endif
    
	    currSE.mapping = linfo_ue;
    
	    readSyntaxElement_UVLC(&currSE,inp);
	    currMB->c_ipred_mode = currSE.value1;

	    if (currSE.value1 < DC_PRED_8 || currSE.value1 > PLANE_8)
	    {
	      printf("%d\n", img->current_mb_nr);
	      error("illegal chroma intra pred mode!\n", 600);
	    }
	 }
}

/*
******************************************************************************
*  Function: calculated field or frame distance between current field(frame)
*            and the reference field(frame).
*     Input:
*    Output:
*    Return: 
* Attention:
*    Author: Yulejun // 2004.07.14
******************************************************************************
*/
int calculate_distance(int blkref, int fw_bw )  //fw_bw>=0: forward ; fw_bw<0: backward
{
  int distance;
  if( img->picture_structure == 1 )
  {
    if ( img->type==P_IMG ) // P img
    {
        if(blkref==0)
              distance = img->tr*2 - img->imgtr_last_P*2;
        else if(blkref==1)
              distance = img->tr*2 - img->imgtr_last_prev_P*2;
	else
	{
	      assert(0); //only two reference pictures for P frame
	}
    }
    else //B_IMG
    {
	if (fw_bw >=0 ) //forward
	      distance = img->tr*2 - img->imgtr_last_P*2;
	else
	      distance = img->imgtr_next_P*2  - img->tr*2;

    }
  }  
  else if( ! img->picture_structure )
  {
    if(img->type==P_IMG)
    {
      if(img->top_bot==0) //top field
			{
				switch ( blkref )
				{
				case 0:
					distance = img->tr*2 - img->imgtr_last_P*2 - 1 ;
					break;
				case 1:
					distance = img->tr*2 - img->imgtr_last_P*2 ;
					break;
				case 2:
					distance = img->tr*2 - img->imgtr_last_prev_P*2 - 1;
					break;
				case 3:
					distance = img->tr*2 - img->imgtr_last_prev_P*2 ;
					break;
				}
			}
        else if(img->top_bot==1) // bottom field.
			{
				switch ( blkref )
				 {
				case 0:
					distance = 1 ;
					break;
				case 1:
					distance = img->tr*2 - img->imgtr_last_P*2 ;
					break;
				case 2:
					distance = img->tr*2 - img->imgtr_last_P*2 + 1;
					break;
				case 3:
					distance = img->tr*2 - img->imgtr_last_prev_P*2 ;
						break;
				  }
			}
	else 
			{
				printf("Error. frame picture should not run into this branch.");
				exit(-1);
			}
    }
    else if(img->type==B_IMG)
    {
			assert(blkref==0 || blkref == 1);
			if (fw_bw >= 0 ) //forward
			{
				if(img->top_bot==0) //top field
				{
					switch ( blkref )
					{
					case 0:
						distance = img->tr*2 - img->imgtr_last_P*2 - 1 ;
						break;
					case 1:
						distance = img->tr*2 - img->imgtr_last_P*2;
						break;
					}
				}
				else if(img->top_bot==1) // bottom field.
				{
				        switch ( blkref )
					{
					case 0:
						distance = img->tr*2 - img->imgtr_last_P*2 ;
						break;
					case 1:
						distance = img->tr*2 - img->imgtr_last_P*2 + 1;
						break;
					}
				}
				else 
				{
					printf("Error. frame picture should not run into this branch.");
					exit(-1);
				}
			}
			else // backward
			{
				if(img->top_bot==0) //top field
				{
					switch ( blkref )
					{
					case 0:
						distance = img->imgtr_next_P*2 - img->tr*2;
						break;
					case 1:
						distance = img->imgtr_next_P*2 - img->tr*2 + 1;
						break;
					}
				}
				else if(img->top_bot==1) // bottom field.
				{
					switch ( blkref )
					{
					case 0:
						distance = img->imgtr_next_P*2 - img->tr*2 -  1;
						break;
					case 1:
						distance = img->imgtr_next_P*2 - img->tr*2 ;
						break;
					}
				}
				else 
				{
					printf("Error. frame picture should not run into this branch.");
					exit(-1);
				}
			}

    }
  }
  return distance;
}
/*Lou 1016 Start*/
//The unit of time distance is calculated by field time
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
int scale_motion_vector(int motion_vector, int currblkref, int neighbourblkref, int currsmbtype, int neighboursmbtype, int block_y_pos, int curr_block_y, int ref, int direct_mv)
{
    int neighbour_coding_stage = -2;
    int current_coding_stage = -2;
    int sign = (motion_vector>0?1:-1);
    int mult_distance;
    int devide_distance;

    motion_vector = abs(motion_vector);

    if(motion_vector == 0)
        return 0;


    mult_distance = calculate_distance( currblkref, ref );
    devide_distance = calculate_distance(neighbourblkref, ref);

    motion_vector = sign*((motion_vector*mult_distance*(512/devide_distance)+256)>>9);

    return motion_vector;
}
/*Lou 1016 End*/

/*
*************************************************************************
* Function:Set motion vector predictor
* Input:
* Output:
* Return: 
* Attention:
*************************************************************************
*/
static void SetMotionVectorPredictor (struct img_par  *img,
                                      int             *pmv_x,
                                      int             *pmv_y,
                                      int             ref_frame,
                                      int             **refFrArr,
                                      int             ***tmp_mv,
                                      int             block_x,
                                      int             block_y,
                                      int             blockshape_x,
                                      int             blockshape_y,
				      int             ref,
                                      int             direct_mv)//Lou 1016
{
  int mb_x                 = 8*block_x;
  int mb_y                 = 8*block_y;
  int pic_block_x          = img->block_x + block_x;
  int pic_block_y          = img->block_y + block_y;
  int mb_width             = img->width/16;
  int mb_nr = img->current_mb_nr;
  int mb_available_up   = (img->mb_y == 0 ) ? 0 : (mb_data[mb_nr].slice_nr == mb_data[mb_nr-mb_width  ].slice_nr);  // jlzheng 6.23 
  int mb_available_left = (img->mb_x == 0 ) ? 0 : (mb_data[mb_nr].slice_nr == mb_data[mb_nr-1         ].slice_nr);  // jlzheng 6.23
  int mb_available_upleft  = (img->mb_x == 0) ? 0 : ((img->mb_y == 0) ? 0 : 
  (mb_data[mb_nr].slice_nr == mb_data[mb_nr-mb_width-1].slice_nr));
  int mb_available_upright = (img->mb_y == 0) ? 0 : ((img->mb_x >= (mb_width-1)) ? 0 :
  (mb_data[mb_nr].slice_nr == mb_data[mb_nr-mb_width+1].slice_nr));
  
  int block_available_up, block_available_left, block_available_upright, block_available_upleft;
  int mv_a, mv_b, mv_c, mv_d, pred_vec=0;
  int mvPredType, rFrameL, rFrameU, rFrameUR;
  int hv;
  int mva[3] , mvb[3],mvc[3];
	int y_up = 1,y_upright=1,y_upleft=1,off_y=0;	
    /*Lou 1016 Start*/
  int rFrameUL;
  Macroblock*     currMB = &mb_data[img->current_mb_nr];
  int smbtypecurr, smbtypeL, smbtypeU, smbtypeUL, smbtypeUR;
  

    smbtypecurr = -2;
    smbtypeL = -2;
    smbtypeU = -2;
    smbtypeUL = -2;
    smbtypeUR = -2;
  /*Lou 1016 End*/

  /* D B C */
  /* A X   */
  
  /* 1 A, B, D are set to 0 if unavailable       */
  /* 2 If C is not available it is replaced by D */

   block_available_up   = mb_available_up   || (mb_y > 0);
   block_available_left = mb_available_left || (mb_x > 0);
  
  if (mb_y > 0)
  {
    if (mb_x < 8)  // first column of 8x8 blocks
    {
      if (mb_y==8)
      {
        if (blockshape_x == 16)      block_available_upright = 0;
        else                         block_available_upright = 1;
      }
      else
      {
        if (mb_x+blockshape_x != 8)  block_available_upright = 1;
        else                         block_available_upright = 0;
      }
    }
    else
    {
      if (mb_x+blockshape_x != 16)   block_available_upright = 1;
      else                           block_available_upright = 0;
    }
  }
  else if (mb_x+blockshape_x != MB_BLOCK_SIZE)
  {
    block_available_upright = block_available_up;
  }
  else
  {
    block_available_upright = mb_available_upright;
  }
  
  if (mb_x > 0)
  {
    block_available_upleft = (mb_y > 0 ? 1 : mb_available_up);
  }
  else if (mb_y > 0)
  {
    block_available_upleft = mb_available_left;
  }
  else
  {
    block_available_upleft = mb_available_upleft;
  }

    smbtypecurr = -2;
    smbtypeL = -2;
    smbtypeU = -2;
    smbtypeUL = -2;
    smbtypeUR = -2;

    mvPredType = MVPRED_MEDIAN;

    rFrameL    = block_available_left    ? refFrArr[pic_block_y]  [pic_block_x-1] : -1;
    rFrameU    = block_available_up      ? refFrArr[pic_block_y-1][pic_block_x]   : -1;
    rFrameUR   = block_available_upright ? refFrArr[pic_block_y-1][pic_block_x+blockshape_x/8] :
    block_available_upleft  ? refFrArr[pic_block_y-1][pic_block_x-1] : -1;
    rFrameUL   = block_available_upleft  ? refFrArr[pic_block_y-1][pic_block_x-1] : -1;

  if((rFrameL != -1)&&(rFrameU == -1)&&(rFrameUR == -1))
    mvPredType = MVPRED_L;
  else if((rFrameL == -1)&&(rFrameU != -1)&&(rFrameUR == -1))
    mvPredType = MVPRED_U;
  else if((rFrameL == -1)&&(rFrameU == -1)&&(rFrameUR != -1))
    mvPredType = MVPRED_UR;
  /*Lou 1016 End*/   
  // Directional predictions 
  else if(blockshape_x == 8 && blockshape_y == 16)
  {
    if(mb_x == 0)
    {
      if(rFrameL == ref_frame)
        mvPredType = MVPRED_L;
    }
    else
    {
      if( rFrameUR == ref_frame)
        mvPredType = MVPRED_UR;
    }
  }
  else if(blockshape_x == 16 && blockshape_y == 8)
  {
    if(mb_y == 0)
    {
      if(rFrameU == ref_frame)
        mvPredType = MVPRED_U;
    }
    else
    {
      if(rFrameL == ref_frame)
        mvPredType = MVPRED_L;
    }
  }
  
  #define MEDIAN(a,b,c)  (a + b + c - min(a, min(b, c)) - max(a, max(b, c)));

  for (hv=0; hv < 2; hv++)
  {
    mva[hv] = mv_a = block_available_left    ? tmp_mv[4+pic_block_x-1             ][pic_block_y][hv] : 0;
    mvb[hv] = mv_b = block_available_up      ? tmp_mv[4+pic_block_x               ][pic_block_y-1][hv] : 0;
    mv_d = block_available_upleft  ? tmp_mv[4+pic_block_x-1][pic_block_y-1][hv] : 0;
    mvc[hv] = mv_c = block_available_upright ? tmp_mv[4+pic_block_x+blockshape_x/8][pic_block_y-1][hv] : mv_d;
    //--- Yulj 2004.07.14
    // mv_a, mv_b... are not scaled.
    mva[hv] = scale_motion_vector(mva[hv], ref_frame, rFrameL, smbtypecurr, smbtypeL, pic_block_y-off_y, pic_block_y, ref, direct_mv);
    mvb[hv] = scale_motion_vector(mvb[hv], ref_frame, rFrameU, smbtypecurr, smbtypeU, pic_block_y-y_up, pic_block_y, ref, direct_mv);
    mv_d = scale_motion_vector(mv_d, ref_frame, rFrameUL, smbtypecurr, smbtypeUL, pic_block_y-y_upleft, pic_block_y, ref, direct_mv);
    mvc[hv] = block_available_upright ? scale_motion_vector(mvc[hv], ref_frame, rFrameUR, smbtypecurr, smbtypeUR, pic_block_y-y_upright, pic_block_y, ref, direct_mv): mv_d;
   
    
    switch (mvPredType)
    {
    case MVPRED_MEDIAN:

      if(hv == 1){
          //  jlzheng 7.2
          // !! for A 

          mva[2] = abs(mva[0] - mvb[0])	+ abs(mva[1] - mvb[1]);
          // !! for B

	  mvb[2] = abs(mvb[0] - mvc[0]) + abs(mvb[1] - mvc[1]);
          // !! for C

          mvc[2] = abs(mvc[0] - mva[0])	+ abs(mvc[1] - mva[1]);
          

⌨️ 快捷键说明

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