--- branches/dev-api-4/xvidcore/src/motion/motion_est.h 2003/06/26 11:50:37 1075 +++ branches/dev-api-4/xvidcore/src/motion/motion_est.h 2003/08/03 10:10:54 1108 @@ -21,7 +21,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.11 2003-06-26 11:50:27 syskin Exp $ + * $Id: motion_est.h,v 1.3.2.15 2003-08-03 10:10:54 syskin Exp $ * ****************************************************************************/ @@ -139,6 +139,7 @@ int16_t * dctSpace; uint32_t iQuant; uint32_t quant_type; + int * cbp; } SearchData; @@ -208,6 +209,7 @@ const IMAGE * const pRefH, const IMAGE * const pRefV, const IMAGE * const pRefHV, + const IMAGE * const pGMC, const uint32_t iLimit); static void @@ -227,8 +229,30 @@ const MACROBLOCK * const prevMBs, MACROBLOCK * const pMB); -static WARPPOINTS -GlobalMotionEst(const MACROBLOCK * const pMBs, +static __inline void +GMEanalyzeMB (const uint8_t * const pCur, + const uint8_t * const pRef, + const uint8_t * const pRefH, + const uint8_t * const pRefV, + const uint8_t * const pRefHV, + const int x, + const int y, + const MBParam * const pParam, + MACROBLOCK * const pMBs, + SearchData * const Data); + +void +GMEanalysis(const MBParam * const pParam, + const FRAMEINFO * const current, + const FRAMEINFO * const reference, + const IMAGE * const pRefH, + const IMAGE * const pRefV, + const IMAGE * const pRefHV); + + + +WARPPOINTS +GlobalMotionEst(MACROBLOCK * const pMBs, const MBParam * const pParam, const FRAMEINFO * const current, const FRAMEINFO * const reference, @@ -236,6 +260,31 @@ const IMAGE * const pRefV, const IMAGE * const pRefHV ); + +int +GlobalMotionEstRefine(WARPPOINTS *const startwp, + MACROBLOCK * const pMBs, + const MBParam * const pParam, + const FRAMEINFO * const current, + const FRAMEINFO * const reference, + const IMAGE * const pCurr, + const IMAGE * const pRef, + const IMAGE * const pRefH, + const IMAGE * const pRefV, + const IMAGE * const pRefHV); + + + + +int +globalSAD(const WARPPOINTS *const wp, + const MBParam * const pParam, + const MACROBLOCK * const pMBs, + const FRAMEINFO * const current, + const IMAGE * const pRef, + const IMAGE * const pCurr, + uint8_t *const GMCblock); + #define iDiamondSize 2 static __inline uint32_t @@ -243,39 +292,39 @@ { 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 (!(VopFlags & XVID_VOP_MODEDECISION_RD)) + Flags &= ~(XVID_ME_QUARTERPELREFINE16_RD+XVID_ME_QUARTERPELREFINE8_RD+XVID_ME_HALFPELREFINE16_RD+XVID_ME_HALFPELREFINE8_RD+XVID_ME_EXTSEARCH_RD); - if (Flags & XVID_ME_EXTSEARCH_BITS) - Flags |= XVID_ME_HALFPELREFINE16_BITS; + if (Flags & XVID_ME_EXTSEARCH_RD) + Flags |= XVID_ME_HALFPELREFINE16_RD; - if (Flags & XVID_ME_EXTSEARCH_BITS && MotionFlags & XVID_ME_EXTSEARCH8) - Flags |= XVID_ME_HALFPELREFINE8_BITS; + if (Flags & XVID_ME_EXTSEARCH_RD && MotionFlags & XVID_ME_EXTSEARCH8) + Flags |= XVID_ME_HALFPELREFINE8_RD; - if (Flags & XVID_ME_HALFPELREFINE16_BITS) - Flags |= XVID_ME_QUARTERPELREFINE16_BITS; + if (Flags & XVID_ME_HALFPELREFINE16_RD) + Flags |= XVID_ME_QUARTERPELREFINE16_RD; - if (Flags & XVID_ME_HALFPELREFINE8_BITS) { - Flags |= XVID_ME_QUARTERPELREFINE8_BITS; + if (Flags & XVID_ME_HALFPELREFINE8_RD) { + Flags |= XVID_ME_QUARTERPELREFINE8_RD; Flags &= ~XVID_ME_HALFPELREFINE8; } - if (Flags & XVID_ME_QUARTERPELREFINE8_BITS) + if (Flags & XVID_ME_QUARTERPELREFINE8_RD) Flags &= ~XVID_ME_QUARTERPELREFINE8; if (!(VolFlags & XVID_VOL_QUARTERPEL)) - Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_BITS+XVID_ME_QUARTERPELREFINE8_BITS); + Flags &= ~(XVID_ME_QUARTERPELREFINE16+XVID_ME_QUARTERPELREFINE8+XVID_ME_QUARTERPELREFINE16_RD+XVID_ME_QUARTERPELREFINE8_RD); if (!(VopFlags & XVID_VOP_HALFPEL)) - Flags &= ~(XVID_ME_EXTSEARCH16+XVID_ME_HALFPELREFINE16+XVID_ME_HALFPELREFINE8+XVID_ME_HALFPELREFINE16_BITS+XVID_ME_HALFPELREFINE8_BITS); + Flags &= ~(XVID_ME_EXTSEARCH16+XVID_ME_HALFPELREFINE16+XVID_ME_HALFPELREFINE8+XVID_ME_HALFPELREFINE16_RD+XVID_ME_HALFPELREFINE8_RD); if ((VopFlags & XVID_VOP_GREYSCALE) || (VopFlags & XVID_VOP_REDUCED)) - Flags &= ~(XVID_ME_CHROMA16 + XVID_ME_CHROMA8); + Flags &= ~(XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP); return Flags; } -/* BITS mode decision and search */ +/* RD mode decision and search */ #include "../bitstream/zigzag.h" #include "../quant/quant_mpeg4.h" @@ -284,20 +333,23 @@ #include "../dct/fdct.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); +findRDinter(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); +findRDinter4v(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); +findRDintra(const SearchData * const Data); + +static int +findRDgmc(const SearchData * const Data, const IMAGE * const vGMC, const int x, const int y); int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); int CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag); @@ -320,24 +372,26 @@ fdct(data); - if (quant_type == 0) sum = quant_inter(coeff, data, quant); + if (quant_type) 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(dqcoeff, coeff, quant); - else dequant4_inter(dqcoeff, coeff, quant); + if (quant_type) dequant_inter(dqcoeff, coeff, quant); + else dequant4_inter(dqcoeff, coeff, quant); - for (i = 0; i < 64; i++) { - distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]); - } + for (i = 0; i < 64; i++) + distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]); - bits += (LAMBDA*distortion)/(quant*quant); + } else { + bits = 0; + for (i = 0; i < 64; i++) + distortion += data[i]*data[i]; + } - return bits; + return bits + (LAMBDA*distortion)/(quant*quant); } static __inline unsigned int @@ -357,7 +411,7 @@ fdct(data); data[0] -= 1024; - if (quant_type == 0) quant_intra(coeff, data, quant, iDcScaler); + if (quant_type) quant_intra(coeff, data, quant, iDcScaler); else quant4_intra(coeff, data, quant, iDcScaler); b_dc = coeff[0]; @@ -373,16 +427,13 @@ else bits += BITS_MULT*dcc_tab[coeff[0] + 255].len; coeff[0] = b_dc; - if (quant_type == 0) dequant_intra(dqcoeff, coeff, quant, iDcScaler); + if (quant_type) dequant_intra(dqcoeff, coeff, quant, iDcScaler); else dequant4_intra(dqcoeff, coeff, quant, iDcScaler); - for (i = 0; i < 64; i++) { + for (i = 0; i < 64; i++) distortion += (data[i] - dqcoeff[i])*(data[i] - dqcoeff[i]); - } - - bits += (LAMBDA*distortion)/(quant*quant); - return bits; + return bits + (LAMBDA*distortion)/(quant*quant); } #endif /* _MOTION_EST_H_ */