1 |
|
/************************************************************************** |
2 |
|
* |
3 |
|
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - MB prediction header file - |
5 |
|
* |
6 |
|
* This program is an implementation of a part of one or more MPEG-4 |
7 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
8 |
|
* to use this software module in hardware or software products are |
9 |
|
* advised that its use may infringe existing patents or copyrights, and |
10 |
|
* any such use would be at such party's own risk. The original |
11 |
|
* developer of this software module and his/her company, and subsequent |
12 |
|
* editors and their companies, will have no liability for use of this |
13 |
|
* software or modifications or derivatives thereof. |
14 |
|
* |
15 |
|
* This program is free software; you can redistribute it and/or modify |
16 |
|
* it under the terms of the GNU General Public License as published by |
17 |
|
* the xvid_free Software Foundation; either version 2 of the License, or |
18 |
|
* (at your option) any later version. |
19 |
|
* |
20 |
|
* This program is distributed in the hope that it will be useful, |
21 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 |
|
* GNU General Public License for more details. |
24 |
|
* |
25 |
|
* You should have received a copy of the GNU General Public License |
26 |
|
* along with this program; if not, write to the xvid_free Software |
27 |
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
28 |
|
* |
29 |
|
* $Id: mbprediction.h,v 1.5 2002-04-28 23:36:28 edgomez Exp $ |
30 |
|
* |
31 |
|
*************************************************************************/ |
32 |
|
|
33 |
#ifndef _MBPREDICTION_H_ |
#ifndef _MBPREDICTION_H_ |
34 |
#define _MBPREDICTION_H_ |
#define _MBPREDICTION_H_ |
35 |
|
|
40 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
41 |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
42 |
|
|
43 |
// very large value |
/* very large value */ |
44 |
#define MV_MAX_ERROR (4096 * 256) |
#define MV_MAX_ERROR (4096 * 256) |
45 |
|
|
46 |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
47 |
|
|
48 |
void MBPrediction(FRAMEINFO *frame, /* <-- the parameter for ACDC and MV prediction */ |
void MBPrediction( |
49 |
|
FRAMEINFO *frame, /* <-- The parameter for ACDC and MV prediction */ |
50 |
uint32_t x_pos, /* <-- The x position of the MB to be searched */ |
uint32_t x_pos, /* <-- The x position of the MB to be searched */ |
51 |
uint32_t y_pos, /* <-- The y position of the MB to be searched */ |
uint32_t y_pos, /* <-- The y position of the MB to be searched */ |
52 |
uint32_t x_dim, /* <-- Number of macroblocks in a row */ |
uint32_t x_dim, /* <-- Number of macroblocks in a row */ |
53 |
int16_t *qcoeff /* <-> The quantized DCT coefficients */ |
int16_t *qcoeff); /* <-> The quantized DCT coefficients */ |
|
); |
|
54 |
|
|
55 |
void add_acdc(MACROBLOCK *pMB, |
void add_acdc(MACROBLOCK *pMB, |
56 |
uint32_t block, |
uint32_t block, |
60 |
|
|
61 |
|
|
62 |
void predict_acdc(MACROBLOCK *pMBs, |
void predict_acdc(MACROBLOCK *pMBs, |
63 |
uint32_t x, uint32_t y, uint32_t mb_width, |
uint32_t x, |
64 |
|
uint32_t y, |
65 |
|
uint32_t mb_width, |
66 |
uint32_t block, |
uint32_t block, |
67 |
int16_t qcoeff[64], |
int16_t qcoeff[64], |
68 |
uint32_t current_quant, |
uint32_t current_quant, |
72 |
/* get_pmvdata returns the median predictor and nothing else */ |
/* get_pmvdata returns the median predictor and nothing else */ |
73 |
|
|
74 |
static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs, |
static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs, |
75 |
const uint32_t x, const uint32_t y, |
const uint32_t x, |
76 |
|
const uint32_t y, |
77 |
const uint32_t x_dim, |
const uint32_t x_dim, |
78 |
const uint32_t block) |
const uint32_t block) |
79 |
{ |
{ |
86 |
|
|
87 |
static VECTOR zeroMV = {0,0}; |
static VECTOR zeroMV = {0,0}; |
88 |
uint32_t index = x + y * x_dim; |
uint32_t index = x + y * x_dim; |
|
// zeroMV.x = zeroMV.y = 0; |
|
89 |
|
|
90 |
// first row (special case) |
/* first row (special case) */ |
91 |
if (y == 0 && (block == 0 || block == 1)) |
if (y == 0 && (block == 0 || block == 1)) |
92 |
{ |
{ |
93 |
if ((x == 0) && (block == 0)) // first column, first block |
if ((x == 0) && (block == 0)) // first column, first block |
105 |
} |
} |
106 |
|
|
107 |
/* |
/* |
108 |
MODE_INTER, vm18 page 48 |
* MODE_INTER, vm18 page 48 |
109 |
MODE_INTER4V vm18 page 51 |
* MODE_INTER4V vm18 page 51 |
110 |
|
* |
111 |
(x,y-1) (x+1,y-1) |
* (x,y-1) (x+1,y-1) |
112 |
[ | ] [ | ] |
* [ | ] [ | ] |
113 |
[ 2 | 3 ] [ 2 | ] |
* [ 2 | 3 ] [ 2 | ] |
114 |
|
* |
115 |
(x-1,y) (x,y) (x+1,y) |
* (x-1,y) (x,y) (x+1,y) |
116 |
[ | 1 ] [ 0 | 1 ] [ 0 | ] |
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
117 |
[ | 3 ] [ 2 | 3 ] [ | ] |
* [ | 3 ] [ 2 | 3 ] [ | ] |
118 |
*/ |
*/ |
119 |
|
|
120 |
switch (block) |
switch (block) |
168 |
trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
169 |
} |
} |
170 |
|
|
171 |
// median,minimum |
/* median,minimum */ |
172 |
|
|
173 |
median.x = MIN(MAX(lneigh.x, tneigh.x), MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x))); |
median.x = MIN(MAX(lneigh.x, tneigh.x), MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x))); |
174 |
median.y = MIN(MAX(lneigh.y, tneigh.y), MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y))); |
median.y = MIN(MAX(lneigh.y, tneigh.y), MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y))); |
186 |
VECTOR * const pmv, |
VECTOR * const pmv, |
187 |
int32_t * const psad) |
int32_t * const psad) |
188 |
{ |
{ |
189 |
/* pmv are filled with: |
|
190 |
[0]: Median (or whatever is correct in a special case) |
/* |
191 |
[1]: left neighbour |
* pmv are filled with: |
192 |
[2]: top neighbour, |
* [0]: Median (or whatever is correct in a special case) |
193 |
[3]: topright neighbour, |
* [1]: left neighbour |
194 |
psad are filled with: |
* [2]: top neighbour |
195 |
[0]: minimum of [1] to [3] |
* [3]: topright neighbour |
196 |
[1]: left neighbour's SAD // [1] to [3] are actually not needed |
* psad are filled with: |
197 |
[2]: top neighbour's SAD, |
* [0]: minimum of [1] to [3] |
198 |
[3]: topright neighbour's SAD, |
* [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed) |
199 |
|
* [2]: top neighbour's SAD |
200 |
|
* [3]: topright neighbour's SAD |
201 |
*/ |
*/ |
202 |
|
|
203 |
int xin1, xin2, xin3; |
int xin1, xin2, xin3; |
236 |
} |
} |
237 |
|
|
238 |
/* |
/* |
239 |
MODE_INTER, vm18 page 48 |
* MODE_INTER, vm18 page 48 |
240 |
MODE_INTER4V vm18 page 51 |
* MODE_INTER4V vm18 page 51 |
241 |
|
* |
242 |
(x,y-1) (x+1,y-1) |
* (x,y-1) (x+1,y-1) |
243 |
[ | ] [ | ] |
* [ | ] [ | ] |
244 |
[ 2 | 3 ] [ 2 | ] |
* [ 2 | 3 ] [ 2 | ] |
245 |
|
* |
246 |
(x-1,y) (x,y) (x+1,y) |
* (x-1,y) (x,y) (x+1,y) |
247 |
[ | 1 ] [ 0 | 1 ] [ 0 | ] |
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
248 |
[ | 3 ] [ 2 | 3 ] [ | ] |
* [ | 3 ] [ 2 | 3 ] [ | ] |
249 |
*/ |
*/ |
250 |
|
|
251 |
switch (block) |
switch (block) |
311 |
return 1; |
return 1; |
312 |
} |
} |
313 |
|
|
314 |
// median,minimum |
/* median,minimum */ |
315 |
|
|
316 |
pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
317 |
pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
318 |
psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]); |
psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]); |
319 |
|
|
320 |
return 0; |
return 0; |
321 |
} |
} |
322 |
|
|