1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* motion estimation |
* - Motion Estimation module - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Christoph Lampert <gruel@web.de> |
7 |
|
* Copyright(C) 2002 Michael Militzer <michael@xvid.org> |
8 |
|
* Copyright(C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr> |
9 |
|
* Copyright(C) 2002 chenm001 <chenm001@163.com> |
10 |
* |
* |
11 |
* This program is an implementation of a part of one or more MPEG-4 |
* This program is an implementation of a part of one or more MPEG-4 |
12 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
29 |
* |
* |
30 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
31 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
32 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
33 |
* |
* |
34 |
*************************************************************************/ |
*************************************************************************/ |
35 |
|
|
|
/************************************************************************** |
|
|
* |
|
|
* Modifications: |
|
|
* |
|
|
* 01.05.2002 updated MotionEstimationBVOP |
|
|
* 25.04.2002 partial prevMB conversion |
|
|
* 22.04.2002 remove some compile warning by chenm001 <chenm001@163.com> |
|
|
* 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 <isibaar@videocoding.de> |
|
|
* |
|
|
**************************************************************************/ |
|
|
|
|
36 |
#include <assert.h> |
#include <assert.h> |
37 |
#include <stdio.h> |
#include <stdio.h> |
38 |
#include <stdlib.h> |
#include <stdlib.h> |
154 |
|
|
155 |
MACROBLOCK *const pMB = &pMBs[x + y * iWcount]; |
MACROBLOCK *const pMB = &pMBs[x + y * iWcount]; |
156 |
|
|
157 |
|
if (pMB->mode == MODE_NOT_CODED) |
158 |
|
continue; |
159 |
|
|
160 |
predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
161 |
|
|
162 |
pMB->sad16 = |
pMB->sad16 = |
2859 |
*currMV = pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
*currMV = pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
2860 |
|
|
2861 |
} else { |
} else { |
2862 |
|
|
2863 |
|
bPredEq = get_ipmvdata(pMBs, iWcount, 0, x, y, 0, pmv, psad); |
2864 |
|
|
2865 |
threshA = psad[0]; |
threshA = psad[0]; |
2866 |
threshB = threshA + 256; |
threshB = threshA + 256; |
2867 |
if (threshA < 512) |
if (threshA < 512) |
2871 |
if (threshB > 1792) |
if (threshB > 1792) |
2872 |
threshB = 1792; |
threshB = 1792; |
2873 |
|
|
|
bPredEq = get_ipmvdata(pMBs, iWcount, 0, x, y, 0, pmv, psad); |
|
2874 |
*currMV = pmv[0]; /* current best := prediction */ |
*currMV = pmv[0]; /* current best := prediction */ |
2875 |
} |
} |
2876 |
|
|
3182 |
: mb->mvs[k].y - mb->directmv[k].y); |
: mb->mvs[k].y - mb->directmv[k].y); |
3183 |
|
|
3184 |
d_sad16 += |
d_sad16 += |
3185 |
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, |
3186 |
get_ref_mv(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, |
get_ref_mv(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, |
3187 |
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), |
3188 |
get_ref_mv(b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
get_ref_mv(b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
3189 |
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), |
3190 |
edged_width); |
edged_width); |
3191 |
} |
} |
3192 |
} |
} |