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

📄 lencod.c

📁 压缩JM12.3d的完整的全部C语言的代码文档,用于嵌入式系统的压缩编解码
💻 C
📖 第 1 页 / 共 5 页
字号:
  }

  get_mem_ACcoeff (&(img->cofAC));
  get_mem_DCcoeff (&(img->cofDC));

  if (input->AdaptiveRounding)
  {
    get_mem3Dint(&(img->fadjust4x4), 4, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
    get_mem3Dint(&(img->fadjust8x8), 3, MB_BLOCK_SIZE, MB_BLOCK_SIZE);
    if (img->yuv_format != 0)
    {
      get_mem4Dint(&(img->fadjust4x4Cr), 4, 2, img->mb_cr_size_y, img->mb_cr_size_x);
      get_mem4Dint(&(img->fadjust8x8Cr), 1, 2, img->mb_cr_size_y, img->mb_cr_size_x);
    }
  }

  if(input->MbInterlace)
  {
    get_mem_mv (&(rddata_top_frame_mb.pred_mv));
    get_mem_mv (&(rddata_top_frame_mb.all_mv));

    get_mem_mv (&(rddata_bot_frame_mb.pred_mv));
    get_mem_mv (&(rddata_bot_frame_mb.all_mv));

    get_mem_ACcoeff (&(rddata_top_frame_mb.cofAC));
    get_mem_DCcoeff (&(rddata_top_frame_mb.cofDC));

    get_mem_ACcoeff (&(rddata_bot_frame_mb.cofAC));
    get_mem_DCcoeff (&(rddata_bot_frame_mb.cofDC));

    if ( input->MbInterlace != FRAME_MB_PAIR_CODING )
    {
      get_mem_mv (&(rddata_top_field_mb.pred_mv));
      get_mem_mv (&(rddata_top_field_mb.all_mv));

      get_mem_mv (&(rddata_bot_field_mb.pred_mv));
      get_mem_mv (&(rddata_bot_field_mb.all_mv));

      get_mem_ACcoeff (&(rddata_top_field_mb.cofAC));
      get_mem_DCcoeff (&(rddata_top_field_mb.cofDC));

      get_mem_ACcoeff (&(rddata_bot_field_mb.cofAC));
      get_mem_DCcoeff (&(rddata_bot_field_mb.cofDC));
    }
  }

  if (img->max_imgpel_value > img->max_imgpel_value_uv)
    byte_abs_range = (img->max_imgpel_value + 1) * 2;
  else
    byte_abs_range = (img->max_imgpel_value_uv + 1) * 2;

  if ((img->quad = (int*)calloc (byte_abs_range, sizeof(int))) == NULL)
    no_mem_exit ("init_img: img->quad");
  img->quad += byte_abs_range/2;
  for (i=0; i < byte_abs_range/2; ++i)
  {
    img->quad[i] = img->quad[-i] = i * i;
  }

  img->width         = (input->img_width + img->auto_crop_right);
  img->height        = (input->img_height + img->auto_crop_bottom);
  img->width_blk     = img->width / BLOCK_SIZE;
  img->height_blk    = img->height / BLOCK_SIZE;
  img->width_padded  =  img->width + 2 * IMG_PAD_SIZE;
  img->height_padded = img->height + 2 * IMG_PAD_SIZE;

  if (img->yuv_format != YUV400)
  {
    img->width_cr = img->width/(16/mb_width_cr[img->yuv_format]);
    img->height_cr= img->height/(16/mb_height_cr[img->yuv_format]);

    input->img_width_cr  = input->img_width/(16/mb_width_cr[img->yuv_format]);
    input->img_height_cr = input->img_height/(16/mb_height_cr[img->yuv_format]);
  }
  else
  {
    img->width_cr = 0;
    img->height_cr= 0;

    input->img_width_cr  = 0;
    input->img_height_cr = 0;
  }
  img->height_cr_frame = img->height_cr;

  img->size = img->width * img->height;
  img->size_cr = img->width_cr * img->height_cr;

  img->PicWidthInMbs    = img->width/MB_BLOCK_SIZE;
  img->FrameHeightInMbs = img->height/MB_BLOCK_SIZE;
  img->FrameSizeInMbs   = img->PicWidthInMbs * img->FrameHeightInMbs;

  img->PicHeightInMapUnits = ( active_sps->frame_mbs_only_flag ? img->FrameHeightInMbs : img->FrameHeightInMbs/2 );

  if( IS_INDEPENDENT(input) )
  {
    for( i=0; i<MAX_PLANE; i++ ){
      if ((img->mb_data_JV[i] = (Macroblock *) calloc(img->FrameSizeInMbs,sizeof(Macroblock))) == NULL)
        no_mem_exit("init_img: img->mb_data_JV");
    }
    img->mb_data = NULL;
  }
  else
  {
    if ((img->mb_data = (Macroblock *) calloc(img->FrameSizeInMbs, sizeof(Macroblock))) == NULL)
      no_mem_exit("init_img: img->mb_data");
  }

  if (input->UseConstrainedIntraPred)
  {
    if ((img->intra_block = (int*)calloc(img->FrameSizeInMbs, sizeof(int))) == NULL)
      no_mem_exit("init_img: img->intra_block");
  }

  if (input->CtxAdptLagrangeMult == 1)
  {
    if ((mb16x16_cost_frame = (double*)calloc(img->FrameSizeInMbs, sizeof(double))) == NULL)
    {
      no_mem_exit("init mb16x16_cost_frame");
    }
  }
  get_mem2D((byte***)&(img->ipredmode), img->height_blk, img->width_blk);        //need two extra rows at right and bottom
  get_mem2D((byte***)&(img->ipredmode8x8), img->height_blk, img->width_blk);     // help storage for ipredmode 8x8, inserted by YV
  memset(&(img->ipredmode[0][0]), -1, img->height_blk * img->width_blk *sizeof(char));
  memset(&(img->ipredmode8x8[0][0]), -1, img->height_blk * img->width_blk *sizeof(char));

  get_mem2D((byte***)&(rddata_top_frame_mb.ipredmode), img->height_blk, img->width_blk);

  if (input->MbInterlace)
  {
    get_mem2D((byte***)&(rddata_bot_frame_mb.ipredmode), img->height_blk, img->width_blk);
    get_mem2D((byte***)&(rddata_top_field_mb.ipredmode), img->height_blk, img->width_blk);
    get_mem2D((byte***)&(rddata_bot_field_mb.ipredmode), img->height_blk, img->width_blk);
  }
  // CAVLC mem
  get_mem3Dint(&(img->nz_coeff), img->FrameSizeInMbs, 4, 4+img->num_blk8x8_uv);


  get_mem2Ddb_offset(&(img->lambda_md), 10, 52 + img->bitdepth_luma_qp_scale,img->bitdepth_luma_qp_scale);
  get_mem3Ddb_offset (&(img->lambda_me), 10, 52 + img->bitdepth_luma_qp_scale, 3, img->bitdepth_luma_qp_scale);
  get_mem3Dint_offset(&(img->lambda_mf), 10, 52 + img->bitdepth_luma_qp_scale, 3, img->bitdepth_luma_qp_scale);

  if (input->CtxAdptLagrangeMult == 1)
  {
    get_mem2Ddb_offset(&(img->lambda_mf_factor), 10, 52 + img->bitdepth_luma_qp_scale, img->bitdepth_luma_qp_scale);
  }

  CAVLC_init();

  img->GopLevels = (input->successive_Bframe) ? 1 : 0;
  img->mb_y_upd=0;

  RandomIntraInit (img->PicWidthInMbs, img->FrameHeightInMbs, input->RandomIntraMBRefresh);

  InitSEIMessages();  // Tian Dong (Sept 2002)

  // Initialize filtering parameters. If sending parameters, the offsets are
  // multiplied by 2 since inputs are taken in "div 2" format.
  // If not sending parameters, all fields are cleared
  if (input->LFSendParameters)
  {
    input->LFAlphaC0Offset <<= 1;
    input->LFBetaOffset <<= 1;
  }
  else
  {
    input->LFDisableIdc = 0;
    input->LFAlphaC0Offset = 0;
    input->LFBetaOffset = 0;
  }

  if( input->separate_colour_plane_flag )
  {
    img->ChromaArrayType = 0;
  }
  else
  {
    img->ChromaArrayType = input->yuv_format;
  }

  if (input->RDPictureDecision)
  {
    img->frm_iter = 3;
  }
  else
    img->frm_iter = 1;
}


/*!
 ***********************************************************************
 * \brief
 *    Free the Image structures
 * \par Input:
 *    Image Parameters struct img_par *img
 ***********************************************************************
 */
void free_img ()
{
  CloseSEIMessages(); // Tian Dong (Sept 2002)
  free_mem_mv (img->pred_mv);
  free_mem_mv (img->all_mv);

  if (input->BiPredMotionEstimation)
  {
    free_mem_mv (img->bipred_mv1);
    free_mem_mv (img->bipred_mv2);
  }

  free_mem_ACcoeff (img->cofAC);
  free_mem_DCcoeff (img->cofDC);

  if (input->AdaptiveRounding)
  {
    free_mem3Dint(img->fadjust4x4, 4);
    free_mem3Dint(img->fadjust8x8, 3);
    if (img->yuv_format != 0)
    {
      free_mem4Dint(img->fadjust4x4Cr, 4, 2);
      free_mem4Dint(img->fadjust8x8Cr, 1, 2);
    }
  }


  if (input->MbInterlace)
  {
    free_mem_mv (rddata_top_frame_mb.pred_mv);
    free_mem_mv (rddata_top_frame_mb.all_mv);

    free_mem_mv (rddata_bot_frame_mb.pred_mv);
    free_mem_mv (rddata_bot_frame_mb.all_mv);

    free_mem_ACcoeff (rddata_top_frame_mb.cofAC);
    free_mem_DCcoeff (rddata_top_frame_mb.cofDC);

    free_mem_ACcoeff (rddata_bot_frame_mb.cofAC);
    free_mem_DCcoeff (rddata_bot_frame_mb.cofDC);

    if ( input->MbInterlace != FRAME_MB_PAIR_CODING )
    {
      free_mem_mv (rddata_top_field_mb.pred_mv);
      free_mem_mv (rddata_top_field_mb.all_mv);

      free_mem_mv (rddata_bot_field_mb.pred_mv);
      free_mem_mv (rddata_bot_field_mb.all_mv);

      free_mem_ACcoeff (rddata_top_field_mb.cofAC);
      free_mem_DCcoeff (rddata_top_field_mb.cofDC);

      free_mem_ACcoeff (rddata_bot_field_mb.cofAC);
      free_mem_DCcoeff (rddata_bot_field_mb.cofDC);
    }
  }

  if (img->max_imgpel_value > img->max_imgpel_value_uv)
    free (img->quad - (img->max_imgpel_value + 1));
  else
    free (img->quad - (img->max_imgpel_value_uv + 1));

  if (input->MbInterlace)
  {
    free_mem2D((byte**)rddata_bot_frame_mb.ipredmode);
    free_mem2D((byte**)rddata_top_field_mb.ipredmode);
    free_mem2D((byte**)rddata_bot_field_mb.ipredmode);
  }
}


/*!
 ************************************************************************
 * \brief
 *    Allocates the picture structure along with its dependent
 *    data structures
 * \return
 *    Pointer to a Picture
 ************************************************************************
 */

Picture *malloc_picture()
{
  Picture *pic;
  if ((pic = calloc (1, sizeof (Picture))) == NULL) no_mem_exit ("malloc_picture: Picture structure");
  //! Note: slice structures are allocated as needed in code_a_picture
  return pic;
}

/*!
 ************************************************************************
 * \brief
 *    Frees a picture
 * \param
 *    pic: POinter to a Picture to be freed
 ************************************************************************
 */


void free_picture(Picture *pic)
{
  if (pic != NULL)
  {
    free_slice_list(pic);
    free (pic);
  }
}


/*!
 ************************************************************************
 * \brief
 *    Reports frame statistical data to a stats file
 ************************************************************************
 */
void report_frame_statistic()
{
  FILE *p_stat_frm = NULL;
  static int64 last_mode_use[NUM_PIC_TYPE][MAXMODE];
  static int   last_b8_mode_0[NUM_PIC_TYPE][2];
  static int   last_mode_chroma_use[4];
  static int64 last_bit_ctr_n = 0;
  int i;
  char name[20];
  int bitcounter;

#ifndef WIN32
  time_t now;
  struct tm *l_time;
  char string[1000];
#else
  char timebuf[128];
#endif


⌨️ 快捷键说明

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