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

📄 macroblock.cpp

📁 h264编解码.用C++实现了图像的编解码功能。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  // make horiz and vert prediction
  ///////////////////////////////

  for (i=0; i < 16; i++)
  {
    img->mprr_2[HOR_PRED][i]	 = s1;
    img->mprr_2[HOR_PRED][16+i]  = s2;
    img->mprr_2[HOR_PRED][32+i]  = s3;
    img->mprr_2[HOR_PRED][48+i]  = s4;
	img->mprr_2[HOR_PRED][64+i]	 = s5;
    img->mprr_2[HOR_PRED][80+i]  = s6;
    img->mprr_2[HOR_PRED][96+i]  = s7;
    img->mprr_2[HOR_PRED][112+i] = s8;
	img->mprr_2[HOR_PRED][128+i] = s9;
    img->mprr_2[HOR_PRED][144+i] = s10;
    img->mprr_2[HOR_PRED][160+i] = s11;
    img->mprr_2[HOR_PRED][176+i] = s12;
	img->mprr_2[HOR_PRED][192+i] = s13;
    img->mprr_2[HOR_PRED][208+i] = s14;
    img->mprr_2[HOR_PRED][224+i] = s15;
    img->mprr_2[HOR_PRED][240+i] = s16;
  }  
  current_intra_sad = IntraMB_Sad(img,imgY_org+img_offset,img->mprr_2[HOR_PRED]);
  if( current_intra_sad <= (*tot_intra_sad))
  {
	  *tot_intra_sad = current_intra_sad;
	  *imode = HOR_PRED_16;
  }
  return *tot_intra_sad; 
}

int intrapred_luma_top(struct img_par *img,int img_x,int img_y,int *tot_intra_sad,int block_num)
{
  int i,j,s0;
  int pi,pj,pk,pl;
  int block_x=img_x&15;
  int block_y=img_y&15;
  int width=img->width+IMG_PAD_SIZE;
  int best_intra_sad;
  int upMode,leftMode,mostProbableMode,best_ipmode;
  double lambda_mode = QP2QUANT[max(0,img->qp-SHIFT_QP)];
  int nonzero;
  int img_offset = img_y*width+img_x;
  int current_intra_sad;
  
  //pe=pf=pg=ph=pa=pb=pc=pd=128;
  pi=imgY[ img_y   *width+img_x-1];
  pj=imgY[(img_y+1)*width+img_x-1];
  pk=imgY[(img_y+2)*width+img_x-1];
  pl=imgY[(img_y+3)*width+img_x-1];
  
  ///////////////////////////////
  // make DC prediction
  ///////////////////////////////
  s0 = (pi + pj + pk + pl + 2)>>2;
  for (j=0; j < BLOCK_SIZE; j++)
  {
	  i=j<<2;
      img->mprr[DC_PRED][i] = s0;
      img->mprr[DC_PRED][i+1] = s0;
      img->mprr[DC_PRED][i+2] = s0;
      img->mprr[DC_PRED][i+3] = s0;
  }

  ///////////////////////////////
  // make horiz and vert prediction
  ///////////////////////////////

  for (i=0; i < BLOCK_SIZE; i++)
  {
    img->mprr[HOR_PRED][i]  = pi;
    img->mprr[HOR_PRED][4+i]  = pj;
    img->mprr[HOR_PRED][8+i]  = pk;
    img->mprr[HOR_PRED][12+i]  = pl;
  }

    // Mode HOR_UP_PRED
    img->mprr[HOR_UP_PRED][0] = (pi + pj + 1) >>1;
    img->mprr[HOR_UP_PRED][1] = (pi + 2*pj + pk + 2) >>2;
    img->mprr[HOR_UP_PRED][2] = 
    img->mprr[HOR_UP_PRED][4] = (pj + pk + 1) >>1;
    img->mprr[HOR_UP_PRED][3] = 
    img->mprr[HOR_UP_PRED][5] = (pj + 2*pk + pl + 2) >>2;
    img->mprr[HOR_UP_PRED][6] = 
    img->mprr[HOR_UP_PRED][8] = (pk + pl + 1) >>1;
    img->mprr[HOR_UP_PRED][7] = 
    img->mprr[HOR_UP_PRED][9] = (pk + 2*pl + pl + 2) >>2;
    img->mprr[HOR_UP_PRED][12] = 
    img->mprr[HOR_UP_PRED][10] = 
    img->mprr[HOR_UP_PRED][11] = 
    img->mprr[HOR_UP_PRED][13] = 
    img->mprr[HOR_UP_PRED][14] = 
    img->mprr[HOR_UP_PRED][15] = pl;
    
    upMode = img->ipredmode[img_x/BLOCK_SIZE+1][img_y>>2];
    leftMode = img->ipredmode[img_x/BLOCK_SIZE][(img_y>>2)+1];
    mostProbableMode  = (upMode < 0 || leftMode < 0) ? DC_PRED : upMode < leftMode ? upMode : leftMode;
    
    best_intra_sad  = (DC_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    best_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[DC_PRED]);                
    best_ipmode=DC_PRED;

    current_intra_sad  = (HOR_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    current_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[HOR_PRED]);            
    if (current_intra_sad < best_intra_sad) 
    {
    	best_intra_sad=current_intra_sad;
        best_ipmode=HOR_PRED;
    }
    
    current_intra_sad  = (HOR_UP_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    current_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[HOR_UP_PRED]);            
    if (current_intra_sad < best_intra_sad) 
    {
    	best_intra_sad=current_intra_sad;
        best_ipmode=HOR_UP_PRED;
    }
    
    *tot_intra_sad+=best_intra_sad;
  
  img->ipredmode[(img_x>>2)+1][(img_y>>2)+1]=best_ipmode;
  img->intra_pred_modes[block_num] = mostProbableMode == best_ipmode ? -1 : best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1;
          
  nonzero = dct_luma(imgY_org+img_offset,img->mprr[best_ipmode],block_x,block_y,img);       
  return nonzero; 
}

int intrapred_luma_left(struct img_par *img,int img_x,int img_y,int *tot_intra_sad,int block_num)
{
  int i,j,s0;
  int pa,pb,pc,pd,pe,pf,pg,ph,pi,pj,pk,pl,px;
  int pic_block_x=img_x>>2;
  int pic_block_y=img_y>>2;
  int block_x=img_x&15;
  int block_y=img_y&15;
  int width=img->width+IMG_PAD_SIZE;
  int best_intra_sad;
  int upMode,leftMode,mostProbableMode,best_ipmode;
  double lambda_mode = QP2QUANT[max(0,img->qp-SHIFT_QP)];
  int nonzero;
  int temp = img_y*width;
  int img_offset = temp+img_x;
  int current_intra_sad;

  temp -= width+img_x;  
  pa=imgY[temp];
  pb=imgY[temp+1];
  pc=imgY[temp+2];
  pd=imgY[temp+3];
  
  pe=imgY[temp+4];
  pf=imgY[temp+5];
  pg=imgY[temp+6];
  ph=imgY[temp+7];
  
  pi=pj=pk=pl=128;
  
  px=128;
  ///////////////////////////////
  // make DC prediction
  ///////////////////////////////
    // left edge
    s0 = (pa + pb + pc + pd + 2)>>2;             
  for (j=0; j < BLOCK_SIZE; j++)
  {
	  i=j*4;
      img->mprr[DC_PRED][i] = s0;
      img->mprr[DC_PRED][i+1] = s0;
      img->mprr[DC_PRED][i+2] = s0;
      img->mprr[DC_PRED][i+3] = s0;
  }

  ///////////////////////////////
  // make horiz and vert prediction
  ///////////////////////////////

  for (i=0; i < BLOCK_SIZE; i++)
  {
	img->mprr[VERT_PRED][i*4] = pa;
	img->mprr[VERT_PRED][i*4+1] = pb;
	img->mprr[VERT_PRED][i*4+2] = pc;
	img->mprr[VERT_PRED][i*4+3] = pd;
  }

    // Mode DIAG_DOWN_LEFT_PRED
    img->mprr[DIAG_DOWN_LEFT_PRED][0] = (pa + pc + (pb<<1) + 2)>>2;
    img->mprr[DIAG_DOWN_LEFT_PRED][1] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][4] = (pb + pd + (pc<<1) + 2)>>2;
    img->mprr[DIAG_DOWN_LEFT_PRED][2] =
    img->mprr[DIAG_DOWN_LEFT_PRED][5] =
    img->mprr[DIAG_DOWN_LEFT_PRED][8] = (pc + pe + (pd<<1) + 2)>>2;
    img->mprr[DIAG_DOWN_LEFT_PRED][3] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][6] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][9] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][12] = (pd + pf + (pe<<1) + 2)>>2;
    img->mprr[DIAG_DOWN_LEFT_PRED][7] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][10] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][13] = (pe + pg + (pf<<1) + 2)>>2;
    img->mprr[DIAG_DOWN_LEFT_PRED][11] = 
    img->mprr[DIAG_DOWN_LEFT_PRED][14] = (pf + ph + (pg<<1) + 2)>>2;
    img->mprr[DIAG_DOWN_LEFT_PRED][15] = (pg + 3*(ph) + 2)>>2;

    // Mode VERT_LEFT_PRED
    img->mprr[VERT_LEFT_PRED][0] = (pa + pb + 1)>>1;
    img->mprr[VERT_LEFT_PRED][1] = 
    img->mprr[VERT_LEFT_PRED][8] = (pb + pc + 1)>>1;
    img->mprr[VERT_LEFT_PRED][2] = 
    img->mprr[VERT_LEFT_PRED][9] = (pc + pd + 1)>>1;
    img->mprr[VERT_LEFT_PRED][3] = 
    img->mprr[VERT_LEFT_PRED][10] = (pd + pe + 1)>>1;
    img->mprr[VERT_LEFT_PRED][11] = (pe + pf + 1)>>1;
    img->mprr[VERT_LEFT_PRED][4] = (pa + (pb<<1) + pc + 2)>>2;
    img->mprr[VERT_LEFT_PRED][5] = 
    img->mprr[VERT_LEFT_PRED][12] = (pb + (pc<<1) + pd + 2)>>2;
    img->mprr[VERT_LEFT_PRED][6] = 
    img->mprr[VERT_LEFT_PRED][13] = (pc + (pd<<1) + pe + 2)>>2;
    img->mprr[VERT_LEFT_PRED][7] = 
    img->mprr[VERT_LEFT_PRED][14] = (pd + (pe<<1) + pf + 2)>>2;
    img->mprr[VERT_LEFT_PRED][15] = (pe + (pf<<1) + pg + 2)>>2;
    
    upMode = img->ipredmode[(img_x>>2)+1][img_y>>2];
    leftMode = img->ipredmode[img_x>>2][(img_y>>2)+1];
    mostProbableMode  = (upMode < 0 || leftMode < 0) ? DC_PRED : upMode < leftMode ? upMode : leftMode;
    
    best_intra_sad  = (DC_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    best_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[DC_PRED]);                
    best_ipmode=DC_PRED;

    current_intra_sad  = (VERT_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    current_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[VERT_PRED]);            
    if (current_intra_sad < best_intra_sad) 
    {
    	best_intra_sad=current_intra_sad;
        best_ipmode=VERT_PRED;
    }
    
    current_intra_sad  = (DIAG_DOWN_LEFT_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    current_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[DIAG_DOWN_LEFT_PRED]);            
    if (current_intra_sad < best_intra_sad) 
    {
    	best_intra_sad=current_intra_sad;
        best_ipmode=DIAG_DOWN_LEFT_PRED;
    }
    
    current_intra_sad  = (VERT_LEFT_PRED == mostProbableMode) ? 0 : (int)floor(4 * lambda_mode );			  
    current_intra_sad += Intra_Sad(img,imgY_org+img_offset,img->mprr[VERT_LEFT_PRED]);            
    if (current_intra_sad < best_intra_sad) 
    {
    	best_intra_sad=current_intra_sad;
        best_ipmode=VERT_LEFT_PRED;
    }
    
    *tot_intra_sad+=best_intra_sad;
  
  img->ipredmode[pic_block_x+1][pic_block_y+1]=best_ipmode;
  img->intra_pred_modes[block_num] = mostProbableMode == best_ipmode ? -1 : best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1;
          
  nonzero = dct_luma(imgY_org+img_offset,img->mprr[best_ipmode],block_x,block_y,img);       
  return nonzero; 
}

/*yummy*/
int intrapred_lumaMB_left(struct img_par *img,int img_x,int img_y,int *tot_intra_sad,int *imode)
{
  int i,j,s0;  
  int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16;  
  int width=img->width+IMG_PAD_SIZE;
  int img_offset = img_y*width+img_x;
  int temp = img_offset-width;
  int current_intra_sad;

  /*up pixel*/
  s1 = imgY[temp];
  s2 = imgY[temp+1];
  s3 = imgY[temp+2];
  s4 = imgY[temp+3];
  s5 = imgY[temp+4];
  s6 = imgY[temp+5];
  s7 = imgY[temp+6];
  s8 = imgY[temp+7];
  s9 = imgY[temp+8];
  s10 = imgY[temp+9];
  s11 = imgY[temp+10];
  s12 = imgY[temp+11];
  s13 = imgY[temp+12];
  s14 = imgY[temp+13];
  s15 = imgY[temp+14];
  s16 = imgY[temp+15];

  ///////////////////////////////
  // make DC prediction
  ///////////////////////////////
    // left edge
  s0 = (s1 +s2 +s3 +s4 +s5 +s6 +s7 +s8 +s9 +s10 +s11 +s12 +s13 +s14 +s15 +s16 + 8)>>4;          
  for (j=0; j < 256; j+=16)
  {
      img->mprr_2[DC_PRED][j]	= s0;		img->mprr_2[DC_PRED][j+1] = s0;
      img->mprr_2[DC_PRED][j+2] = s0;		img->mprr_2[DC_PRED][j+3] = s0;
	  img->mprr_2[DC_PRED][j+4] = s0;		img->mprr_2[DC_PRED][j+5] = s0;
      img->mprr_2[DC_PRED][j+6] = s0;		img->mprr_2[DC_PRED][j+7] = s0;
	  img->mprr_2[DC_PRED][j+8] = s0;		img->mprr_2[DC_PRED][j+9] = s0;
      img->mprr_2[DC_PRED][j+10] = s0;		img->mprr_2[DC_PRED][j+11] = s0;
	  img->mprr_2[DC_PRED][j+12] = s0;		img->mprr_2[DC_PRED][j+13] = s0;
      img->mprr_2[DC_PRED][j+14] = s0;		img->mprr_2[DC_PRED][j+15] = s0;
  }
  *tot_intra_sad = IntraMB_Sad(img,imgY_org+img_offset,img->mprr_2[DC_PRED]);
  *imode = DC_PRED_16;

  ///////////////////////////////
  // make horiz and vert prediction
  ///////////////////////////////

  for (i=0; i < 256; i+=16)
  {
    img->mprr_2[VERT_PRED][i]	  = s1;
    img->mprr_2[VERT_PRED][1+i]  = s2;
    img->mprr_2[VERT_PRED][2+i]  = s3;
    img->mprr_2[VERT_PRED][3+i]  = s4;
	img->mprr_2[VERT_PRED][4+i]  = s5;
    img->mprr_2[VERT_PRED][5+i]  = s6;
    img->mprr_2[VERT_PRED][6+i]  = s7;
    img->mprr_2[VERT_PRED][7+i] = s8;
	img->mprr_2[VERT_PRED][8+i] = s9;
    img->mprr_2[VERT_PRED][9+i] = s10;
    img->mprr_2[VERT_PRED][10+i] = s11;
    img->mprr_2[VERT_PRED][11+i] = s12;
	img->mprr_2[VERT_PRED][12+i] = s13;
    img->mprr_2[VERT_PRED][13+i] = s14;
    img->mprr_2[VERT_PRED][14+i] = s15;
    img->mprr_2[VERT_PRED][15+i] = s16;
  } 
  current_intra_sad = IntraMB_Sad(img,imgY_org+img_offset,img->mprr_2[VERT_PRED]);
  if( current_intra_sad <= (*tot_intra_sad))
  {
	  *tot_intra_sad = current_intra_sad;
	  *imode = VERT_PRED_16;
  }
  return *tot_intra_sad; 
}

int intrapred_luma_noright(struct img_par *img,int img_x,int img_y,int *tot_intra_sad,int block_num)
{
  int i,j,s0;
  int pa,pb,pc,pd,pe,pf,pg,ph,pi,pj,pk,pl,px;
  int pic_block_x=img_x>>2;
  int pic_block_y=img_y>>2;
  int block_x=img_x&15;
  int block_y=img_y&15;
  int width=img->width+IMG_PAD_SIZE;
  int best_intra_sad;
  int upMode,leftMode,mostProbableMode,best_ipmode,ipmode;
  double lambda_mode = QP2QUANT[max(0,img->qp-SHIFT_QP)];
  int nonzero;
  int img_offset = img_y*width+img_x;
  int temp = img_offset-width;
  int current_intra_sad;

  pa=imgY[temp];
  pb=imgY[temp+1];
  pc=imgY[temp+2];
  pd=imgY[temp+3];

  pe=pf=pg=ph=pd;
    
  px=imgY[temp-1]; temp+=width;
  pi=imgY[temp-1]; temp+=width;
  pj=imgY[temp-1]; temp+=width;
  pk=imgY[temp-1]; temp+=width;
  pl=imgY[temp-1];
  
  
  ///////////////////////////////
  // make DC prediction
  ///////////////////////////////
 
  s0 = (pa + pb + pc + pd + pi + pj + pk + pl + 4)>>3;
  for (j=0; j < BLOCK_SIZE; j++)
  {
  	  i=j<<2;
      img->mprr[DC_PRED][i] = s0;
      img->mprr[DC_PRED][i+1] = s0;
      img->mprr[DC_PRED][i+2] = s0;
      img->mprr[DC_PRED][i+3] = s0;
  }

⌨️ 快捷键说明

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