--- motion_est.h 2002/09/23 20:36:02 1.1.2.1 +++ motion_est.h 2002/12/11 10:32:29 1.1.2.10 @@ -26,7 +26,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: motion_est.h,v 1.1.2.1 2002/09/23 20:36:02 chl Exp $ + * $Id: motion_est.h,v 1.1.2.10 2002/12/11 10:32:29 syskin Exp $ * ***************************************************************************/ @@ -44,13 +44,14 @@ /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */ #define MV16_INTER_BIAS 512 +/* vector map (vlc delta size) smoother parameters ! float !*/ +#define NEIGH_TEND_16X16 10.5 +#define NEIGH_TEND_8X8 4.0 +#define NEIGH_8X8_BIAS 30 + /* Parameters which control inter/inter4v decision */ #define IMV16X16 2 -/* vector map (vlc delta size) smoother parameters ! float !*/ -#define NEIGH_TEND_16X16 4.0 -#define NEIGH_TEND_8X8 7.0 - static const int lambda_vec16[32] = { 0 ,(int)(1.00235 * NEIGH_TEND_16X16 + 0.5), (int)(1.15582*NEIGH_TEND_16X16 + 0.5), (int)(1.31976*NEIGH_TEND_16X16 + 0.5), @@ -69,7 +70,7 @@ (int)(21.2656*NEIGH_TEND_16X16 + 0.5), (int)(24.8580*NEIGH_TEND_16X16 + 0.5), (int)(29.6436*NEIGH_TEND_16X16 + 0.5), (int)(36.4949*NEIGH_TEND_16X16 + 0.5) }; -static const int lambda_vec8[32] = +static const int lambda_vec8[32] = { 0 ,(int)(1.00235 * NEIGH_TEND_8X8 + 0.5), (int)(1.15582 + NEIGH_TEND_8X8 + 0.5), (int)(1.31976*NEIGH_TEND_8X8 + 0.5), (int)(1.49591*NEIGH_TEND_8X8 + 0.5), (int)(1.68601*NEIGH_TEND_8X8 + 0.5), @@ -95,22 +96,40 @@ 10, 11, 11, 11, 11, 11, 11, 12, 12 }; +static const int DQtab[4] = { + -1, -2, 1, 2 +}; + +#define RRV_MV_SCALEDOWN(a) ( (a)>=0 ? (a+1)/2 : (a-1)/2 ) +#define RRV_MV_SCALEUP(a) ( (a)>0 ? 2*(a)-1 : (a)<0 ? 2*(a)+1 : (a) ) + typedef struct { // general fields int max_dx, min_dx, max_dy, min_dy; + uint32_t rounding; VECTOR predMV; VECTOR *currentMV; + VECTOR *currentQMV; int32_t *iMinSAD; const uint8_t * Ref; const uint8_t * RefH; const uint8_t * RefV; const uint8_t * RefHV; + const uint8_t * RefCU; + const uint8_t * RefCV; + const uint8_t * CurU; + const uint8_t * CurV; + uint8_t * RefQ; const uint8_t * Cur; - uint32_t iQuant; + uint32_t lambda16; + uint32_t lambda8; uint32_t iEdgedWidth; uint32_t iFcode; int * temp; + int qpel, qpel_precision; + int chroma; + int rrv; //fields for interpolate and direct mode const uint8_t *bRef; const uint8_t *bRefH; @@ -151,21 +170,76 @@ const uint32_t height, const uint32_t fcode) { + int k; + const int search_range = 32 << (fcode - 1); + const int high = search_range - 1; + const int low = -search_range; + k = 2 * (int)(width - x*block_sz); + *max_dx = MIN(high, k); + k = 2 * (int)(height - y*block_sz); + *max_dy = MIN(high, k); + + k = -2 * (int)((x+1) * block_sz); + *min_dx = MAX(low, k); + k = -2 * (int)((y+1) * block_sz); + *min_dy = MAX(low, k); +} + +static void __inline +get_range_rrv(int32_t * const min_dx, + int32_t * const max_dx, + int32_t * const min_dy, + int32_t * const max_dy, + const uint32_t x, + const uint32_t y, + const uint32_t block_sz, /* block dimension, 8 or 16 */ + const uint32_t width, + const uint32_t height, + const uint32_t fcode) +{ int k; - int high = (32 << (fcode - 1)) - 1; + const int search_range = 32 << (fcode - 1); + const int high = RRV_MV_SCALEUP(search_range - 1); //halfzero -> halfpel, because we do our search in halfpel + const int low = RRV_MV_SCALEUP(-search_range); k = 2 * (int)(width - x*block_sz); *max_dx = MIN(high, k); k = 2 * (int)(height - y*block_sz); *max_dy = MIN(high, k); - high = -(32 << (fcode - 1)); k = -2 * (int)((x+1) * block_sz); - *min_dx = MAX(high, k); + *min_dx = MAX(low, k); k = -2 * (int)((y+1) * block_sz); - *min_dy = MAX(high, k); + *min_dy = MAX(low, k); +} +static void __inline +get_range_qpel(int32_t * const min_dx, + int32_t * const max_dx, + int32_t * const min_dy, + int32_t * const max_dy, + const uint32_t x, + const uint32_t y, + const uint32_t block_sz, /* block dimension, 8 or 16 */ + const uint32_t width, + const uint32_t height, + const uint32_t fcode) +{ + int k; + const int search_range = 32 << (fcode - 1); + const int high = search_range - 1; + const int low = -search_range; + + k = 4 * (int)(width - x*block_sz); + *max_dx = MIN(high, k); + k = 4 * (int)(height - y*block_sz); + *max_dy = MIN(high, k); + + k = -4 * (int)((x+1) * block_sz); + *min_dx = MAX(low, k); + k = -4 * (int)((y+1) * block_sz); + *min_dy = MAX(low, k); } @@ -179,7 +253,8 @@ const MBParam * const pParam, MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, - const int block); + const int block, + SearchData * const Data); bool MotionEstimation(MBParam * const pParam, @@ -191,7 +266,7 @@ const uint32_t iLimit); static void -SearchP(const uint8_t * const pRef, +SearchP(const IMAGE * const pRef, const uint8_t * const pRefH, const uint8_t * const pRefV, const uint8_t * const pRefHV, @@ -200,23 +275,11 @@ const int y, const uint32_t MotionFlags, const uint32_t iQuant, - const uint32_t iFcode, + SearchData * const Data, const MBParam * const pParam, const MACROBLOCK * const pMBs, const MACROBLOCK * const prevMBs, int inter4v, MACROBLOCK * const pMB); - -#ifdef _SMP -bool -SMP_MotionEstimation(MBParam * const pParam, - FRAMEINFO * const current, - FRAMEINFO * const reference, - const IMAGE * const pRefH, - const IMAGE * const pRefV, - const IMAGE * const pRefHV, - const uint32_t iLimit); -#endif - #endif /* _MOTION_EST_H_ */