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

📄 image.c

📁 H.264视频编码器(ITU的264编码参考软件)
💻 C
📖 第 1 页 / 共 5 页
字号:

  for (i = 0; i < 3; i++)
    for (k = 0; k < 2; k++)
      for (l = 0; l < 18; l++)
        img->cofDC[i][k][l] = rdopt->cofDC[i][k][l];

  for (j = 0; j < 4; j++)
    for (i = 0; i < 4; i++)
    {
      enc_picture->ref_idx[LIST_0][img->block_x + i][img->block_y + j] = rdopt->refar[LIST_0][j][i];
      enc_picture->ref_pic_id [LIST_0][img->block_x+i][img->block_y+j] = enc_picture->ref_pic_num[LIST_0 + list_offset][enc_picture->ref_idx[LIST_0][img->block_x+i][img->block_y+j]];
      if (bframe)
      {
        enc_picture->ref_idx[LIST_1][img->block_x + i][img->block_y + j] = rdopt->refar[LIST_1][j][i];
        enc_picture->ref_pic_id [LIST_1][img->block_x+i][img->block_y+j] = enc_picture->ref_pic_num[LIST_1 + list_offset][enc_picture->ref_idx[LIST_1][img->block_x+i][img->block_y+j]];
      }
    }
    
    //===== reconstruction values =====
  for (j = 0; j < 16; j++)
    for (i = 0; i < 16; i++)
    {
      enc_picture->imgY[img->pix_y + j][img->pix_x + i] = rdopt->rec_mbY[j][i];
    }
      
     
    if (img->yuv_format != YUV400)
    {
      for (j = 0; j < img->mb_cr_size_y; j++)
        for (i = 0; i < img->mb_cr_size_x; i++)
        {
          enc_picture->imgUV[0][img->pix_c_y + j][img->pix_c_x + i] = rdopt->rec_mbU[j][i];
          enc_picture->imgUV[1][img->pix_c_y + j][img->pix_c_x + i] = rdopt->rec_mbV[j][i];
        }
    }

  for (i = 0; i < 4; i++)
  {
    currMB->b8mode[i] = rdopt->b8mode[i];
    currMB->b8pdir[i] = rdopt->b8pdir[i];
  }

  currMB->luma_transform_size_8x8_flag = rdopt->luma_transform_size_8x8_flag;
//  currMB->NoMbPartLessThan8x8Flag  = rdopt->NoMbPartLessThan8x8Flag;  //DEL-VG-29072004
  
  //==== intra prediction modes ====
  if (mode == P8x8)
  {
    for (k = 0, j = img->block_y; j < img->block_y + 4; j++)
      for (i = img->block_x; i < img->block_x + 4; i++, k++)
      {
        img->ipredmode[i][j]        = rdopt->ipredmode[i][j];
        currMB->intra_pred_modes[k] = rdopt->intra_pred_modes[k];
      }
  }
  else if (mode != I4MB && mode != I8MB)
  {
    for (k = 0, j = img->block_y; j < img->block_y + 4; j++)
      for (     i = img->block_x; i < img->block_x + 4; i++, k++)
      {
        img->ipredmode[i][j]        = DC_PRED;
        currMB->intra_pred_modes[k] = DC_PRED;
      }
  }
  else if (mode == I4MB || mode == I8MB)
  {
    for (k = 0, j = img->block_y; j < img->block_y + 4; j++)
      for (     i = img->block_x; i < img->block_x + 4; i++, k++)
      {
        img->ipredmode[i][j]        = rdopt->ipredmode[i][j];
        currMB->intra_pred_modes[k] = rdopt->intra_pred_modes[k];
        
      }
      
  }

  if (img->MbaffFrameFlag)
  {
    // motion vectors
    copy_motion_vectors_MB ();
    
    
    if (!IS_INTRA(currMB))
    {
      for (j = 0; j < 4; j++)
        for (i = 0; i < 4; i++)
        {
          b8mode = currMB->b8mode[i/2+2*(j/2)];
          b8pdir = currMB->b8pdir[i/2+2*(j/2)];

          if (b8pdir!=1)
          {
            enc_picture->mv[LIST_0][i+img->block_x][j+img->block_y][0] = rdopt->all_mv[i][j][LIST_0][rdopt->refar[LIST_0][j][i]][b8mode][0];
            enc_picture->mv[LIST_0][i+img->block_x][j+img->block_y][1] = rdopt->all_mv[i][j][LIST_0][rdopt->refar[LIST_0][j][i]][b8mode][1];
          }
          else
          {
            enc_picture->mv[LIST_0][i+img->block_x][j+img->block_y][0] = 0;
            enc_picture->mv[LIST_0][i+img->block_x][j+img->block_y][1] = 0;
          }
          if (bframe)
          {
            if (b8pdir!=0)
            {
              enc_picture->mv[LIST_1][i+img->block_x][j+img->block_y][0] = rdopt->all_mv[i][j][LIST_1][rdopt->refar[LIST_1][j][i]][b8mode][0];
              enc_picture->mv[LIST_1][i+img->block_x][j+img->block_y][1] = rdopt->all_mv[i][j][LIST_1][rdopt->refar[LIST_1][j][i]][b8mode][1];
            }
            else
            {
              enc_picture->mv[LIST_1][i+img->block_x][j+img->block_y][0] = 0;
              enc_picture->mv[LIST_1][i+img->block_x][j+img->block_y][1] = 0;
            }
          }
        }
    }
    else
    {
      for (j = 0; j < 4; j++)
        for (i = 0; i < 4; i++)
        {
          enc_picture->mv[LIST_0][i+img->block_x][j+img->block_y][0] = 0;
          enc_picture->mv[LIST_0][i+img->block_x][j+img->block_y][1] = 0;
          
          if (bframe)
          {
            enc_picture->mv[LIST_1][i+img->block_x][j+img->block_y][0] = 0;
            enc_picture->mv[LIST_1][i+img->block_x][j+img->block_y][1] = 0;
          }
        }
    }
  }
  
}                             // end of copy_rdopt_data
  
static void copy_motion_vectors_MB ()
{
  int i,j,k,l;

  for (i = 0; i < 4; i++)
  {
    for (j = 0; j < 4; j++)
    {
      for (k = 0; k < img->max_num_references; k++)
      {
        for (l = 0; l < 9; l++)
        {
          img->all_mv[i][j][LIST_0][k][l][0] = rdopt->all_mv[i][j][LIST_0][k][l][0];
          img->all_mv[i][j][LIST_0][k][l][1] = rdopt->all_mv[i][j][LIST_0][k][l][1];

          img->all_mv[i][j][LIST_1][k][l][0] = rdopt->all_mv[i][j][LIST_1][k][l][0];
          img->all_mv[i][j][LIST_1][k][l][1] = rdopt->all_mv[i][j][LIST_1][k][l][1];

          img->pred_mv[i][j][LIST_0][k][l][0] = rdopt->pred_mv[i][j][LIST_0][k][l][0];
          img->pred_mv[i][j][LIST_0][k][l][1] = rdopt->pred_mv[i][j][LIST_0][k][l][1];
          
          img->pred_mv[i][j][LIST_1][k][l][0] = rdopt->pred_mv[i][j][LIST_1][k][l][0];
          img->pred_mv[i][j][LIST_1][k][l][1] = rdopt->pred_mv[i][j][LIST_1][k][l][1];
          
        }
      }
    }
  }
}
  

static void ReportNALNonVLCBits(int tmp_time, int me_time)
{
  //! Need to add type (i.e. SPS, PPS, SEI etc).
    printf ("%04d(NVB)%8d \n", frame_no, stats->bit_ctr_parametersets_n);

}
static void ReportFirstframe(int tmp_time,int me_time)
{
  //Rate control
  int bits;
  printf ("%04d(IDR)%8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n,0,
    img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, me_time,
    img->fld_flag ? "FLD" : "FRM", intras);

  //Rate control
  if(input->RCEnable)
  {
    if((!input->PicInterlace)&&(!input->MbInterlace))
        bits = stats->bit_ctr-stats->bit_ctr_n; // used for rate control update 
    else
    {
      bits = stats->bit_ctr - Iprev_bits; // used for rate control update 
      Iprev_bits = stats->bit_ctr;
    }
  }

  stats->bitr0 = stats->bitr;
  stats->bit_ctr_0 = stats->bit_ctr;
  stats->bit_ctr = 0;
}


static void ReportIntra(int tmp_time, int me_time)
{
	
  if (img->currentPicture->idr_flag == 1)
    printf ("%04d(IDR)%8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n, 0,
    img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, me_time,
    img->fld_flag ? "FLD" : "FRM", intras); 
  else
    printf ("%04d(I)  %8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n, 0,
    img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, me_time,
    img->fld_flag ? "FLD" : "FRM", intras);

}

static void ReportSP(int tmp_time, int me_time)
{
  printf ("%04d(SP) %8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n, active_pps->weighted_pred_flag, img->qp, snr->snr_y,
    snr->snr_u, snr->snr_v, tmp_time, me_time,
          img->fld_flag ? "FLD" : "FRM", intras);
}

static void ReportBS(int tmp_time, int me_time)
{
  printf ("%04d(BS) %8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d %1d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n, active_pps->weighted_bipred_idc, img->qp, snr->snr_y,
    snr->snr_u, snr->snr_v, tmp_time, me_time,
    img->fld_flag ? "FLD" : "FRM", intras,img->direct_spatial_mv_pred_flag);
}

static void ReportB(int tmp_time, int me_time)
{
    printf ("%04d(B)  %8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d %1d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n, active_pps->weighted_bipred_idc,img->qp,
    snr->snr_y, snr->snr_u, snr->snr_v, tmp_time,me_time,
    img->fld_flag ? "FLD" : "FRM",intras,img->direct_spatial_mv_pred_flag);
}


static void ReportP(int tmp_time, int me_time)
{            
    printf ("%04d(P)  %8d %1d %2d %7.3f %7.3f %7.3f  %7d   %5d     %3s   %3d\n",
    frame_no, stats->bit_ctr - stats->bit_ctr_n, active_pps->weighted_pred_flag, img->qp, snr->snr_y,
    snr->snr_u, snr->snr_v, tmp_time, me_time,
          img->fld_flag ? "FLD" : "FRM", intras);

}

/*!
 ************************************************************************
 * \brief
 *    Copies contents of a Sourceframe structure into the old-style
 *    variables imgY_org_frm and imgUV_org_frm.  No other side effects
 * \param sf
 *    the source frame the frame is to be taken from
 ************************************************************************
 */

static void CopyFrameToOldImgOrgVariables (Sourceframe *sf)
{
  int x, y;
  
  for (y=0; y<sf->y_framesize; y++)
  for (x=0; x<sf->x_size; x++)
    imgY_org_frm [y][x] = sf->yf[y*sf->x_size+x];

  if (img->yuv_format != YUV400)
  {
    for (y=0; y<sf->y_framesize_cr; y++)
      for (x=0; x<sf->x_size_cr; x++)
      {
        imgUV_org_frm[0][y][x] = sf->uf[y*sf->x_size_cr+x];
        imgUV_org_frm[1][y][x] = sf->vf[y*sf->x_size_cr+x];
      }
  }
}

/*!
 ************************************************************************
 * \brief
 *    Copies contents of a Sourceframe structure into the old-style
 *    variables imgY_org_top and imgUV_org_top.  No other side effects
 * \param sf
 *    the source frame the field is to be taken from
 ************************************************************************
 */

static void CopyTopFieldToOldImgOrgVariables (Sourceframe *sf)
{
  int x, y;

  for (y=0; y<sf->y_fieldsize; y++)
  for (x=0; x<sf->x_size; x++)
    imgY_org_top [y][x] = sf->yt[y*sf->x_size+x];

  if (img->yuv_format != YUV400)
  {
    for (y=0; y<sf->y_fieldsize_cr; y++)
      for (x=0;x<sf->x_size_cr; x++)
      {
        imgUV_org_top[0][y][x] = sf->ut[y*sf->x_size_cr+x];
        imgUV_org_top[1][y][x] = sf->vt[y*sf->x_size_cr+x];
      }
  }
}
/*!
 ************************************************************************
 * \brief
 *    Copies contents of a Sourceframe structure into the old-style
 *    variables imgY_org_bot and imgUV_org_bot.  No other side effects
 * \param sf
 *    the source frame the field is to be taken from
 ************************************************************************
 */

static void CopyBottomFieldToOldImgOrgVariables (Sourceframe *sf)
{
  int x, y;
  
  for (y=0; y<sf->y_fieldsize; y++)
  for (x=0; x<sf->x_size; x++)
    imgY_org_bot [y][x] = sf->yb[y*sf->x_size+x];

  if (img->yuv_format != YUV400)
  {
    for (y=0; y<sf->y_fieldsize_cr; y++)
      for (x=0;x<sf->x_size_cr; x++)
      {
        imgUV_org_bot[0][y][x] = sf->ub[y*sf->x_size_cr+x];
        imgUV_org_bot[1][y][x] = sf->vb[y*sf->x_size_cr+x];
      }
  }
}


/*!
************************************************************************
* \brief
*    Allocates Sourceframe structure
* \param xs
*    horizontal size of frame in pixels
* \param ys
*    vertical size of frame in pixels, must be divisible by 2
* \param xs_cr
*    horizontal chroma size of frame in pixels
* \param ys_cr
*    vertical chroma size of frame in pixels, must be divisible by 2
* \return
*    pointer to initialized source frame structure
************************************************************************
*/

static Sourceframe *AllocSourceframe (int xs, int ys, int xs_cr, int ys_cr)
{
  Sourceframe *sf = NULL;
  const unsigned int bytes_y = xs*ys*sizeof(imgpel);
  const unsigned int bytes_uv = (xs_cr*ys_cr)*sizeof(imgpel);

  if ((sf = calloc (1, sizeof (Sourceframe))) == NULL) no_mem_exit ("ReadOneFrame: sf");
  if (sf->yf == NULL) if ((sf->yf = calloc (1, bytes_y)) == NULL) no_mem_exit ("ReadOneFrame: sf->yf");
  if (sf->yt == NULL) if ((sf->yt = calloc (1, bytes_y/2)) == NULL) no_mem_exit ("ReadOneFrame: sf->yt");
  if (sf->yb == NULL) if ((sf->yb = calloc (1, bytes_y/2)) == NULL) no_mem_exit ("ReadOneFrame: sf->yb");
  if (img->yuv_format != YUV400)
  {
    if (sf->uf == NULL) if ((sf->uf = calloc (1, bytes_uv)) == NULL) no_mem_exit ("ReadOneFrame: sf->uf");
    if (sf->ut == NULL) if ((sf->ut = calloc (1, bytes_uv/2)) == NULL) no_mem_exit ("ReadOneFrame: sf->ut");
    if (sf->ub == NULL) if ((sf->ub = calloc (1, bytes_uv/2)) == NULL) no_mem_exit ("ReadOneFrame: sf->ub");
    if (sf->vf == NULL) if ((sf->vf = calloc (1, bytes_uv)) == NULL) no_mem_exit ("ReadOneFrame: sf->vf");
    if (sf->vt == NULL) if ((sf->vt = calloc (1, bytes_uv/2)) == NULL) no_mem_exit ("ReadOneFrame: sf->vt");
    if (sf->vb == NULL) if ((sf->vb = calloc (1, bytes_uv/2)) == NULL) no_mem_exit ("ReadOneFrame: sf->vb");
  }
  sf->x_size = xs;
  sf->x_size_cr = xs_cr;  //ADD-VG-15052004
  sf->y_framesize = ys;
  sf->y_framesize_cr = ys_cr;
  sf->y_fieldsize = ys/2;
  sf->y_fieldsize_cr = ys_cr/2;
  
  return sf;
}



/*!
 ************************************************************************
 * \brief
 *    Frees Sourceframe structure
 * \param sf
 *    pointer to Sourceframe previoously allocated with ALlocSourceframe()
 * \return
 *    none
 ************************************************************************
 */

static void FreeSourceframe (Sourceframe *sf)
{
  if (sf!=NULL) 
  {
    if (sf->yf != NULL) free (sf->yf);
    if (sf->yt != NULL) free (sf->yt);
    if (sf->yb != NULL) free (sf->yb);
    if (img->yuv_format != YUV400)
    {
      if (sf->uf != NULL) free (sf->uf);
      if (sf->ut != NULL) free (sf->ut);
      if (sf->ub != NULL) free (sf->ub);
      if (sf->vf != NULL) free (sf->vf);
      if (sf->vt != NULL) free (sf->vt);
      if (sf->vb != NULL) free (sf->vb);
    }
    free (sf);
  }
}

/*!
 ****************************

⌨️ 快捷键说明

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