1 |
/************************************************************************** |
/************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Motion header - |
* - Motion sad 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) |
41 |
|
|
42 |
|
#define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) ) |
43 |
|
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
44 |
|
|
45 |
/***************************************************************************** |
/***************************************************************************** |
46 |
* Modified rounding tables -- defined in estimation_common.c |
* Modified rounding tables -- defined in motion_est.c |
47 |
* Original tables see ISO spec tables 7-6 -> 7-9 |
* Original tables see ISO spec tables 7-6 -> 7-9 |
48 |
****************************************************************************/ |
****************************************************************************/ |
49 |
|
|
55 |
/* K = 1 */ |
/* K = 1 */ |
56 |
extern const uint32_t roundtab_79[4]; |
extern const uint32_t roundtab_79[4]; |
57 |
|
|
58 |
|
/* |
59 |
|
* getref: calculate reference image pointer |
60 |
|
* the decision to use interpolation h/v/hv or the normal image is |
61 |
|
* based on dx & dy. |
62 |
|
*/ |
63 |
|
|
64 |
|
static __inline const uint8_t * |
65 |
|
get_ref(const uint8_t * const refn, |
66 |
|
const uint8_t * const refh, |
67 |
|
const uint8_t * const refv, |
68 |
|
const uint8_t * const refhv, |
69 |
|
const uint32_t x, |
70 |
|
const uint32_t y, |
71 |
|
const uint32_t block, /* block dimension, 8 or 16 */ |
72 |
|
const int32_t dx, |
73 |
|
const int32_t dy, |
74 |
|
const int32_t stride) |
75 |
|
{ |
76 |
|
switch (((dx & 1) << 1) + (dy & 1)) { /* ((dx%2)?2:0)+((dy%2)?1:0) */ |
77 |
|
case 0: |
78 |
|
return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); |
79 |
|
case 1: |
80 |
|
return refv + (int) ((x * block + dx / 2) + (y * block + (dy - 1) / 2) * stride); |
81 |
|
case 2: |
82 |
|
return refh + (int) ((x * block + (dx - 1) / 2) + (y * block + dy / 2) * stride); |
83 |
|
default: |
84 |
|
return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block + (dy - 1) / 2) * stride); |
85 |
|
} |
86 |
|
} |
87 |
|
|
88 |
/** MotionEstimation **/ |
void MotionEstimationBVOP(MBParam * const pParam, |
|
|
|
|
bool MotionEstimation(MBParam * const pParam, |
|
|
FRAMEINFO * const current, |
|
|
FRAMEINFO * const reference, |
|
|
const IMAGE * const pRefH, |
|
|
const IMAGE * const pRefV, |
|
|
const IMAGE * const pRefHV, |
|
|
const IMAGE * const pGMC, |
|
|
const uint32_t iLimit); |
|
|
|
|
|
void |
|
|
MotionEstimationBVOP(MBParam * const pParam, |
|
89 |
FRAMEINFO * const frame, |
FRAMEINFO * const frame, |
90 |
|
// forward (past) reference |
91 |
const int32_t time_bp, |
const int32_t time_bp, |
92 |
const int32_t time_pp, |
const int32_t time_pp, |
93 |
const MACROBLOCK * const f_mbs, |
const MACROBLOCK * const f_mbs, |
95 |
const IMAGE * const f_refH, |
const IMAGE * const f_refH, |
96 |
const IMAGE * const f_refV, |
const IMAGE * const f_refV, |
97 |
const IMAGE * const f_refHV, |
const IMAGE * const f_refHV, |
98 |
|
// backward (future) reference |
99 |
const FRAMEINFO * const b_reference, |
const FRAMEINFO * const b_reference, |
100 |
const IMAGE * const b_ref, |
const IMAGE * const b_ref, |
101 |
const IMAGE * const b_refH, |
const IMAGE * const b_refH, |
102 |
const IMAGE * const b_refV, |
const IMAGE * const b_refV, |
103 |
const IMAGE * const b_refHV); |
const IMAGE * const b_refHV); |
104 |
|
|
105 |
void |
void MBMotionCompensationBVOP(MBParam * pParam, |
|
GMEanalysis(const MBParam * const pParam, |
|
|
const FRAMEINFO * const current, |
|
|
const FRAMEINFO * const reference, |
|
|
const IMAGE * const pRefH, |
|
|
const IMAGE * const pRefV, |
|
|
const IMAGE * const pRefHV); |
|
|
|
|
|
WARPPOINTS |
|
|
GlobalMotionEst(MACROBLOCK * const pMBs, |
|
|
const MBParam * const pParam, |
|
|
const FRAMEINFO * const current, |
|
|
const FRAMEINFO * const reference, |
|
|
const IMAGE * const pRefH, |
|
|
const IMAGE * const pRefV, |
|
|
const IMAGE * const pRefHV); |
|
|
|
|
|
int |
|
|
GlobalMotionEstRefine( |
|
|
WARPPOINTS *const startwp, |
|
|
MACROBLOCK * const pMBs, |
|
|
const MBParam * const pParam, |
|
|
const FRAMEINFO * const current, |
|
|
const FRAMEINFO * const reference, |
|
|
const IMAGE * const pCurr, |
|
|
const IMAGE * const pRef, |
|
|
const IMAGE * const pRefH, |
|
|
const IMAGE * const pRefV, |
|
|
const IMAGE * const pRefHV); |
|
|
|
|
|
int |
|
|
globalSAD(const WARPPOINTS *const wp, |
|
|
const MBParam * const pParam, |
|
|
const MACROBLOCK * const pMBs, |
|
|
const FRAMEINFO * const current, |
|
|
const IMAGE * const pRef, |
|
|
const IMAGE * const pCurr, |
|
|
uint8_t *const GMCblock); |
|
|
|
|
|
|
|
|
int |
|
|
MEanalysis( const IMAGE * const pRef, |
|
|
const FRAMEINFO * const Current, |
|
|
const MBParam * const pParam, |
|
|
const int maxIntra, |
|
|
const int intraCount, |
|
|
const int bCount, |
|
|
const int b_thresh); |
|
|
|
|
|
/** MotionCompensation **/ |
|
|
|
|
|
void |
|
|
MBMotionCompensation(MACROBLOCK * const mb, |
|
|
const uint32_t i, |
|
|
const uint32_t j, |
|
|
const IMAGE * const ref, |
|
|
const IMAGE * const refh, |
|
|
const IMAGE * const refv, |
|
|
const IMAGE * const refhv, |
|
|
const IMAGE * const refGMC, |
|
|
IMAGE * const cur, |
|
|
int16_t * dct_codes, |
|
|
const uint32_t width, |
|
|
const uint32_t height, |
|
|
const uint32_t edged_width, |
|
|
const int32_t quarterpel, |
|
|
const int reduced_resolution, |
|
|
const int32_t rounding); |
|
|
|
|
|
void |
|
|
MBMotionCompensationBVOP(MBParam * pParam, |
|
106 |
MACROBLOCK * const mb, |
MACROBLOCK * const mb, |
107 |
const uint32_t i, |
const uint32_t i, |
108 |
const uint32_t j, |
const uint32_t j, |
117 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
118 |
int16_t * dct_codes); |
int16_t * dct_codes); |
119 |
|
|
120 |
|
|
121 |
|
/* GMC stuff. Maybe better put it into a separate file */ |
122 |
|
|
123 |
|
void |
124 |
|
generate_GMCparameters( const int num_wp, // [input]: number of warppoints |
125 |
|
const int res, // [input]: resolution |
126 |
|
const WARPPOINTS *const warp, // [input]: warp points |
127 |
|
const int width, const int height, // [input]: without edges! |
128 |
|
GMC_DATA *const gmc); // [output] precalculated parameters |
129 |
|
|
130 |
|
void |
131 |
|
generate_GMCimage( const GMC_DATA *const gmc_data, // [input] precalculated data |
132 |
|
const IMAGE *const pRef, // [input] |
133 |
|
const int mb_width, |
134 |
|
const int mb_height, |
135 |
|
const int stride, |
136 |
|
const int stride2, |
137 |
|
const int fcode, // [input] some parameters... |
138 |
|
const int32_t quarterpel, // [input] for rounding avgMV |
139 |
|
const int reduced_resolution, // [input] ignored |
140 |
|
const int32_t rounding, // [input] for rounding image data |
141 |
|
MACROBLOCK *const pMBs, // [output] average motion vectors |
142 |
|
IMAGE *const pGMC); // [output] full warped image |
143 |
|
|
144 |
|
VECTOR generate_GMCimageMB( const GMC_DATA *const gmc_data, /* [input] all precalc data */ |
145 |
|
const IMAGE *const pRef, // [input] |
146 |
|
const int mi, const int mj, /* [input] MB position */ |
147 |
|
const int stride, /* [input] Lumi stride */ |
148 |
|
const int stride2, /* [input] chroma stride */ |
149 |
|
const int quarterpel, /* [input] for rounding of AvgMV */ |
150 |
|
const int rounding, |
151 |
|
IMAGE *const pGMC); /* [outut] generate image */ |
152 |
|
|
153 |
|
int |
154 |
|
MEanalysis( const IMAGE * const pRef, |
155 |
|
const FRAMEINFO * const Current, |
156 |
|
const MBParam * const pParam, |
157 |
|
const int maxIntra, |
158 |
|
const int intraCount, |
159 |
|
const int bCount, |
160 |
|
const int b_thresh); |
161 |
|
|
162 |
#endif /* _MOTION_H_ */ |
#endif /* _MOTION_H_ */ |