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

📄 image.c

📁 我们自己做的JM76向ARM平台移植的ADS版本
💻 C
📖 第 1 页 / 共 5 页
字号:
  }

  //==== 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)
  {
    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)
  {
    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 ReportFirstframe(int tmp_time)
{
  //Rate control
  int bits;

  printf ("%04d(I)  %8d %3d %7.4f %7.4f %7.4f  %5d       %3s \n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n,
          img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time,
          img->fld_flag ? "FLD" : "FRM");

  //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)
{
  if (img->currentPicture->idr_flag == 1)
    printf ("%04d(IDR)%8d %3d %7.4f %7.4f %7.4f  %5d       %3s \n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n,
          img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time,
          img->fld_flag ? "FLD" : "FRM"); 
  else
    printf ("%04d(I)  %8d %3d %7.4f %7.4f %7.4f  %5d       %3s \n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n,
          img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time,
          img->fld_flag ? "FLD" : "FRM");
}

static void ReportSP(int tmp_time)
{
  printf ("%04d(SP) %8d %3d %7.4f %7.4f %7.4f  %5d       %3s    %4d\n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n, img->qp, snr->snr_y,
          snr->snr_u, snr->snr_v, tmp_time,
          img->fld_flag ? "FLD" : "FRM", intras);
}

static void ReportBS(int tmp_time)
{
  printf ("%04d(BS) %8d %3d %7.4f %7.4f %7.4f  %5d       %3s    %4d\n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n, img->qp, snr->snr_y,
          snr->snr_u, snr->snr_v, tmp_time,
          img->fld_flag ? "FLD" : "FRM", intras);
}

static void ReportB(int tmp_time)
{
  printf ("%04d(B)  %8d %3d %7.4f %7.4f %7.4f  %5d       %3s \n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n, img->qp,
          snr->snr_y, snr->snr_u, snr->snr_v, tmp_time,
          img->fld_flag ? "FLD" : "FRM");
}


static void ReportP(int tmp_time)
{            
  printf ("%04d(P)  %8d %3d %7.4f %7.4f %7.4f  %5d       %3s    %4d\n",
          frame_no, stat->bit_ctr - stat->bit_ctr_n, img->qp, snr->snr_y,
          snr->snr_u, snr->snr_v, tmp_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
 * \para
 *    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/2; y++)
    for (x=0; x<sf->x_size/2; x++)
    {
      imgUV_org_frm[0][y][x] = sf->uf[y*sf->x_size/2+x];
      imgUV_org_frm[1][y][x] = sf->vf[y*sf->x_size/2+x];
    }
}

/*!
 ************************************************************************
 * \brief
 *    Copies contents of a Sourceframe structure into the old-style
 *    variables imgY_org_top and imgUV_org_top.  No other side effects
 * \para
 *    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/2; y++)
    for (x=0;x<sf->x_size/2; x++)
    {
      imgUV_org_top[0][y][x] = sf->ut[y*sf->x_size/2+x];
      imgUV_org_top[1][y][x] = sf->vt[y*sf->x_size/2+x];
    }
}
/*!
 ************************************************************************
 * \brief
 *    Copies contents of a Sourceframe structure into the old-style
 *    variables imgY_org_bot and imgUV_org_bot.  No other side effects
 * \para
 *    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/2; y++)
    for (x=0;x<sf->x_size/2; x++)
    {
      imgUV_org_bot[0][y][x] = sf->ub[y*sf->x_size/2+x];
      imgUV_org_bot[1][y][x] = sf->vb[y*sf->x_size/2+x];
    }
}


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

static Sourceframe *AllocSourceframe (int xs, int ys)
{
  Sourceframe *sf = NULL;
  const unsigned int bytes_y = xs*ys;
  const unsigned int bytes_uv = (xs*ys)/4;

  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->y_framesize = ys;
  sf->y_fieldsize = ys/2;

  return sf;
}



/*!
 ************************************************************************
 * \brief
 *    Frees Sourceframe structure
 * \para
 *    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
 * \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
 * \para
 *    src: source frame component
 *    top: destination top field component
 *    bot: destination bottom field component
 *    xs: horizontal size of frame in pixels
 *    ys: vertical size of frame in pixels, must be divisible by 2
 ************************************************************************
 */
static void GenerateFieldComponent (char *src, char *top, char *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);
    memcpy (&bot[xs * fieldline], &src[xs * (fieldline * 2 + 1)], xs);
  }
}


/*!
 ************************************************************************
 * \brief
 *    Reads one new frame from file
 * \para
 *    FrameNoInFile: Frame number in the source file
 *    HeaderSize: Number of bytes in the source file to be skipped
 *    xs: horizontal size of frame in pixels, must be divisible by 16
 *    ys: vertical size of frame in pixels, must be divisible by 16 or
 *        32 in case of MB-adaptive frame/field coding
 *    sf: Sourceframe structure to which the frame is written
 ************************************************************************
 */
static void ReadOneFrame (int FrameNoInFile, int HeaderSize, int xs, int ys, Sourceframe *sf)
{
//  int i;

//  const unsigne

⌨️ 快捷键说明

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