1 |
|
/***************************************************************************** |
2 |
|
* |
3 |
|
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Motion Estimation related header - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Christoph Lampert <gruel@web.de> |
7 |
|
* 2002 Michael Militzer <michael@xvid.org> |
8 |
|
* 2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net> |
9 |
|
* |
10 |
|
* 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 |
12 |
|
* the Free Software Foundation ; either version 2 of the License, or |
13 |
|
* (at your option) any later version. |
14 |
|
* |
15 |
|
* This program is distributed in the hope that it will be useful, |
16 |
|
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
17 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
* GNU General Public License for more details. |
19 |
|
* |
20 |
|
* You should have received a copy of the GNU General Public License |
21 |
|
* along with this program ; if not, write to the Free Software |
22 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
|
* |
24 |
|
* $Id$ |
25 |
|
* |
26 |
|
****************************************************************************/ |
27 |
|
|
28 |
|
#ifndef _ESTIMATION_H_ |
29 |
|
#define _ESTIMATION_H_ |
30 |
|
|
31 |
|
#include "../portab.h" |
32 |
|
#include "../global.h" |
33 |
|
#include "../image/reduced.h" |
34 |
|
|
35 |
|
/* hard coded motion search parameters */ |
36 |
|
|
37 |
|
/* very large value */ |
38 |
|
#define MV_MAX_ERROR (4096 * 256) |
39 |
|
|
40 |
|
/* INTER bias for INTER/INTRA decision; mpeg4 spec suggests 2*nb */ |
41 |
|
#define MV16_INTER_BIAS 450 |
42 |
|
|
43 |
|
/* vector map (vlc delta size) smoother parameters ! float !*/ |
44 |
|
#define NEIGH_TEND_16X16 10.5 |
45 |
|
#define NEIGH_TEND_8X8 40.0 |
46 |
|
#define NEIGH_8X8_BIAS 40 |
47 |
|
|
48 |
|
#define BITS_MULT 16 |
49 |
|
|
50 |
|
#define INITIAL_SKIP_THRESH 10 |
51 |
|
#define FINAL_SKIP_THRESH 50 |
52 |
|
#define MAX_SAD00_FOR_SKIP 20 |
53 |
|
#define MAX_CHROMA_SAD_FOR_SKIP 22 |
54 |
|
|
55 |
|
/* Parameters which control inter/inter4v decision */ |
56 |
|
#define IMV16X16 2 |
57 |
|
|
58 |
|
extern const int xvid_me_lambda_vec16[32]; |
59 |
|
|
60 |
|
#define CHECK_CANDIDATE(X,Y,D) { \ |
61 |
|
CheckCandidate((X),(Y), data, (D) ); } |
62 |
|
|
63 |
|
#define RRV_MV_SCALEDOWN(a) ( (a)>=0 ? (a+1)/2 : (a-1)/2 ) |
64 |
|
|
65 |
|
/* fast ((A)/2)*2 */ |
66 |
|
#define EVEN(A) (((A)<0?(A)+1:(A)) & ~1) |
67 |
|
|
68 |
|
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
69 |
|
|
70 |
|
static const VECTOR zeroMV = { 0, 0 }; |
71 |
|
|
72 |
|
typedef struct |
73 |
|
{ |
74 |
|
/* data modified by CheckCandidates */ |
75 |
|
int32_t iMinSAD[5]; /* smallest SADs found so far */ |
76 |
|
VECTOR currentMV[5]; /* best vectors found so far */ |
77 |
|
VECTOR currentQMV[5]; /* as above, but used during qpel search */ |
78 |
|
int temp[4]; /* temporary space */ |
79 |
|
unsigned int dir; /* 'direction', set when better vector is found */ |
80 |
|
int chromaX, chromaY, chromaSAD; /* info to make ChromaSAD faster */ |
81 |
|
VECTOR currentQMV2; /* extra vector for SubpelRefine_fast */ |
82 |
|
int32_t iMinSAD2; /* extra SAD value for SubpelRefine_fast */ |
83 |
|
|
84 |
|
/* general fields */ |
85 |
|
int max_dx, min_dx, max_dy, min_dy; /* maximum range */ |
86 |
|
uint32_t rounding; /* rounding type in use */ |
87 |
|
VECTOR predMV; /* vector which predicts current vector */ |
88 |
|
const uint8_t * RefP[6]; /* reference pictures - N, V, H, HV, cU, cV */ |
89 |
|
const uint8_t * Cur; /* current picture */ |
90 |
|
const uint8_t *CurU, *CurV; /* current picture - chroma planes */ |
91 |
|
|
92 |
|
uint8_t * RefQ; /* temporary space for interpolations */ |
93 |
|
uint32_t lambda16; /* how much vector bits weight */ |
94 |
|
uint32_t lambda8; /* as above - for inter4v mode */ |
95 |
|
uint32_t iEdgedWidth; /* picture's stride */ |
96 |
|
uint32_t iFcode; /* current fcode */ |
97 |
|
|
98 |
|
int qpel; /* if we're coding in qpel mode */ |
99 |
|
int qpel_precision; /* if X and Y are in qpel precision (refinement probably) */ |
100 |
|
int chroma; /* should we include chroma SAD? */ |
101 |
|
int rrv; /* are we using reduced resolution? */ |
102 |
|
|
103 |
|
/* fields for interpolate and direct modes */ |
104 |
|
const uint8_t * b_RefP[6]; /* backward reference pictures - N, V, H, HV, cU, cV */ |
105 |
|
VECTOR bpredMV; /* backward prediction - used interpolate mode only */ |
106 |
|
uint32_t bFcode; /* backward fcode - used as above */ |
107 |
|
|
108 |
|
/* fields for direct mode */ |
109 |
|
VECTOR directmvF[4]; /* scaled reference vectors */ |
110 |
|
VECTOR directmvB[4]; /* as above */ |
111 |
|
const VECTOR * referencemv; /* pointer to not-scaled reference vectors */ |
112 |
|
|
113 |
|
/* BITS/R-D stuff */ |
114 |
|
int16_t * dctSpace; /* temporary space for dct */ |
115 |
|
uint32_t iQuant; /* current quant */ |
116 |
|
uint32_t quant_type; /* current quant type */ |
117 |
|
unsigned int cbp[2]; /* CBP of the best vector found so far + cbp for inter4v search */ |
118 |
|
const uint16_t * scan_table; /* current scan table */ |
119 |
|
const uint16_t * mpeg_quant_matrices; /* current MPEG quantization matrices */ |
120 |
|
|
121 |
|
} SearchData; |
122 |
|
|
123 |
|
typedef void(CheckFunc)(const int x, const int y, |
124 |
|
SearchData * const Data, |
125 |
|
const unsigned int Direction); |
126 |
|
|
127 |
|
CheckFunc CheckCandidate16no4v; /* shared between p-vop and b-vop search */ |
128 |
|
|
129 |
|
uint8_t * |
130 |
|
xvid_me_interpolate8x8qpel(const int x, const int y, const uint32_t block, |
131 |
|
const uint32_t dir, const SearchData * const data); |
132 |
|
|
133 |
|
uint8_t * |
134 |
|
xvid_me_interpolate16x16qpel(const int x, const int y, const uint32_t dir, |
135 |
|
const SearchData * const data); |
136 |
|
|
137 |
|
int32_t |
138 |
|
xvid_me_ChromaSAD(const int dx, const int dy, SearchData * const data); |
139 |
|
|
140 |
|
int |
141 |
|
xvid_me_SkipDecisionP(const IMAGE * current, const IMAGE * reference, |
142 |
|
const int x, const int y, |
143 |
|
const uint32_t stride, const uint32_t iQuant, int rrv); |
144 |
|
|
145 |
|
#define iDiamondSize 2 |
146 |
|
typedef void |
147 |
|
MainSearchFunc(int x, int y, SearchData * const Data, |
148 |
|
int bDirection, CheckFunc * const CheckCandidate); |
149 |
|
|
150 |
|
MainSearchFunc xvid_me_DiamondSearch, xvid_me_AdvDiamondSearch, xvid_me_SquareSearch; |
151 |
|
|
152 |
|
void |
153 |
|
xvid_me_SubpelRefine(SearchData * const data, CheckFunc * const CheckCandidate); |
154 |
|
|
155 |
|
void |
156 |
|
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate); |
157 |
|
|
158 |
|
void |
159 |
|
xvid_me_ModeDecision_RD(SearchData * const Data, |
160 |
|
MACROBLOCK * const pMB, |
161 |
|
const MACROBLOCK * const pMBs, |
162 |
|
const int x, const int y, |
163 |
|
const MBParam * const pParam, |
164 |
|
const uint32_t MotionFlags, |
165 |
|
const uint32_t VopFlags, |
166 |
|
const uint32_t VolFlags, |
167 |
|
const IMAGE * const pCurrent, |
168 |
|
const IMAGE * const pRef, |
169 |
|
const IMAGE * const vGMC, |
170 |
|
const int coding_type); |
171 |
|
|
172 |
|
void |
173 |
|
xvid_me_ModeDecision_Fast(SearchData * const Data, |
174 |
|
MACROBLOCK * const pMB, |
175 |
|
const MACROBLOCK * const pMBs, |
176 |
|
const int x, const int y, |
177 |
|
const MBParam * const pParam, |
178 |
|
const uint32_t MotionFlags, |
179 |
|
const uint32_t VopFlags, |
180 |
|
const uint32_t VolFlags, |
181 |
|
const IMAGE * const pCurrent, |
182 |
|
const IMAGE * const pRef, |
183 |
|
const IMAGE * const vGMC, |
184 |
|
const int coding_type); |
185 |
|
|
186 |
|
|
187 |
|
#endif /* _ESTIMATION_H_ */ |