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

📄 image.c

📁 包含FRExt部分的JM源码
💻 C
📖 第 1 页 / 共 5 页
字号:
      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, stat->bit_ctr_parametersets_n);

}
static void ReportFirstframe(int tmp_time,int me_time)
{
  //Rate control
  int bits;
  printf ("%04d(IDR)%8d %1d %2d %7.4f %7.4f %7.4f  %7d   %5d     %3s \n",
    frame_no, stat->bit_ctr - stat->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 = stat->bit_ctr-stat->bit_ctr_n; // used for rate control update 
    else
    {
      bits = stat->bit_ctr - Iprev_bits; // used for rate control update 
      Iprev_bits = stat->bit_ctr;
    }
  }

  stat->bitr0 = stat->bitr;
  stat->bit_ctr_0 = stat->bit_ctr;
  stat->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.4f %7.4f %7.4f  %7d   %5d     %3s \n",
    frame_no, stat->bit_ctr - stat->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.4f %7.4f %7.4f  %7d   %5d     %3s \n",
    frame_no, stat->bit_ctr - stat->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.4f %7.4f %7.4f  %7d   %5d     %3s   %3d\n",
    frame_no, stat->bit_ctr - stat->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.4f %7.4f %7.4f  %7d   %5d     %3s   %3d %1d\n",
    frame_no, stat->bit_ctr - stat->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_type);
}

static void ReportB(int tmp_time, int me_time)
{
    printf ("%04d(B)  %8d %1d %2d %7.4f %7.4f %7.4f  %7d   %5d     %3s   %3d %1d\n",
    frame_no, stat->bit_ctr - stat->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_type);
}


static void ReportP(int tmp_time, int me_time)
{            
    printf ("%04d(P)  %8d %1d %2d %7.4f %7.4f %7.4f  %7d   %5d     %3s   %3d\n",
    frame_no, stat->bit_ctr - stat->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];
  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];
  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];
    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
* \return
*    pointer to initialized source frame structure
************************************************************************
*/

static Sourceframe *AllocSourceframeNew (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); //CHA-VG-15052004

  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 (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 (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);
  }
}

/*!
 ************************************************************************
 * \brief
 *    Calculates the absolute frame number in the source file out
 *    of various variables in img-> and input->
 * \return
 *    frame number in the file to be read
 * \par side effects
 *    global variable frame_no updated -- dunno, for what this one is necessary
 ************************************************************************
 */
static int CalculateFrameNumber()
{
  if (img->type == B_SLICE)
    frame_no = start_tr_in_this_IGOP + (IMG_NUMBER - 1) * (input->jumpd + 1) + img->b_interval * img->b_frame_to_code;
  else
    {
      frame_no = start_tr_in_this_IGOP + IMG_NUMBER * (input->jumpd + 1);
#ifdef _ADAPT_LAST_GROUP_
      if (input->last_frame && img->number + 1 == input->no_frames)
        frame_no = input->last_frame;
#endif
    }
  return frame_no;
}


/*!
 ************************************************************************
 * \brief
 *    Generate Field Component from Frame Components by copying
 * \param src
 *    source frame component
 * \param top
 *    destination top field component
 * \param bot
 *    destination bottom field component
 * \param xs
 *    horizontal size of frame in pixels
 * \param ys
 *    vertical size of frame in pixels, must be divisible by 2
 ************************************************************************
 */
static void GenerateFieldComponent (imgpel *src, imgpel *top, imgpel *bot, int xs, int ys)
{
  int fieldline;
  assert (ys % 2 == 0);

  for (fieldline = 0; fieldline < ys/2; fieldline++)
  {
    memcpy (&top[xs * fieldline], &src[xs * (fieldline * 2 + 0)], xs*sizeof(imgpel));
    memcpy (&bot[xs * fieldli

⌨️ 快捷键说明

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