--- motion_est.h 2003/01/24 11:44:24 1.1.2.14 +++ 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.1.2.14 2003/01/24 11:44:24 syskin Exp $ + * $Id: motion_est.h,v 1.6 2003/04/08 11:12:07 syskin Exp $ * ***************************************************************************/ @@ -90,12 +90,14 @@ (int)(29.6436*NEIGH_TEND_8X8 + 0.5), (int)(36.4949*NEIGH_TEND_8X8 + 0.5) }; // mv.length table -static const uint32_t mvtab[33] = { - 1, 2, 3, 4, 6, 7, 7, 7, - 9, 9, 9, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 11, 11, 11, 11, 11, 11, 12, 12 -}; +static const int mvtab[64] = { + 1, 2, 3, 4, 6, 7, 7, 7, + 9, 9, 9, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 11, 11, 11, 11, 11, 11, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12 }; static const int DQtab[4] = { -1, -2, 1, 2 @@ -103,8 +105,6 @@ #define RRV_MV_SCALEDOWN(a) ( (a)>=0 ? (a+1)/2 : (a-1)/2 ) -static const VECTOR zeroMV = {0,0}; - typedef struct { // general fields @@ -114,12 +114,7 @@ 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 * RefP[6]; // N, V, H, HV, cU, cV const uint8_t * CurU; const uint8_t * CurV; uint8_t * RefQ; @@ -133,19 +128,15 @@ int chroma; int rrv; //fields for interpolate and direct modes - const uint8_t * bRef; - const uint8_t * bRefH; - const uint8_t * bRefV; - const uint8_t * bRefHV; - const uint8_t * b_RefCU; - const uint8_t * b_RefCV; - + const uint8_t * b_RefP[6]; // N, V, H, HV, cU, cV VECTOR bpredMV; uint32_t bFcode; // fields for direct mode VECTOR directmvF[4]; VECTOR directmvB[4]; const VECTOR * referencemv; +// _BITS stuff + int16_t * dctSpace; } SearchData; @@ -210,12 +201,12 @@ bool 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); + FRAMEINFO * const current, + FRAMEINFO * const reference, + const IMAGE * const pRefH, + const IMAGE * const pRefV, + const IMAGE * const pRefHV, + const uint32_t iLimit); static void SearchP(const IMAGE * const pRef, @@ -226,6 +217,7 @@ const int x, const int y, const uint32_t MotionFlags, + const uint32_t GlobalFlags, const uint32_t iQuant, SearchData * const Data, const MBParam * const pParam, @@ -246,4 +238,67 @@ #define iDiamondSize 2 +static __inline uint32_t +MakeGoodMotionFlags(const uint32_t MotionFlags, const uint32_t GlobalFlags) +{ + uint32_t Flags = MotionFlags; + + if (!(GlobalFlags & XVID_MODEDECISION_BITS)) + Flags &= ~(QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS+EXTSEARCH_BITS); + + if (Flags & EXTSEARCH_BITS) + Flags |= HALFPELREFINE16_BITS; + + if (Flags & EXTSEARCH_BITS && MotionFlags & PMV_EXTSEARCH8) + Flags |= HALFPELREFINE8_BITS; + + if (Flags & HALFPELREFINE16_BITS) + Flags |= QUARTERPELREFINE16_BITS; + + if (Flags & HALFPELREFINE8_BITS) { + Flags |= QUARTERPELREFINE8_BITS; + Flags &= ~PMV_HALFPELREFINE8; + } + + if (Flags & QUARTERPELREFINE8_BITS) + Flags &= ~PMV_QUARTERPELREFINE8; + + if (!(GlobalFlags & XVID_QUARTERPEL)) + Flags &= ~(PMV_QUARTERPELREFINE16+PMV_QUARTERPELREFINE8+QUARTERPELREFINE16_BITS+QUARTERPELREFINE8_BITS); + + if (!(GlobalFlags & XVID_HALFPEL)) + Flags &= ~(PMV_EXTSEARCH16+PMV_HALFPELREFINE16+PMV_HALFPELREFINE8+HALFPELREFINE16_BITS+HALFPELREFINE8_BITS); + + if (GlobalFlags & (XVID_GREYSCALE + XVID_REDUCED)) + Flags &= ~(PMV_CHROMA16 + PMV_CHROMA8); + + return Flags; +} + +/* BITS mode decision and search */ + +#include "../bitstream/zigzag.h" +#include "../quant/quant_mpeg4.h" +#include "../quant/quant_h263.h" +#include "../bitstream/vlc_codes.h" + +static int +CountMBBitsInter(SearchData * const Data, + const MACROBLOCK * const pMBs, const int x, const int y, + const MBParam * const pParam, + const uint32_t MotionFlags); + +static int +CountMBBitsInter4v(const SearchData * const Data, + MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, + const int x, const int y, + const MBParam * const pParam, const uint32_t MotionFlags, + const VECTOR * const backup); + +static int +CountMBBitsIntra(const SearchData * const Data); + +int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); +int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); + #endif /* _MOTION_EST_H_ */