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

📄 rdopt.c

📁 h.264 影像壓縮 必須在 .net 的環境 下操作
💻 C
📖 第 1 页 / 共 5 页
字号:
    {
      for (j = img->block_y; j < img->block_y + 4; j++)
        for (i = img->block_x; i < img->block_x + 4;i++)
        {
          cur_ref = (int) enc_picture->ref_idx[clist][j][i];
          enc_picture->ref_pic_id [clist][j][i] = (cur_ref>=0
            ? enc_picture->ref_pic_num[clist + currMB->list_offset][cur_ref]
            : -1);
        }
    }
  }
  else
  {
    for (j = img->block_y; j < img->block_y + 4; j++)
      for (i = img->block_x; i < img->block_x + 4;i++)
      {
        cur_ref = (int) enc_picture->ref_idx[LIST_0][j][i];
        enc_picture->ref_pic_id [LIST_0][j][i] = (cur_ref>=0
          ? enc_picture->ref_pic_num[LIST_0 + currMB->list_offset][cur_ref]
          : -1);
      }
  }

#undef IS_FW
#undef IS_BW
}


/*!
 *************************************************************************************
 * \brief
 *    Intra 16x16 mode decision
 *************************************************************************************
 */
void Intra16x16_Mode_Decision (Macroblock* currMB, int* i16mode)
{
  /* generate intra prediction samples for all 4 16x16 modes */
  intrapred_16x16 (currMB, PLANE_Y);
  if ((active_sps->chroma_format_idc == YUV444)&&(IS_INDEPENDENT(input)==0))
  {
    select_plane(PLANE_U);
    intrapred_16x16 (currMB, PLANE_U);
    select_plane(PLANE_V);
    intrapred_16x16 (currMB, PLANE_V);
    select_plane(PLANE_Y);
  }
  find_sad_16x16 (currMB, i16mode);   /* get best new intra mode */
  
  currMB->cbp = dct_16x16 (currMB, PLANE_Y, *i16mode);
  if ((active_sps->chroma_format_idc == YUV444)&&(IS_INDEPENDENT(input)==0))
  {
    select_plane(PLANE_U);
    cmp_cbp[1] = dct_16x16 (currMB, PLANE_U, *i16mode);
    select_plane(PLANE_V);
    cmp_cbp[2] = dct_16x16 (currMB, PLANE_V, *i16mode);
    select_plane(PLANE_Y);
    currMB->cbp |= cmp_cbp[1];
    currMB->cbp |= cmp_cbp[2];
    cmp_cbp[1] = currMB->cbp;
    cmp_cbp[2] = currMB->cbp;
  }
}



/*!
 *************************************************************************************
 * \brief
 *    Sets Coefficients and reconstruction for an 8x8 block
 *************************************************************************************
 */
void SetCoeffAndReconstruction8x8 (Macroblock* currMB)
{
  int block, k, j, i, uv;
  int cur_ref;

  //============= MIXED TRANSFORM SIZES FOR 8x8 PARTITION ==============
  //--------------------------------------------------------------------
  int l;
  int bframe = img->type==B_SLICE;

  if (currMB->luma_transform_size_8x8_flag)
  {

    //============= set mode and ref. frames ==============
    for(i = 0;i<4;i++)
    {
      currMB->b8mode[i]   = tr8x8.part8x8mode[i];
      currMB->b8pdir[i]   = tr8x8.part8x8pdir[i];
    }

    if (bframe)
    {
      for (j = 0;j<4;j++)
        for (i = 0;i<4;i++)
        {
          k = 2*(j >> 1)+(i >> 1);
          l = 2*(j & 0x01)+(i & 0x01);
          enc_picture->ref_idx[LIST_0][img->block_y+j][img->block_x+i] = ((currMB->b8pdir[k] & 0x01) == 0) ? tr8x8.part8x8l0ref[k] : - 1;
          enc_picture->ref_idx[LIST_1][img->block_y+j][img->block_x+i] = (currMB->b8pdir[k] > 0) ? tr8x8.part8x8l1ref[k] : - 1;
        }
    }
    else
    {
      for (j = 0;j<4;j++)
        for (i = 0;i<4;i++)
        {
          k = 2*(j >> 1)+(i >> 1);
          l = 2*(j & 0x01)+(i & 0x01);
          enc_picture->ref_idx[LIST_0][img->block_y+j][img->block_x+i] = tr8x8.part8x8l0ref[k];
        }
    }


    for (j = img->block_y;j<img->block_y + BLOCK_MULTIPLE;j++)
    {
      for (i = img->block_x;i<img->block_x + BLOCK_MULTIPLE;i++)
      {
        cur_ref = (int) enc_picture->ref_idx[LIST_0][j][i];

        enc_picture->ref_pic_id [LIST_0][j][i] =(cur_ref>=0
          ? enc_picture->ref_pic_num[LIST_0 + currMB->list_offset][cur_ref]
          : -1);
      }
    }

    if (bframe)
    {
      for (j = img->block_y; j < img->block_y + BLOCK_MULTIPLE; j++)
      {
        for (i = img->block_x;i<img->block_x + BLOCK_MULTIPLE;i++)
        {
          cur_ref = (int) enc_picture->ref_idx[LIST_1][j][i];

          enc_picture->ref_pic_id [LIST_1][j][i] = (cur_ref>=0
            ? enc_picture->ref_pic_num[LIST_1 + currMB->list_offset][cur_ref]
            : -1);
        }

      }
    }

    //====== set the mv's for 8x8 partition with transform size 8x8 ======
    //save the mv data for 4x4 transform

    StoreMV8x8(1);
    //set new mv data for 8x8 transform
    RestoreMV8x8(0);

    //============= get pre-calculated data ==============
    //restore coefficients from 8x8 transform

    for (block = 0; block<4; block++)
    {
      for (k = 0; k<4; k++)
        for (j = 0; j<2; j++)
          memcpy (img->cofAC[block][k][j],cofAC8x8ts[0][block][k][j], 65 * sizeof(int));
    }
    
    if( img->yuv_format == YUV444 && !IS_INDEPENDENT(input) )
    {
      for (uv=0; uv<2; uv++)
      {
        for (block = 0; block<4; block++)
        {
          for (k = 0; k<4; k++)
            for (j = 0; j<2; j++)
              memcpy (img->cofAC[4+block+uv*4][k][j],cofAC8x8ts[uv][block][k][j], 65 * sizeof(int));
        }
      }
    }
    //restore reconstruction
    if (cnt_nonz8_8x8ts <= _LUMA_8x8_COEFF_COST_ &&
      ((currMB->qp_scaled[0])!=0 || img->lossless_qpprime_flag==0) &&
      (img->type!=SP_SLICE))// modif ES added last condition (we probably never go there so is the next modification useful ? check)
    {
      currMB->cbp     = 0;
      currMB->cbp_blk = 0;
      for (j = 0; j < MB_BLOCK_SIZE; j++)
      {
        memcpy(&enc_picture->imgY[img->pix_y+j][img->pix_x], tr8x8.mpr8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
        if(img->type==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator ))
          memcpy(&lrec[img->pix_y+j][img->pix_x],tr8x8.lrec[j], MB_BLOCK_SIZE * sizeof(int));
      }
      for(block=0;block<4;block++)
      {
        for( i = 0; i < 4; i++ )
          for( j = 0; j < 2; j++ )
            memset( img->cofAC[block][i][j], 0, 65 * sizeof(int));
      }
      if( img->yuv_format==YUV444 && !IS_INDEPENDENT(input) )
      {
        for (j = 0; j < MB_BLOCK_SIZE; j++)
        {
          memcpy(&enc_picture->imgUV[0][img->pix_y+j][img->pix_x], tr8x8.mpr8x8CbCr[0][j], MB_BLOCK_SIZE * sizeof(imgpel));
          memcpy(&enc_picture->imgUV[1][img->pix_y+j][img->pix_x], tr8x8.mpr8x8CbCr[1][j], MB_BLOCK_SIZE * sizeof(imgpel));
        }
        for (uv=0; uv<2; uv++)
        {
          for (block = 0; block<4; block++)
          {
            for (k = 0; k<4; k++)
              for (j = 0; j<2; j++)
                memset( img->cofAC[4+block+uv*4][k][j], 0, 65 * sizeof(int));
          }
        }
      }
    }
    else
    {
      currMB->cbp     = cbp8_8x8ts;
      currMB->cbp_blk = cbp_blk8_8x8ts;
      for (j = 0; j < MB_BLOCK_SIZE; j++)
      {
        memcpy (&enc_picture->imgY[img->pix_y+j][img->pix_x],tr8x8.rec_mbY8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
        if(img->type==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator))
          memcpy (&lrec[img->pix_y+j][img->pix_x],tr8x8.lrec[j], MB_BLOCK_SIZE * sizeof(int));
      }
      
      if( img->yuv_format == YUV444 && !IS_INDEPENDENT(input) ) 
      {
        cmp_cbp[1] = cmp_cbp[2] = cbp8_8x8ts;
        for (j = 0; j < MB_BLOCK_SIZE; j++)
        {
          memcpy (&enc_picture->imgUV[0][img->pix_y+j][img->pix_x],tr8x8.rec_mbU8x8[j], MB_BLOCK_SIZE * sizeof(imgpel)); 
          memcpy (&enc_picture->imgUV[1][img->pix_y+j][img->pix_x],tr8x8.rec_mbV8x8[j], MB_BLOCK_SIZE * sizeof(imgpel)); 
        }
      }
    }
  }
  else
  {
    //============= get pre-calculated data ==============
    //---------------------------------------------------
    //--- restore coefficients ---
    for (block = 0; block<4+img->num_blk8x8_uv; block++)
    {
      for (k = 0; k<4; k++)
        for (j = 0; j<2; j++)
          memcpy (img->cofAC[block][k][j],cofAC8x8[block][k][j], 65 * sizeof(int));
    }
    if( img->yuv_format == YUV444 && !IS_INDEPENDENT(input) ) 
    {
      for (block = 0; block<4; block++)
      {
        for (k = 0; k<4; k++)
        {
          for (j = 0; j<2; j++)
          {
            memcpy (img->cofAC[block+4][k][j],cofAC8x8CbCr[0][block][k][j], 65 * sizeof(int));     
            memcpy (img->cofAC[block+8][k][j],cofAC8x8CbCr[1][block][k][j], 65 * sizeof(int));   
          }
        }
      }
    }

    if (cnt_nonz_8x8<=5 && img->type!=SP_SLICE &&
      ((currMB->qp_scaled[0])!=0 || img->lossless_qpprime_flag==0))
    {
      currMB->cbp     = 0;
      currMB->cbp_blk = 0;
      for (j = 0; j < MB_BLOCK_SIZE; j++)
      {
        memcpy (&enc_picture->imgY[img->pix_y+j][img->pix_x],tr4x4.mpr8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
        if(img->type ==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator))
          memcpy (&lrec[img->pix_y+j][img->pix_x],tr4x4.lrec[j], MB_BLOCK_SIZE * sizeof(int)); // restore coeff. SP frame
      }
      for(block=0;block<4;block++)
      {
        for( i = 0; i < 4; i++ )
          for( j = 0; j < 2; j++ )
            memset( img->cofAC[block][i][j], 0, 65 * sizeof(int));
      }
      if (img->yuv_format ==YUV444 && !IS_INDEPENDENT(input))
      {
        for (j = 0; j < MB_BLOCK_SIZE; j++)
        {
          memcpy (&enc_picture->imgUV[0][img->pix_y+j][img->pix_x],tr4x4.mpr8x8CbCr[0][j], MB_BLOCK_SIZE * sizeof(imgpel));    
          memcpy (&enc_picture->imgUV[1][img->pix_y+j][img->pix_x],tr4x4.mpr8x8CbCr[1][j], MB_BLOCK_SIZE * sizeof(imgpel));  
        }
        for (uv=0; uv<2; uv++)
        {
          for (block = 0; block<4; block++)
          {
            for (k = 0; k<4; k++)
              for (j = 0; j<2; j++)
                memset( img->cofAC[4+block+uv*4][k][j], 0, 65 * sizeof(int));
          }
        }
      }
    }
    else
    {
      currMB->cbp     = cbp8x8;
      currMB->cbp_blk = cbp_blk8x8;
      for (j = 0; j < MB_BLOCK_SIZE; j++)
      {
        memcpy (&enc_picture->imgY[img->pix_y+j][img->pix_x],tr4x4.rec_mbY8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
        if(img->type==SP_SLICE &&(!si_frame_indicator && !sp2_frame_indicator))
          memcpy (&lrec[img->pix_y+j][img->pix_x],tr4x4.lrec[j], MB_BLOCK_SIZE * sizeof(int));
      }
      if( img->yuv_format == YUV444 && !IS_INDEPENDENT(input)) 
      {
        cmp_cbp[1] = cmp_cbp[2] = cbp8x8;
        for (j = 0; j < MB_BLOCK_SIZE; j++)
        {
          memcpy (&enc_picture->imgUV[0][img->pix_y+j][img->pix_x],tr4x4.rec_mbU8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
          memcpy (&enc_picture->imgUV[1][img->pix_y+j][img->pix_x],tr4x4.rec_mbV8x8[j], MB_BLOCK_SIZE * sizeof(imgpel));
        }
      }
    }
  }
}


/*!
 *************************************************************************************
 * \brief
 *    Sets motion vectors for a macroblock
 *************************************************************************************
 */
void SetMotionVectorsMB (Macroblock* currMB, int bframe)
{
  int i, j, k, l, m, mode8, pdir8, ref, by, bx;
  short ******all_mv  = img->all_mv;
  short ******pred_mv = img->pred_mv;
  int  l1_ref;
  int jdiv, jmod;

  if (!bframe)
  {
    for (j = 0; j<4; j++)
    {
      jmod = j & 0x01;
      jdiv = j >>   1;
      by    = img->block_y+j;
      for (i = 0; i<4; i++)
      {
        mode8 = currMB->b8mode[k=2*jdiv+(i>>1)];
        l     = 2*jmod + (i & 0x01);

        bx   = img->block_x+i;

        pdir8 = currMB->b8pdir[k];
        ref    = enc_picture->ref_idx[LIST_0][by][bx];

        if (pdir8>=0)
        {
          enc_picture->mv[LIST_0][by][bx][0] = all_mv [j][i][LIST_0][ ref][mode8][0];
          enc_picture->mv[LIST_0][by][bx][1] = all_mv [j][i][LIST_0][ ref][mode8][1];
        }
        else
        {
          enc_picture->mv[LIST_0][by][bx][0] = 0;
          enc_picture->mv[LIST_0][by][bx][1] = 0;
        }
      }
    }
  }
  else
  {
    for (j = 0; j<4; j++)
    {
      jmod = j & 0x01;
      jdiv = j >>   1;
      by    = img->block_y+j;
      for (i = 0; i<4; i++)
      {
        mode8 = currMB->b8mode[k=2*jdiv+(i>>1)];
        l     = 2*jmod + (i & 0x01);

        bx    = img->block_x+i;

        pdir8 = currMB->b8pdir[k];
        ref    = enc_picture->ref_idx[LIST_0][by][bx];
        l1_ref = enc_picture->ref_idx[LIST_1][by][bx];

        if (currMB->bi_pred_me && (pdir8 == 2) && currMB->mb_type==1)
        {
          all_mv  = currMB->bi_pred_me == 1 ? img->bipred_mv1 : img->bipred_mv2;
          ref = 0;
          l1_ref = 0;
        }

        if (pdir8==-1) // intra
        {
          enc_picture->mv[LIST_0][by][bx][0] = 0;
          enc_picture->mv[LIST_0][by][bx][1] = 0;
        

⌨️ 快捷键说明

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