--- motion_est.h 2003/06/09 01:22:18 1.3.2.8 +++ motion_est.h 2003/04/08 11:12:07 1.6 @@ -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.3.2.8 2003/06/09 01:22:18 edgomez Exp $ + * $Id: motion_est.h,v 1.6 2003/04/08 11:12:07 syskin Exp $ * ***************************************************************************/ @@ -39,7 +39,7 @@ /* hard coded motion search parameters for motion_est and smp_motion_est */ -/* very large value */ +// very large value #define MV_MAX_ERROR (4096 * 256) /* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */ @@ -50,8 +50,6 @@ #define NEIGH_TEND_8X8 40.0 #define NEIGH_8X8_BIAS 30 -#define BITS_MULT 16 - /* Parameters which control inter/inter4v decision */ #define IMV16X16 2 @@ -91,7 +89,7 @@ (int)(21.2656*NEIGH_TEND_8X8 + 0.5), (int)(24.8580*NEIGH_TEND_8X8 + 0.5), (int)(29.6436*NEIGH_TEND_8X8 + 0.5), (int)(36.4949*NEIGH_TEND_8X8 + 0.5) }; -/* mv.length table */ +// mv.length table static const int mvtab[64] = { 1, 2, 3, 4, 6, 7, 7, 7, 9, 9, 9, 10, 10, 10, 10, 10, @@ -109,14 +107,14 @@ typedef struct { - /* general fields */ +// 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 * RefP[6]; /* N, V, H, HV, cU, cV */ + const uint8_t * RefP[6]; // N, V, H, HV, cU, cV const uint8_t * CurU; const uint8_t * CurV; uint8_t * RefQ; @@ -129,21 +127,16 @@ int qpel, qpel_precision; int chroma; int rrv; - - /* fields for interpolate and direct modes */ - const uint8_t * b_RefP[6]; /* N, V, H, HV, cU, cV */ +//fields for interpolate and direct modes + const uint8_t * b_RefP[6]; // N, V, H, HV, cU, cV VECTOR bpredMV; uint32_t bFcode; - - /* fields for direct mode */ +// fields for direct mode VECTOR directmvF[4]; VECTOR directmvB[4]; const VECTOR * referencemv; - - /* BITS/R-D stuff */ +// _BITS stuff int16_t * dctSpace; - uint32_t iQuant; - uint32_t quant_type; } SearchData; @@ -224,14 +217,16 @@ const int x, const int y, const uint32_t MotionFlags, - const uint32_t VopFlags, - const uint32_t VolFlags, + const uint32_t GlobalFlags, + const uint32_t iQuant, SearchData * const Data, const MBParam * const pParam, const MACROBLOCK * const pMBs, const MACROBLOCK * const prevMBs, + int inter4v, MACROBLOCK * const pMB); + static WARPPOINTS GlobalMotionEst(const MACROBLOCK * const pMBs, const MBParam * const pParam, @@ -244,38 +239,38 @@ #define iDiamondSize 2 static __inline uint32_t -MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t VopFlags, const uint32_t VolFlags) +MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags) { uint32_t Flags = MotionFlags; - if (!(VopFlags & XVID_VOP_MODEDECISION_BITS)) - Flags &= ~(XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS+XVID_ME_EXTSEARCH_BITS); + if (!(GlobalFlags & XVID_MODEDECISION_BITS)) + Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS); - if (Flags & XVID_ME_EXTSEARCH_BITS) - Flags |= XVID_ME_HALFPELREFINE16_BITS; + if (Flags & EXTSEARCH_BITS) + Flags |= HALFPELREFINE16_BITS; - if (Flags & XVID_ME_EXTSEARCH_BITS && MotionFlags & XVID_ME_EXTSEARCH8) - Flags |= XVID_ME_HALFPELREFINE8_BITS; + if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8) + Flags |= HALFPELREFINE8_BITS; - if (Flags & XVID_ME_HALFPELREFINE16_BITS) - Flags |= XVID_ME_QUARTERPELREFINE16_BITS; + if (Flags & HALFPELREFINE16_BITS) + Flags |= QUARTERPELREFINE16_BITS; - if (Flags & XVID_ME_HALFPELREFINE8_BITS) { - Flags |= XVID_ME_QUARTERPELREFINE8_BITS; - Flags &= ~XVID_ME_HALFPELREFINE8; + if (Flags & HALFPELREFINE8_BITS) { + Flags |= QUARTERPELREFINE8_BITS; + Flags &= ~PMV_HALFPELREFINE8; } - if (Flags & XVID_ME_QUARTERPELREFINE8_BITS) - Flags &= ~XVID_ME_QUARTERPELREFINE8; + if (Flags & QUARTERPELREFINE8_BITS) + Flags &= ~PMV_QUARTERPELREFINE8; - if (!(VolFlags & XVID_VOL_QUARTERPEL)) - Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS); + if (!(GlobalFlags & XVID_QUARTERPEL)) + Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS); - if (!(VopFlags & XVID_VOP_HALFPEL)) - Flags &= ~(XVID_ME_EXTSEARCH16+XVID_ME_HALFPELREFINE16+XVID_ME_HALFPELREFINE8+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS); + if (!(GlobalFlags & XVID_HALFPEL)) + Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS); - if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED)) - Flags &= ~(XVID_ME_CHROMA16 + XVID_ME_CHROMA8); + if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED)) + Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8); return Flags; } @@ -286,7 +281,6 @@ #include "../quant/quant_mpeg4.h" #include "../quant/quant_h263.h" #include "../bitstream/vlc_codes.h" -#include "../dct/fdct.h" static int CountMBBitsInter(SearchData * const Data, @@ -307,85 +301,4 @@ int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); -#define LAMBDA ( (int)(1.0*BITS_MULT) ) - -static __inline unsigned int -Block_CalcBits( int16_t * const coeff, - int16_t * const data, - const uint32_t quant, const int quant_type, - uint32_t * cbp, - const int block) -{ - int sum; - int bits; - const int lambda = LAMBDA*quant*quant; - int distortion = 0; - int i; - - fdct(data); - - if (quant_type == 0) sum = quant_inter(coeff, data, quant); - else sum = quant4_inter(coeff, data, quant); - - if (sum > 0) { - *cbp |= 1 << (5 - block); - bits = BITS_MULT * CodeCoeffInter_CalcBits(coeff, scan_tables[0]); - } else bits = 0; - - if (quant_type == 0) dequant_inter(coeff, coeff, quant); - else dequant4_inter(coeff, coeff, quant); - - for (i = 0; i < 64; i++) { - distortion += (data[i] - coeff[i])*(data[i] - coeff[i]); - } - bits += (BITS_MULT*BITS_MULT*distortion)/lambda; - - - return bits; -} - -static __inline unsigned int -Block_CalcBitsIntra(int16_t * const coeff, - int16_t * const data, - const uint32_t quant, const int quant_type, - uint32_t * cbp, - const int block, - int * dcpred) -{ - int bits, i; - const int lambda = LAMBDA*quant*quant; - int distortion = 0; - uint32_t iDcScaler = get_dc_scaler(quant, block > 3); - int b_dc; - - fdct(data); - data[0] -= 1024; - - if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler); - else quant4_intra(coeff, data, quant, iDcScaler); - - b_dc = coeff[0]; - if (block < 4) { - coeff[0] -= *dcpred; - *dcpred = b_dc; - } - - *cbp |= 1 << (5 - block); - bits = BITS_MULT*CodeCoeffIntra_CalcBits(coeff, scan_tables[0]); - bits += BITS_MULT*dcy_tab[coeff[0] + 255].len; - if (bits != 0) *cbp |= 1 << (5 - block); - - coeff[0] = b_dc; - if (quant_type == 0) dequant_intra(coeff, coeff, quant, iDcScaler); - else dequant4_intra(coeff, coeff, quant, iDcScaler); - - for (i = 0; i < 64; i++) { - distortion += (data[i] - coeff[i])*(data[i] - coeff[i]); - } - - bits += (BITS_MULT*BITS_MULT*distortion)/lambda; - - return bits; -} - #endif /* _MOTION_EST_H_ */