--- trunk/xvidcore/src/motion/motion_est.c 2002/07/28 13:06:46 347 +++ trunk/xvidcore/src/motion/motion_est.c 2002/09/06 16:59:47 430 @@ -1,69 +1,37 @@ -/************************************************************************** +/***************************************************************************** * - * XVID MPEG-4 VIDEO CODEC - * motion estimation + * XVID MPEG-4 VIDEO CODEC + * - Motion Estimation module - * - * This program is an implementation of a part of one or more MPEG-4 - * Video tools as specified in ISO/IEC 14496-2 standard. Those intending - * to use this software module in hardware or software products are - * advised that its use may infringe existing patents or copyrights, and - * any such use would be at such party's own risk. The original - * developer of this software module and his/her company, and subsequent - * editors and their companies, will have no liability for use of this - * software or modifications or derivatives thereof. + * Copyright(C) 2002 Christoph Lampert + * Copyright(C) 2002 Michael Militzer + * Copyright(C) 2002 Edouard Gomez + * Copyright(C) 2002 chenm001 * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is an implementation of a part of one or more MPEG-4 + * Video tools as specified in ISO/IEC 14496-2 standard. Those intending + * to use this software module in hardware or software products are + * advised that its use may infringe existing patents or copyrights, and + * any such use would be at such party's own risk. The original + * developer of this software module and his/her company, and subsequent + * editors and their companies, will have no liability for use of this + * software or modifications or derivatives thereof. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - *************************************************************************/ - -/************************************************************************** - * - * Modifications: - * - * 01.05.2002 updated MotionEstimationBVOP - * 25.04.2002 partial prevMB conversion - * 22.04.2002 remove some compile warning by chenm001 - * 14.04.2002 added MotionEstimationBVOP() - * 02.04.2002 add EPZS(^2) as ME algorithm, use PMV_USESQUARES to choose between - * EPZS and EPZS^2 - * 08.02.2002 split up PMVfast into three routines: PMVFast, PMVFast_MainLoop - * PMVFast_Refine to support multiple searches with different start points - * 07.01.2002 uv-block-based interpolation - * 06.01.2002 INTER/INTRA-decision is now done before any SEARCH8 (speedup) - * changed INTER_BIAS to 150 (as suggested by suxen_drol) - * removed halfpel refinement step in PMVfastSearch8 + quality=5 - * added new quality mode = 6 which performs halfpel refinement - * filesize difference between quality 5 and 6 is smaller than 1% - * (Isibaar) - * 31.12.2001 PMVfastSearch16 and PMVfastSearch8 (gruel) - * 30.12.2001 get_range/MotionSearchX simplified; blue/green bug fix - * 22.12.2001 commented best_point==99 check - * 19.12.2001 modified get_range (purple bug fix) - * 15.12.2001 moved pmv displacement from mbprediction - * 02.12.2001 motion estimation/compensation split (Isibaar) - * 16.11.2001 rewrote/tweaked search algorithms; pross@cs.rmit.edu.au - * 10.11.2001 support for sad16/sad8 functions - * 28.08.2001 reactivated MODE_INTER4V for EXT_MODE - * 24.08.2001 removed MODE_INTER4V_Q, disabled MODE_INTER4V for EXT_MODE - * 22.08.2001 added MODE_INTER4V_Q - * 20.08.2001 added pragma to get rid of internal compiler error with VC6 - * idea by Cyril. Thanks. - * - * Michael Militzer + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - **************************************************************************/ + *************************************************************************/ #include #include @@ -186,6 +154,9 @@ MACROBLOCK *const pMB = &pMBs[x + y * iWcount]; + if (pMB->mode == MODE_NOT_CODED) + continue; + predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); pMB->sad16 = @@ -2888,6 +2859,9 @@ *currMV = pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; } else { + + bPredEq = get_ipmvdata(pMBs, iWcount, 0, x, y, 0, pmv, psad); + threshA = psad[0]; threshB = threshA + 256; if (threshA < 512) @@ -2897,7 +2871,6 @@ if (threshB > 1792) threshB = 1792; - bPredEq = get_ipmvdata(pMBs, iWcount, 0, x, y, 0, pmv, psad); *currMV = pmv[0]; /* current best := prediction */ } @@ -3209,11 +3182,11 @@ : mb->mvs[k].y - mb->directmv[k].y); d_sad16 += - sad8bi(frame->image.y + 2*(i+(k&1))*8 + 2*(j+(k>>1))*8*edged_width, + sad8bi(frame->image.y + (2*i+(k&1))*8 + (2*j+(k>>1))*8*edged_width, get_ref_mv(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, - 2*(i+(k&1)), 2*(j+(k>>1)), 8, &mb->mvs[k], edged_width), + (2*i+(k&1)), (2*j+(k>>1)), 8, &mb->mvs[k], edged_width), get_ref_mv(b_ref->y, b_refH->y, b_refV->y, b_refHV->y, - 2*(i+(k&1)), 2*(j+(k>>1)), 8, &mb->b_mvs[k], edged_width), + (2*i+(k&1)), (2*j+(k>>1)), 8, &mb->b_mvs[k], edged_width), edged_width); } } @@ -3297,14 +3270,31 @@ f_predMV.x, f_predMV.y, b_predMV.x, b_predMV.y, f_min_dx, f_max_dx, f_min_dy, f_max_dy, b_min_dx, b_max_dx, b_min_dy, b_max_dy, - edged_width, 1, + edged_width, 2, frame->fcode, frame->bcode,frame->quant,0); + i_sad16 = Diamond16_InterpolMainSearch( + f_ref->y, f_refH->y, f_refV->y, f_refHV->y, + frame->image.y + i * 16 + j * 16 * edged_width, + b_ref->y, b_refH->y, b_refV->y, b_refHV->y, + i, j, + f_interpolMV.x, f_interpolMV.y, + b_interpolMV.x, b_interpolMV.y, + i_sad16, + &f_interpolMV, &b_interpolMV, + f_predMV.x, f_predMV.y, b_predMV.x, b_predMV.y, + f_min_dx, f_max_dx, f_min_dy, f_max_dy, + b_min_dx, b_max_dx, b_min_dy, b_max_dy, + edged_width, 1, + frame->fcode, frame->bcode,frame->quant,0); // equiv to halfpel refine + /* DIRECT MODE DELTA VECTOR SEARCH. This has to be made more effective, but at the moment I'm happy it's running at all */ -/* range is taken without fcode restriction, just a hack instead of writing down the dimensions, of course */ +/* There are two range restrictions for direct mode: deltaMV is limited to [-32,31] in halfpel units, and + absolute vector must not lie outside of image dimensions. Constraint one is dealt with by CHECK_MV16_DIRECT + and for constraint two we need distance to boundary. This is done by get_range very large fcode (hack!) */ get_range(&min_dx, &max_dx, &min_dy, &max_dy, i, j, 16, iWidth, iHeight, 19); @@ -3317,9 +3307,22 @@ 0,0, d_sad16, &mb->deltamv, - mb->directmv, // this has to be pre-initialized with b_mb->mvs[} + mb->directmv, // this has to be pre-initialized with b_mb->mvs[] + min_dx, max_dx, min_dy, max_dy, + edged_width, 2, frame->quant, 0); + + d_sad16 = Diamond16_DirectMainSearch( + f_ref->y, f_refH->y, f_refV->y, f_refHV->y, + frame->image.y + i*16 + j*16*edged_width, + b_ref->y, b_refH->y, b_refV->y, b_refHV->y, + i, j, + TRB,TRD, + mb->deltamv.x, mb->deltamv.y, + d_sad16, + &mb->deltamv, + mb->directmv, // this has to be pre-initialized with b_mb->mvs[] min_dx, max_dx, min_dy, max_dy, - edged_width, 1, frame->quant, 0); + edged_width, 1, frame->quant, 0); // equiv to halfpel refine // i_sad16 = 65535; /* remove the comment to disable any of the MODEs */