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

📄 image.c

📁 the newest JM software by h.264 JVT official reference model.
💻 C
📖 第 1 页 / 共 5 页
字号:
        getSubImagesChroma( s );
    }
  }
}

/*!
 ************************************************************************
 * \brief
 *    Upsample 4 times, store them in out4x.  Color is simply copied
 *    for 4:4:4 Independent mode
 *
 * \par Input:
 *    nplane
 *
 ************************************************************************/
void UnifiedOneForthPix_JV (int nplane, StorablePicture *s)
{
  int ypadded_size = s->size_y_padded;
  int xpadded_size = s->size_x_padded;

  if( nplane == 0 )
  {
    // don't upsample twice
    if (s->imgY_sub)
      return;
    // Y component
    get_mem4Dpel (&(s->imgY_sub), 4, 4, ypadded_size, xpadded_size);
    if (NULL == s->imgY_sub)
      no_mem_exit("UnifiedOneForthPix_JV: s->imgY_sub");

    // don't upsample twice
    if (s->imgUV_sub)
      return;
    // Y component
    get_mem5Dpel (&(s->imgUV_sub), 2, 4, 4, ypadded_size, xpadded_size);
    if (NULL == s->imgUV_sub)
      no_mem_exit("UnifiedOneForthPix_JV: s->imgUV_sub");

    s->p_img[0] = s->imgY;
    s->p_img[1] = s->imgUV[0];
    s->p_img[2] = s->imgUV[1];

    s->p_img_sub[0] = s->imgY_sub;
    s->p_img_sub[1] = s->imgUV_sub[0];
    s->p_img_sub[2] = s->imgUV_sub[1];
  }

  // derive the subpixel images for first component
  s->colour_plane_id = nplane;
  s->p_curr_img = s->p_img[nplane];
  s->p_curr_img_sub = s->p_img_sub[nplane];

  getSubImagesLuma ( s );
}



  /*!
 ************************************************************************
 * \brief
 *    Just a placebo
 ************************************************************************
 */
Boolean dummy_slice_too_big (int bits_slice)
{
  return FALSE;
}


static inline void copy_motion_vectors_MB (ImageParameters *img, RD_DATA *rdopt)
{
  memcpy(&img->all_mv [LIST_0][0][0][0][0][0], &rdopt->all_mv [LIST_0][0][0][0][0][0], 2 * img->max_num_references * 9 * 4 * 4 * 2 * sizeof(short));  
}


/*!
***************************************************************************
// For MB level field/frame coding
***************************************************************************
*/
void copy_rdopt_data (Macroblock *currMB, int bot_block)
{
  int i, j;

  int bframe = (img->type == B_SLICE);
  int mode;
  short b8mode, b8pdir;
  int block_y;

  int list_offset = currMB->list_offset;

  mode                = rdopt->mode;
  currMB->mb_type     = rdopt->mb_type;    // copy mb_type
  currMB->cbp         = rdopt->cbp;        // copy cbp
  currMB->cbp_blk     = rdopt->cbp_blk;    // copy cbp_blk
  img->i16offset      = rdopt->i16offset;

  currMB->prev_qp  = rdopt->prev_qp;
  currMB->prev_dqp = rdopt->prev_dqp;
  currMB->prev_cbp = rdopt->prev_cbp;
  currMB->delta_qp = rdopt->delta_qp;
  currMB->qp       = rdopt->qp;
  update_qp (img, currMB);

  currMB->c_ipred_mode = rdopt->c_ipred_mode;

  memcpy(img->cofAC[0][0][0],rdopt->cofAC[0][0][0], (4 + img->num_blk8x8_uv) * 4 * 2 * 65 * sizeof(int));
  memcpy(img->cofDC[0][0],rdopt->cofDC[0][0], 3 * 2 * 18 * sizeof(int));

  for (j = 0; j < BLOCK_MULTIPLE; j++)
  {
    block_y = img->block_y + j;
    memcpy(&enc_picture->motion.ref_idx[LIST_0][block_y][img->block_x], rdopt->refar[LIST_0][j], BLOCK_MULTIPLE * sizeof(char));
    for (i = 0; i < BLOCK_MULTIPLE; i++)
      enc_picture->motion.ref_pic_id [LIST_0][block_y][img->block_x + i] =
      enc_picture->ref_pic_num[LIST_0 + list_offset][(short)enc_picture->motion.ref_idx[LIST_0][block_y][img->block_x+i]];
  }
  if (bframe)
  {
    for (j = 0; j < BLOCK_MULTIPLE; j++)
    {
      block_y = img->block_y + j;
      memcpy(&enc_picture->motion.ref_idx[LIST_1][block_y][img->block_x], rdopt->refar[LIST_1][j], BLOCK_MULTIPLE * sizeof(char));
      for (i = 0; i < BLOCK_MULTIPLE; i++)
        enc_picture->motion.ref_pic_id [LIST_1][block_y][img->block_x + i] =
        enc_picture->ref_pic_num[LIST_1 + list_offset][(short)enc_picture->motion.ref_idx[LIST_1][block_y][img->block_x + i]];
    }
  }

  //===== reconstruction values =====
  for (j = 0; j < MB_BLOCK_SIZE; j++)
    memcpy(&enc_picture->imgY[img->pix_y + j][img->pix_x],rdopt->rec_mbY[j], MB_BLOCK_SIZE * sizeof(imgpel));

  if (img->yuv_format != YUV400)
  {
    for (j = 0; j < img->mb_cr_size_y; j++)
    {
      memcpy(&enc_picture->imgUV[0][img->pix_c_y + j][img->pix_c_x], rdopt->rec_mb_cr[0][j], img->mb_cr_size_x * sizeof(imgpel));
      memcpy(&enc_picture->imgUV[1][img->pix_c_y + j][img->pix_c_x], rdopt->rec_mb_cr[1][j], img->mb_cr_size_x * sizeof(imgpel));
    }
  }

  memcpy(currMB->b8mode, rdopt->b8mode, 4 * sizeof(short));
  memcpy(currMB->b8pdir, rdopt->b8pdir, 4 * sizeof(short));


  currMB->luma_transform_size_8x8_flag = rdopt->luma_transform_size_8x8_flag;

  //==== intra prediction modes ====
  if (mode == P8x8)
  {
    memcpy(currMB->intra_pred_modes,rdopt->intra_pred_modes, MB_BLOCK_PARTITIONS * sizeof(char));
    for (j = img->block_y; j < img->block_y + BLOCK_MULTIPLE; j++)
      memcpy(&img->ipredmode[j][img->block_x],&rdopt->ipredmode[j][img->block_x], BLOCK_MULTIPLE * sizeof(char));
  }
  else if (mode != I4MB && mode != I8MB)
  {
    memset(currMB->intra_pred_modes,DC_PRED, MB_BLOCK_PARTITIONS * sizeof(char));
    for (j = img->block_y; j < img->block_y + BLOCK_MULTIPLE; j++)
      memset(&img->ipredmode[j][img->block_x],DC_PRED, BLOCK_MULTIPLE * sizeof(char));
  }
  else if (mode == I4MB || mode == I8MB)
  {
    memcpy(currMB->intra_pred_modes,rdopt->intra_pred_modes, MB_BLOCK_PARTITIONS * sizeof(char));
    memcpy(currMB->intra_pred_modes8x8,rdopt->intra_pred_modes8x8, MB_BLOCK_PARTITIONS * sizeof(char));
    for (j = img->block_y; j < img->block_y + BLOCK_MULTIPLE; j++) 
    {
      memcpy(&img->ipredmode[j][img->block_x],&rdopt->ipredmode[j][img->block_x], BLOCK_MULTIPLE * sizeof(char));
    }
  }

  if (img->MbaffFrameFlag || (params->UseRDOQuant && params->RDOQ_QP_Num > 1))
  {
    // motion vectors
    copy_motion_vectors_MB (img, rdopt);

    if (!IS_INTRA(currMB))
    {
      memset(currMB->bipred_me, 0, 4* sizeof(short));

      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->motion.mv[LIST_0][j+img->block_y][i+img->block_x][0] = rdopt->all_mv[LIST_0][(short)rdopt->refar[LIST_0][j][i]][b8mode][j][i][0];
            enc_picture->motion.mv[LIST_0][j+img->block_y][i+img->block_x][1] = rdopt->all_mv[LIST_0][(short)rdopt->refar[LIST_0][j][i]][b8mode][j][i][1];
          }
          else
          {
            enc_picture->motion.mv[LIST_0][j+img->block_y][i+img->block_x][0] = 0;
            enc_picture->motion.mv[LIST_0][j+img->block_y][i+img->block_x][1] = 0;
          }
          if (bframe)
          {
            if (b8pdir!=0)
            {
              enc_picture->motion.mv[LIST_1][j+img->block_y][i+img->block_x][0] = rdopt->all_mv[LIST_1][(short)rdopt->refar[LIST_1][j][i]][b8mode][j][i][0];
              enc_picture->motion.mv[LIST_1][j+img->block_y][i+img->block_x][1] = rdopt->all_mv[LIST_1][(short)rdopt->refar[LIST_1][j][i]][b8mode][j][i][1];
            }
            else
            {
              enc_picture->motion.mv[LIST_1][j+img->block_y][i+img->block_x][0] = 0;
              enc_picture->motion.mv[LIST_1][j+img->block_y][i+img->block_x][1] = 0;
            }
          }
        }
    }
    else
    {
      for (j = 0; j < 4; j++)
        memset(enc_picture->motion.mv[LIST_0][j+img->block_y][img->block_x], 0, 2 * BLOCK_MULTIPLE * sizeof(short));
      if (bframe)
      {
        for (j = 0; j < 4; j++)
          memset(enc_picture->motion.mv[LIST_1][j+img->block_y][img->block_x], 0, 2 * BLOCK_MULTIPLE * sizeof(short));
      }
    }
  }
} // end of copy_rdopt_data


static void ReportNALNonVLCBits(int64 tmp_time, int64 me_time)
{
  //! Need to add type (i.e. SPS, PPS, SEI etc).
  if (params->Verbose != 0)
    printf ("%05d(NVB)%8d \n", img->frame_no, stats->bit_ctr_parametersets_n);
}


static void ReportSimple(ImageParameters *cur_img, char *pic_type, int cur_bits, DistMetric *metric, int tmp_time, int me_time)
{
  printf ("%05d(%3s)%8d   %2d %7.3f %7.3f %7.3f %9d %7d    %3s    %d\n",
    cur_img->frame_no, pic_type, cur_bits, 
    cur_img->AverageFrameQP,
    metric->value[0], metric->value[1], metric->value[2], 
    tmp_time, me_time,
    cur_img->fld_flag ? "FLD" : "FRM", 
    cur_img->nal_reference_idc);
}

static void ReportVerbose(ImageParameters *cur_img, char *pic_type, int cur_bits, int wp_method, int lambda, DistMetric *mPSNR, int tmp_time, int me_time, int direct_mode)
{
  printf ("%05d(%3s)%8d %1d %2d %2d %7.3f %7.3f %7.3f %9d %7d    %3s %5d %1d %2d %2d  %d   %d\n",
    cur_img->frame_no, pic_type, cur_bits, wp_method,
    cur_img->AverageFrameQP, lambda, 
    mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],     
    tmp_time, me_time,
    cur_img->fld_flag ? "FLD" : "FRM", intras, direct_mode,
    cur_img->num_ref_idx_l0_active, cur_img->num_ref_idx_l1_active, cur_img->rd_pass, cur_img->nal_reference_idc);
}

static void ReportVerboseNVB(ImageParameters *cur_img, char *pic_type, int cur_bits, int nvb_bits, int wp_method, int lambda, DistMetric *mPSNR, int tmp_time, int me_time, int direct_mode)
{
  printf ("%05d(%3s)%8d %3d  %1d %2d %2d %7.3f %7.3f %7.3f %9d %7d    %3s %5d %1d %2d %2d  %d   %d\n",
    cur_img->frame_no, pic_type, cur_bits, nvb_bits, wp_method,
    cur_img->AverageFrameQP, lambda, 
    mPSNR->value[0], mPSNR->value[1], mPSNR->value[2],     
    tmp_time, me_time,
    cur_img->fld_flag ? "FLD" : "FRM", intras, direct_mode,
    cur_img->num_ref_idx_l0_active, cur_img->num_ref_idx_l1_active, cur_img->rd_pass, cur_img->nal_reference_idc);
}

static void ReportVerboseSSIM(ImageParameters *cur_img, char *pic_type, int cur_bits, int wp_method, int lambda, DistMetric *mPSNR, DistMetric *mSSIM,int tmp_time, int me_time, int direct_mode)
{
  printf ("%05d(%3s)%8d %1d %2d %2d %7.3f %7.3f %7.3f %7.4f %7.4f %7.4f %9d %7d    %3s %5d %1d %2d %2d  %d   %d\n",
    cur_img->frame_no, pic_type, cur_bits, wp_method,
    cur_img->AverageFrameQP, lambda, 
    mPSNR->value[0], mPSNR->value[1], mPSNR->value[2], 
    mSSIM->value[0], mSSIM->value[1], mSSIM->value[2], 
    tmp_time, me_time,
    img->fld_flag ? "FLD" : "FRM", intras, direct_mode,
    img->num_ref_idx_l0_active, img->num_ref_idx_l1_active,img->rd_pass, img->nal_reference_idc);
}

static void ReportVerboseNVBSSIM(ImageParameters *cur_img, char *pic_type, int cur_bits, int nvb_bits, int wp_method, int lambda, DistMetric *mPSNR, DistMetric *mSSIM,int tmp_time, int me_time, int direct_mode)
{
  printf ("%05d(%3s)%8d %3d  %1d %2d %2d %7.3f %7.3f %7.3f %7.4f %7.4f %7.4f %9d %7d    %3s %5d %1d %2d %2d  %d   %d\n",
    cur_img->frame_no, pic_type, cur_bits, nvb_bits, wp_method,
    cur_img->AverageFrameQP, lambda, 
    mPSNR->value[0], mPSNR->value[1], mPSNR->value[2], 
    mSSIM->value[0], mSSIM->value[1], mSSIM->value[2], 
    tmp_time, me_time,
    img->fld_flag ? "FLD" : "FRM", intras, direct_mode,
    img->num_ref_idx_l0_active, img->num_ref_idx_l1_active,img->rd_pass, img->nal_reference_idc);
}

static void ReportFirstframe(int64 tmp_time, int64 me_time)
{
  if (params->Verbose == 1)
  {
    ReportSimple(img, "IDR", (int) (stats->bit_ctr - stats->bit_ctr_n), &dist->metric[PSNR], (int) tmp_time, (int) me_time);
  }
  else if (params->Verbose == 2)
  {
    int lambda = (int) img->lambda_me[I_SLICE][img->AverageFrameQP][0];
    if (params->Distortion[SSIM] == 1)
      ReportVerboseSSIM(img, "IDR", (int) (stats->bit_ctr - stats->bit_ctr_n), 0, lambda, &dist->metric[PSNR], &dist->metric[SSIM], (int) tmp_time, (int) me_time, 0);
    else
      ReportVerbose(img, "IDR", (int) (stats->bit_ctr - stats->bit_ctr_n), 0, lambda, &dist->metric[PSNR], (int) tmp_time, (int) me_time, 0);
  }
  else if (params->Verbose == 3)
  {
    int lambda = (int) img->lambda_me[I_SLICE][img->AverageFrameQP][0];
    if (params->Distortion[SSIM] == 1)
      ReportVerboseNVBSSIM(img, "IDR", (int) (stats->bit_ctr - stats->bit_ctr_n) + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &dist->metric[PSNR], &dist->metric[SSIM], (int) tmp_time, (int) me_time, 0);
    else
      ReportVerboseNVB(img, "IDR", (int) (stats->bit_ctr - stats->bit_ctr_n) + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &dist->metric[PSNR], (int) tmp_time, (int) me_time, 0);
  }

  stats->bit_counter[I_SLICE] = stats->bit_ctr;
  stats->bit_ctr = 0;
}

static void ReportIntra(int64 tmp_time, int64 me_time)
{
  char pic_type[4];

  if ((params->redundant_pic_flag == 0) || !redundant_coding )
  {
    if (img->currentPicture->idr_flag == TRUE)
      strcpy(pic_type,"IDR");
    else
      strcpy(pic_type," I ");
  }
  else
    strcpy(pic_type,"R");

  if (params->Verbose == 1)
  {
    ReportSimple(img, pic_type, (int) (stats->bit_ctr - stats->bit_ctr_n), &dist->metric[PSNR], (int) tmp_time, (int) me_time);
  }
  else if (params->Verbose == 2)
  {
    int lambda = (int) img->lambda_me[I_SLICE][img->AverageFrameQP][0];
    if (params->Distortion[SSIM] == 1)
    {
      ReportVerboseSSIM(img, pic_type, (int) (stats->bit_ctr - stats->bit_ctr_n), 0, lambda, &dist->metric[PSNR], &dist->metric[SSIM], (int) tmp_time, (int) me_time, 0);
    }
    else
    {
      ReportVerbose(img, pic_type, (int) (stats->bit_ctr - stats->bit_ctr_n), 0, lambda, &dist->metric[PSNR], (int) tmp_time, (int) me_time, 0);
    }
  }
  else if (params->Verbose == 3)
  {
    int lambda = (int) img->lambda_me[I_SLICE][img->AverageFrameQP][0];
    if (params->Distortion[SSIM] == 1)
    {
      ReportVerboseNVBSSIM(img, pic_type, (int) (stats->bit_ctr - stats->bit_ctr_n) + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &dist->metric[PSNR], &dist->metric[SSIM], (int) tmp_time, (int) me_time, 0);
    }
    else
    {
      ReportVerboseNVB(img, pic_type, (int) (stats->bit_ctr - stats->bit_ctr_n) + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, 0, lambda, &dist->metric[PSNR], (int) tmp_time, (int) me_time, 0);
    }
  }
}

static void ReportB(int64 tmp_time, int64 me_time)
{
  if (params->Verbose == 1)
  {
    ReportSimple(img, " B ", (int) (stats->bit_ctr - stats->bit_ctr_n), &dist->metric[PSNR], (int) tmp_time, (int) me_time);
  }
  else if (params->Verbose == 2)
  {
    int lambda = (int) img->lambda_me[img->nal_reference_idc ? 5 : B_SLICE][img->AverageFrameQP][0];    
    if (params->Distortion[SSIM] == 1)
      ReportVerboseSSIM(img, " B ", (int) (stats->bit_ctr - stats->bit_ctr_n), active_pps->weighted_bipred_idc, lambda, &dist->metric[PSNR], &dist->metric[SSIM], (int) tmp_time, (int) me_time, img->direct_spatial_mv_pred_flag);
    else
      ReportVerbose(img, " B ", (int) (stats->bit_ctr - stats->bit_ctr_n), active_pps->weighted_bipred_idc, lambda, &dist->metric[PSNR], (int) tmp_time, (int) me_time, img->direct_spatial_mv_pred_flag);
  }
  else if (params->Verbose == 3)
  {
    int lambda = (int) img->lambda_me[img->nal_reference_idc ? 5 : B_SLICE][img->AverageFrameQP][0];    
    if (params->Distortion[SSIM] == 1)
      ReportVerboseNVBSSIM(img, " B ", (int) (stats->bit_ctr - stats->bit_ctr_n) + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, active_pps->weighted_bipred_idc, lambda, &dist->metric[PSNR], &dist->metric[SSIM], (int) tmp_time, (int) me_time, img->direct_spatial_mv_pred_flag);
    else
      ReportVerboseNVB(img, " B ", (int) (stats->bit_ctr - stats->bit_ctr_n) + stats->bit_ctr_parametersets_n, stats->bit_ctr_parametersets_n, active_pps->weighted_bipred_idc, lambda, &dist->metric[PSNR], (int) tmp_time, (int) me_time, img->direct_spatial_mv_pred_flag);
  }
}

static v

⌨️ 快捷键说明

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