1 |
/************************************************************************** |
/************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Motion sad header - |
* - Motion header - |
5 |
* |
* |
6 |
* 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 |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
36 |
#include "../portab.h" |
#include "../portab.h" |
37 |
#include "../global.h" |
#include "../global.h" |
38 |
|
|
39 |
// fast ((A)/2)*2 |
/***************************************************************************** |
40 |
#define EVEN(A) (((A)<0?(A)+1:(A)) & ~1) |
* Modified rounding tables -- defined in estimation_common.c |
41 |
|
* Original tables see ISO spec tables 7-6 -> 7-9 |
42 |
|
****************************************************************************/ |
43 |
|
|
44 |
|
extern const uint32_t roundtab[16]; |
45 |
|
/* K = 4 */ |
46 |
|
extern const uint32_t roundtab_76[16]; |
47 |
|
/* K = 2 */ |
48 |
|
extern const uint32_t roundtab_78[8]; |
49 |
|
/* K = 1 */ |
50 |
|
extern const uint32_t roundtab_79[4]; |
51 |
|
|
|
#define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) ) |
|
|
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
|
52 |
|
|
53 |
/* |
/** MotionEstimation **/ |
|
* getref: calculate reference image pointer |
|
|
* the decision to use interpolation h/v/hv or the normal image is |
|
|
* based on dx & dy. |
|
|
*/ |
|
|
|
|
|
static const uint32_t roundtab[16] = |
|
|
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
|
|
|
|
|
|
|
|
static __inline const uint8_t * |
|
|
get_ref(const uint8_t * const refn, |
|
|
const uint8_t * const refh, |
|
|
const uint8_t * const refv, |
|
|
const uint8_t * const refhv, |
|
|
const uint32_t x, |
|
|
const uint32_t y, |
|
|
const uint32_t block, /* block dimension, 8 or 16 */ |
|
|
|
|
|
const int32_t dx, |
|
|
const int32_t dy, |
|
|
const uint32_t stride) |
|
|
{ |
|
|
|
|
|
|
|
|
switch (((dx & 1) << 1) + (dy & 1)) { /* ((dx%2)?2:0)+((dy%2)?1:0) */ |
|
|
case 0: |
|
|
return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); |
|
|
case 1: |
|
|
return refv + (int) ((x * block + dx / 2) + (y * block + |
|
|
(dy - 1) / 2) * stride); |
|
|
case 2: |
|
|
return refh + (int) ((x * block + (dx - 1) / 2) + (y * block + |
|
|
dy / 2) * stride); |
|
|
default: |
|
|
return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block + |
|
|
(dy - 1) / 2) * stride); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* This is somehow a copy of get_ref, but with MV instead of X,Y */ |
|
|
|
|
|
static __inline const uint8_t * |
|
|
get_ref_mv(const uint8_t * const refn, |
|
|
const uint8_t * const refh, |
|
|
const uint8_t * const refv, |
|
|
const uint8_t * const refhv, |
|
|
const uint32_t x, |
|
|
const uint32_t y, |
|
|
const uint32_t block, /* block dimension, 8 or 16 */ |
|
|
|
|
|
const VECTOR * mv, /* measured in half-pel! */ |
|
|
|
|
|
const uint32_t stride) |
|
|
{ |
|
|
|
|
|
switch ((((mv->x) & 1) << 1) + ((mv->y) & 1)) { |
|
|
case 0: |
|
|
return refn + (int) ((x * block + (mv->x) / 2) + (y * block + |
|
|
(mv->y) / 2) * stride); |
|
|
case 1: |
|
|
return refv + (int) ((x * block + (mv->x) / 2) + (y * block + |
|
|
((mv->y) - 1) / 2) * stride); |
|
|
case 2: |
|
|
return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block + |
|
|
(mv->y) / 2) * stride); |
|
|
default: |
|
|
return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block + |
|
|
((mv->y) - |
|
|
1) / 2) * stride); |
|
|
} |
|
54 |
|
|
55 |
} |
bool MotionEstimation(MBParam * const pParam, |
56 |
|
FRAMEINFO * const current, |
57 |
|
FRAMEINFO * const reference, |
58 |
|
const IMAGE * const pRefH, |
59 |
|
const IMAGE * const pRefV, |
60 |
|
const IMAGE * const pRefHV, |
61 |
|
const IMAGE * const pGMC, |
62 |
|
const uint32_t iLimit); |
63 |
|
|
64 |
void MotionEstimationBVOP(MBParam * const pParam, |
void |
65 |
|
MotionEstimationBVOP(MBParam * const pParam, |
66 |
FRAMEINFO * const frame, |
FRAMEINFO * const frame, |
|
// forward (past) reference |
|
67 |
const int32_t time_bp, |
const int32_t time_bp, |
68 |
const int32_t time_pp, |
const int32_t time_pp, |
69 |
const MACROBLOCK * const f_mbs, |
const MACROBLOCK * const f_mbs, |
71 |
const IMAGE * const f_refH, |
const IMAGE * const f_refH, |
72 |
const IMAGE * const f_refV, |
const IMAGE * const f_refV, |
73 |
const IMAGE * const f_refHV, |
const IMAGE * const f_refHV, |
74 |
// backward (future) reference |
const FRAMEINFO * const b_reference, |
|
const MACROBLOCK * const b_mbs, |
|
75 |
const IMAGE * const b_ref, |
const IMAGE * const b_ref, |
76 |
const IMAGE * const b_refH, |
const IMAGE * const b_refH, |
77 |
const IMAGE * const b_refV, |
const IMAGE * const b_refV, |
78 |
const IMAGE * const b_refHV); |
const IMAGE * const b_refHV); |
79 |
|
|
80 |
void MBMotionCompensationBVOP(MBParam * pParam, |
void |
81 |
|
GMEanalysis(const MBParam * const pParam, |
82 |
|
const FRAMEINFO * const current, |
83 |
|
const FRAMEINFO * const reference, |
84 |
|
const IMAGE * const pRefH, |
85 |
|
const IMAGE * const pRefV, |
86 |
|
const IMAGE * const pRefHV); |
87 |
|
|
88 |
|
WARPPOINTS |
89 |
|
GlobalMotionEst(MACROBLOCK * const pMBs, |
90 |
|
const MBParam * const pParam, |
91 |
|
const FRAMEINFO * const current, |
92 |
|
const FRAMEINFO * const reference, |
93 |
|
const IMAGE * const pRefH, |
94 |
|
const IMAGE * const pRefV, |
95 |
|
const IMAGE * const pRefHV); |
96 |
|
|
97 |
|
int |
98 |
|
GlobalMotionEstRefine( |
99 |
|
WARPPOINTS *const startwp, |
100 |
|
MACROBLOCK * const pMBs, |
101 |
|
const MBParam * const pParam, |
102 |
|
const FRAMEINFO * const current, |
103 |
|
const FRAMEINFO * const reference, |
104 |
|
const IMAGE * const pCurr, |
105 |
|
const IMAGE * const pRef, |
106 |
|
const IMAGE * const pRefH, |
107 |
|
const IMAGE * const pRefV, |
108 |
|
const IMAGE * const pRefHV); |
109 |
|
|
110 |
|
int |
111 |
|
globalSAD(const WARPPOINTS *const wp, |
112 |
|
const MBParam * const pParam, |
113 |
|
const MACROBLOCK * const pMBs, |
114 |
|
const FRAMEINFO * const current, |
115 |
|
const IMAGE * const pRef, |
116 |
|
const IMAGE * const pCurr, |
117 |
|
uint8_t *const GMCblock); |
118 |
|
|
119 |
|
|
120 |
|
int |
121 |
|
MEanalysis( const IMAGE * const pRef, |
122 |
|
const FRAMEINFO * const Current, |
123 |
|
const MBParam * const pParam, |
124 |
|
const int maxIntra, |
125 |
|
const int intraCount, |
126 |
|
const int bCount, |
127 |
|
const int b_thresh, |
128 |
|
const MACROBLOCK * const prev_mbs); |
129 |
|
|
130 |
|
/** MotionCompensation **/ |
131 |
|
|
132 |
|
void |
133 |
|
MBMotionCompensation(MACROBLOCK * const mb, |
134 |
|
const uint32_t i, |
135 |
|
const uint32_t j, |
136 |
|
const IMAGE * const ref, |
137 |
|
const IMAGE * const refh, |
138 |
|
const IMAGE * const refv, |
139 |
|
const IMAGE * const refhv, |
140 |
|
const IMAGE * const refGMC, |
141 |
|
IMAGE * const cur, |
142 |
|
int16_t * dct_codes, |
143 |
|
const uint32_t width, |
144 |
|
const uint32_t height, |
145 |
|
const uint32_t edged_width, |
146 |
|
const int32_t quarterpel, |
147 |
|
const int reduced_resolution, |
148 |
|
const int32_t rounding); |
149 |
|
|
150 |
|
void |
151 |
|
MBMotionCompensationBVOP(MBParam * pParam, |
152 |
MACROBLOCK * const mb, |
MACROBLOCK * const mb, |
153 |
const uint32_t i, |
const uint32_t i, |
154 |
const uint32_t j, |
const uint32_t j, |
163 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
164 |
int16_t * dct_codes); |
int16_t * dct_codes); |
165 |
|
|
|
void |
|
|
MotionEstimationHinted( MBParam * const pParam, |
|
|
FRAMEINFO * const current, |
|
|
FRAMEINFO * const reference, |
|
|
const IMAGE * const pRefH, |
|
|
const IMAGE * const pRefV, |
|
|
const IMAGE * const pRefHV); |
|
|
|
|
|
int |
|
|
MEanalysis( const IMAGE * const pRef, |
|
|
const IMAGE * const pCurrent, |
|
|
MBParam * const pParam, |
|
|
MACROBLOCK * const pMBs, |
|
|
const uint32_t iFcode); |
|
|
|
|
|
int |
|
|
FindFcode( const MBParam * const pParam, |
|
|
const FRAMEINFO * const current); |
|
|
|
|
|
|
|
166 |
#endif /* _MOTION_H_ */ |
#endif /* _MOTION_H_ */ |