1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* motion estimation |
* - Motion Estimation related code - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2002 Christoph Lampert <gruel@web.de> |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* 2002 Michael Militzer <michael@xvid.org> |
8 |
* to use this software module in hardware or software products are |
* 2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net> |
|
* 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. |
|
9 |
* |
* |
10 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
11 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* |
* |
20 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
21 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
|
* |
24 |
|
* $Id: motion_est.c,v 1.58.2.18 2003-06-19 09:58:57 syskin Exp $ |
25 |
* |
* |
26 |
*************************************************************************/ |
****************************************************************************/ |
27 |
|
|
28 |
#include <assert.h> |
#include <assert.h> |
29 |
#include <stdio.h> |
#include <stdio.h> |
672 |
|
|
673 |
bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
bits += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
674 |
|
|
675 |
|
if (data->temp[0] + t < data->iMinSAD[1]) { |
676 |
|
data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; } |
677 |
|
if (data->temp[1] < data->iMinSAD[2]) { |
678 |
|
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
679 |
|
if (data->temp[2] < data->iMinSAD[3]) { |
680 |
|
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
681 |
|
if (data->temp[3] < data->iMinSAD[4]) { |
682 |
|
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
683 |
|
|
684 |
bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len; |
bits += BITS_MULT*xvid_cbpy_tab[15-(cbp>>2)].len; |
685 |
|
|
686 |
if (bits >= data->iMinSAD[0]) return; |
if (bits >= data->iMinSAD[0]) return; |
707 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
708 |
*dir = Direction; |
*dir = Direction; |
709 |
} |
} |
|
|
|
|
if (data->temp[0] + t < data->iMinSAD[1]) { |
|
|
data->iMinSAD[1] = data->temp[0] + t; current[1].x = x; current[1].y = y; } |
|
|
if (data->temp[1] < data->iMinSAD[2]) { |
|
|
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
|
|
if (data->temp[2] < data->iMinSAD[3]) { |
|
|
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
|
|
if (data->temp[3] < data->iMinSAD[4]) { |
|
|
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
|
|
|
|
710 |
} |
} |
711 |
|
|
712 |
static void |
static void |
713 |
CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateBits8(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
714 |
{ |
{ |
1290 |
Data->iMinSAD[3] = pMB->sad8[2]; |
Data->iMinSAD[3] = pMB->sad8[2]; |
1291 |
Data->iMinSAD[4] = pMB->sad8[3]; |
Data->iMinSAD[4] = pMB->sad8[3]; |
1292 |
|
|
1293 |
if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) || (x | y)) { |
if ((!(VopFlags & XVID_VOP_MODEDECISION_BITS)) && (x | y)) { |
1294 |
threshA = Data->temp[0]; /* that's where we keep this SAD atm */ |
threshA = Data->temp[0]; /* that's where we keep this SAD atm */ |
1295 |
if (threshA < 512) threshA = 512; |
if (threshA < 512) threshA = 512; |
1296 |
else if (threshA > 1024) threshA = 1024; |
else if (threshA > 1024) threshA = 1024; |