me_umhex.h
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:15k
源码类别:

Audio

开发平台:

Visual C++

  1. /*!
  2.  ************************************************************************
  3.  *
  4.  * file me_umhex.h
  5.  *
  6.  * brief
  7.  *   Macro definitions and global variables for UMHEX fast
  8.  *   integer pel motion estimation and fractional pel motion estimation
  9.  *
  10.  * author
  11.  *   Main contributors: (see contributors.h for copyright, address and affiliation details)
  12.  *    - Zhibo Chen         <chenzhibo@tsinghua.org.cn>
  13.  *    - JianFeng Xu        <fenax@video.mdc.tsinghua.edu.cn>
  14.  *    - Wenfang Fu         <fwf@video.mdc.tsinghua.edu.cn>
  15.  *    - Xiaozhong Xu       <xxz@video.mdc.tsinghua.edu.cn>
  16.  *
  17.  * date
  18.  *   2006.1
  19.  ************************************************************************
  20.  */
  21. #ifndef _ME_UMHEX_H_
  22. #define _ME_UMHEX_H_
  23. #include "mbuffer.h"
  24. #define EARLY_TERMINATION                                                             
  25.   if ((min_mcost-pred_SAD)<pred_SAD*betaFourth_2)                                     
  26.   goto fourth_2_step;                                                                 
  27.   else if((min_mcost-pred_SAD)<pred_SAD*betaFourth_1)                                 
  28.   goto fourth_1_step;
  29. #define SEARCH_ONE_PIXEL                                                              
  30.   if(iabs(cand_x - center_x) <=search_range && iabs(cand_y - center_y)<= search_range)
  31.   {                                                                                   
  32.     if(!McostState[cand_y-center_y+search_range][cand_x-center_x+search_range])       
  33.     {                                                                                 
  34.       mcost = MV_COST (lambda_factor, mvshift, cand_x, cand_y, pred_x, pred_y);       
  35.       if(mcost<min_mcost)                                                             
  36.       {                                                                               
  37.         mcost += computeUniPred[dist_method](orig_pic,                                
  38.         blocksize_y,blocksize_x, min_mcost - mcost,                                   
  39.         (cand_x << 2) + IMG_PAD_SIZE_TIMES4, (cand_y << 2) + IMG_PAD_SIZE_TIMES4);    
  40.         McostState[cand_y-center_y+search_range][cand_x-center_x+search_range] = 1;   
  41.         if (mcost < min_mcost)                                                        
  42.         {                                                                             
  43.           best_x = cand_x;                                                            
  44.           best_y = cand_y;                                                            
  45.           min_mcost = mcost;                                                          
  46.         }                                                                             
  47.       }                                                                               
  48.     }                                                                                 
  49.    }
  50. #define SEARCH_ONE_PIXEL_BIPRED                                                       
  51. if(iabs(cand_x - center2_x) <=search_range && iabs(cand_y - center2_y)<= search_range)
  52. {                                                                                     
  53.   if(!McostState[cand_y-center2_y+search_range][cand_x-center2_x+search_range])       
  54.   {                                                                                   
  55.     mcost  = MV_COST (lambda_factor, mvshift, center1_x, center1_y, pred_x1, pred_y1);
  56.     mcost += MV_COST (lambda_factor, mvshift, cand_x, cand_y, pred_x2, pred_y2);      
  57.   if(mcost<min_mcost)                                                                 
  58.   {                                                                                   
  59.       mcost  += computeBiPred(cur_pic, blocksize_y, blocksize_x,                      
  60.       min_mcost - mcost,                                                              
  61.       (center1_x << 2) + IMG_PAD_SIZE_TIMES4,                                         
  62.       (center1_y << 2) + IMG_PAD_SIZE_TIMES4,                                         
  63.       (cand_x << 2) + IMG_PAD_SIZE_TIMES4,                                            
  64.       (cand_y << 2) + IMG_PAD_SIZE_TIMES4);                                           
  65.       McostState[cand_y-center2_y+search_range][cand_x-center2_x+search_range] = 1;   
  66.       if (mcost < min_mcost)                                                          
  67.       {                                                                               
  68.         best_x = cand_x;                                                              
  69.         best_y = cand_y;                                                              
  70.         min_mcost = mcost;                                                            
  71.       }                                                                               
  72.     }                                                                                   
  73.   }                                                                                   
  74. }
  75. byte **McostState;                          //!< state for integer pel search
  76. byte **SearchState;                         //!< state for fractional pel search
  77. int ****fastme_ref_cost;                    //!< store SAD information needed for forward ref-frame prediction
  78. int ***fastme_l0_cost;                      //!< store SAD information needed for forward median and uplayer prediction
  79. int ***fastme_l1_cost;                      //!< store SAD information needed for backward median and uplayer prediction
  80. int ***fastme_l0_cost_bipred;               //!< store SAD information for bipred mode
  81. int ***fastme_l1_cost_bipred;               //!< store SAD information for bipred mode
  82. int bipred_flag;                            //!< flag for bipred
  83. int **fastme_best_cost;                     //!< for multi ref early termination threshold
  84. int pred_SAD;                               //!<  SAD prediction in use.
  85. int pred_MV_ref[2], pred_MV_uplayer[2];     //!< pred motion vector by space or temporal correlation,Median is provided
  86. int UMHEX_blocktype;                        //!< blocktype for UMHEX SetMotionVectorPredictor
  87. int predict_point[5][2];
  88. int SAD_a,SAD_b,SAD_c,SAD_d;
  89. int Threshold_DSR_MB[8];                    //!<  Threshold for usage of DSR. DSR refer to JVT-Q088
  90. //for early termination
  91. float  Bsize[8];
  92. float AlphaFourth_1[8];
  93. float AlphaFourth_2[8];
  94. byte *flag_intra;
  95. int  flag_intra_SAD;
  96. void UMHEX_DefineThreshold(void);
  97. void UMHEX_DefineThresholdMB(void);
  98. int  UMHEX_get_mem(void);
  99. void UMHEX_free_mem(void);
  100. void UMHEX_decide_intrabk_SAD(void);
  101. void UMHEX_skip_intrabk_SAD(int best_mode, int ref_max);
  102. void UMHEX_setup(short ref, int list, int block_y, int block_x, int blocktype, short   ******all_mv);
  103. int                                     //  ==> minimum motion cost after search
  104. UMHEXIntegerPelBlockMotionSearch  (Macroblock *currMB,     // <--  current Macroblock
  105.                                   imgpel   *orig_pic,      // <--  not used
  106.                                   short     ref,           // <--  reference frame (0... or -1 (backward))
  107.                                   int       list,          // <--  reference picture list
  108.                                   int       list_offset,   // <--  MBAFF list offset
  109.                                   char   ***refPic,        // <--  reference array
  110.                                   short ****tmp_mv,        // <--  mv array
  111.                                   int       pic_pix_x,     // <--  absolute x-coordinate of regarded AxB block
  112.                                   int       pic_pix_y,     // <--  absolute y-coordinate of regarded AxB block
  113.                                   int       blocktype,     // <--  block type (1-16x16 ... 7-4x4)
  114.                                   short     pred_mv[2],    // <--  motion vector predictor (x) in sub-pel units
  115.                                   short     mv[2],         //  --> motion vector (x) - in pel units
  116.                                   int       search_range,  // <--  1-d search range in pel units
  117.                                   int       min_mcost,     // <--  minimum motion cost (cost for center or huge value)
  118.                                   int       lambda_factor, // <--  lagrangian parameter for determining motion cost
  119.                                   int       apply_weights
  120.                                   );
  121. int                                                   //  ==> minimum motion cost after search
  122. UMHEXSubPelBlockMotionSearch (
  123.                              imgpel*   orig_pic,      // <--  original pixel values for the AxB block
  124.                              short       ref,         // <--  reference frame (0... or -1 (backward))
  125.                              int       list,          // <--  reference picture list
  126.                              int       list_offset,   // <--  MBAFF list offset
  127.                              int       pic_pix_x,     // <--  absolute x-coordinate of regarded AxB block
  128.                              int       pic_pix_y,     // <--  absolute y-coordinate of regarded AxB block
  129.                              int       blocktype,     // <--  block type (1-16x16 ... 7-4x4)
  130.                              short     pred_mv[2],    // <--  motion vector predictor (x) in sub-pel units
  131.                              short     mv[2],         // <--> in: search center (x) / out: motion vector (x) - in pel units
  132.                              int       search_pos2,   // <--  search positions for    half-pel search  (default: 9)
  133.                              int       search_pos4,   // <--  search positions for quarter-pel search  (default: 9)
  134.                              int       min_mcost,     // <--  minimum motion cost (cost for center or huge value)
  135.                              int       lambda_factor, // <--  lagrangian parameter for determining motion cost
  136.                              int       apply_weights
  137.                              );
  138. extern int UMHEXSubPelBlockME ( //  ==> minimum motion cost after search
  139.                              imgpel*   orig_pic,      // <--  original pixel values for the AxB block
  140.                              short       ref,         // <--  reference frame (0... or -1 (backward))
  141.                              int       list,          // <--  reference picture list
  142.                              int       list_offset,   // <--  MBAFF list offset
  143.                              int       pic_pix_x,     // <--  absolute x-coordinate of regarded AxB block
  144.                              int       pic_pix_y,     // <--  absolute y-coordinate of regarded AxB block
  145.                              int       blocktype,     // <--  block type (1-16x16 ... 7-4x4)
  146.                              short     pred_mv[2],    // <--  motion vector predictor (x) in sub-pel units
  147.                              short     mv[2],         // <--> in: search center (x) / out: motion vector (x) - in pel units
  148.                              int       search_pos2,   // <--  search positions for    half-pel search  (default: 9)
  149.                              int       search_pos4,   // <--  search positions for quarter-pel search  (default: 9)
  150.                              int       min_mcost,     // <--  minimum motion cost (cost for center or huge value)
  151.                              int*      lambda, // <--  lagrangian parameter for determining motion cost
  152.                              int       apply_weights
  153.                              );
  154. extern int                                         //  ==> minimum motion cost after search
  155. SubPelBlockMotionSearch (imgpel*   orig_pic,       // <--  original pixel values for the AxB block
  156.                          short     ref,            // <--  reference frame (0... or -1 (backward))
  157.                          int       list,
  158.                          int       list_offset,   // <--  MBAFF list offset
  159.                          int       pic_pix_x,      // <--  absolute x-coordinate of regarded AxB block
  160.                          int       pic_pix_y,      // <--  absolute y-coordinate of regarded AxB block
  161.                          int       blocktype,      // <--  block type (1-16x16 ... 7-4x4)
  162.                          short     pred_mv[2],     // <--  motion vector predictor in sub-pel units
  163.                          short     mv[2],          // <--> in: search center  / out: motion vector - in pel units
  164.                          int       search_pos2,    // <--  search positions for    half-pel search  (default: 9)
  165.                          int       search_pos4,    // <--  search positions for quarter-pel search  (default: 9)
  166.                          int       min_mcost,      // <--  minimum motion cost (cost for center or huge value)
  167.                          int       *lambda_factor, // <--  lagrangian parameter for determining motion cost
  168.                          int       apply_weights);
  169. int                                                //  ==> minimum motion cost after search
  170. UMHEXBipredIntegerPelBlockMotionSearch (Macroblock *currMB, // <--  current Macroblock
  171.                                        imgpel*   orig_pic,      // <--  original pixel values for the AxB block
  172.                                        short     ref,           // <--  reference frame (0... or -1 (backward))
  173.                                        int       list,          // <--  Current reference list
  174.                                        int       list_offset,   // <--  MBAFF list offset
  175.                                        char   ***refPic,        // <--  reference array
  176.                                        short ****tmp_mv,        // <--  mv array
  177.                                        int       pic_pix_x,     // <--  absolute x-coordinate of regarded AxB block
  178.                                        int       pic_pix_y,     // <--  absolute y-coordinate of regarded AxB block
  179.                                        int       blocktype,     // <--  block type (1-16x16 ... 7-4x4)
  180.                                        short     pred_mv1[2],   // <--  motion vector predictor (x|y) in sub-pel units
  181.                                        short     pred_mv2[2],   // <--  motion vector predictor (x|y) in sub-pel units
  182.                                        short     mv[2],         // <--> in: search center (x) / out: motion vector (x) - in pel units
  183.                                        short     s_mv[2],       // <--> in: search center (x) / out: motion vector (x) - in pel units
  184.                                        int       search_range,  // <--  1-d search range in pel units
  185.                                        int       min_mcost,     // <--  minimum motion cost (cost for center or huge value)
  186.                                        int       iteration_no,  // <--  bi pred iteration number
  187.                                        int       lambda_factor, // <--  lagrangian parameter for determining motion cost
  188.                                        int       apply_weights
  189.                                        );
  190. void UMHEXSetMotionVectorPredictor (Macroblock *currMB, short pmv[2], char **refPic, short ***tmp_mv,
  191.                                     short  ref_frame, int list, int mb_x, int mb_y,
  192.                                     int blockshape_x, int blockshape_y, int *search_range);
  193. #endif