36 |
#include "../portab.h" |
#include "../portab.h" |
37 |
#include "../global.h" |
#include "../global.h" |
38 |
|
|
39 |
// fast ((A)/2)*2 |
/* fast ((A)/2)*2 */ |
40 |
#define EVEN(A) (((A)<0?(A)+1:(A)) & ~1) |
#define EVEN(A) (((A)<0?(A)+1:(A)) & ~1) |
41 |
|
|
42 |
#define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) ) |
#define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) ) |
43 |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
44 |
|
|
45 |
static const uint32_t roundtab[16] = |
/***************************************************************************** |
46 |
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
* Modified rounding tables -- defined in motion_est.c |
47 |
|
* Original tables see ISO spec tables 7-6 -> 7-9 |
48 |
/* |
****************************************************************************/ |
|
* modified rounding tables |
|
|
* original tables see ISO spec tables 7-6 -> 7-9 |
|
|
*/ |
|
49 |
|
|
50 |
|
extern const uint32_t roundtab[16]; |
51 |
/* K = 4 */ |
/* K = 4 */ |
52 |
static const uint32_t roundtab_76[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 }; |
extern const uint32_t roundtab_76[16]; |
53 |
/* K = 2 */ |
/* K = 2 */ |
54 |
static const uint32_t roundtab_78[8] = { 0, 0, 1, 1, 0, 0, 0, 1 }; |
extern const uint32_t roundtab_78[8]; |
55 |
/* K = 1 */ |
/* K = 1 */ |
56 |
static const uint32_t roundtab_79[4] = { 0, 1, 0, 0 }; |
extern const uint32_t roundtab_79[4]; |
|
|
|
57 |
|
|
58 |
/* |
/* |
59 |
* getref: calculate reference image pointer |
* getref: calculate reference image pointer |
69 |
const uint32_t x, |
const uint32_t x, |
70 |
const uint32_t y, |
const uint32_t y, |
71 |
const uint32_t block, /* block dimension, 8 or 16 */ |
const uint32_t block, /* block dimension, 8 or 16 */ |
|
|
|
72 |
const int32_t dx, |
const int32_t dx, |
73 |
const int32_t dy, |
const int32_t dy, |
74 |
const uint32_t stride) |
const int32_t stride) |
75 |
{ |
{ |
|
|
|
|
|
|
76 |
switch (((dx & 1) << 1) + (dy & 1)) { /* ((dx%2)?2:0)+((dy%2)?1:0) */ |
switch (((dx & 1) << 1) + (dy & 1)) { /* ((dx%2)?2:0)+((dy%2)?1:0) */ |
77 |
case 0: |
case 0: |
78 |
return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); |
return refn + (int) ((x * block + dx / 2) + (y * block + dy / 2) * stride); |
79 |
case 1: |
case 1: |
80 |
return refv + (int) ((x * block + dx / 2) + (y * block + |
return refv + (int) ((x * block + dx / 2) + (y * block + (dy - 1) / 2) * stride); |
|
(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); |
|
81 |
case 2: |
case 2: |
82 |
return refh + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block + |
return refh + (int) ((x * block + (dx - 1) / 2) + (y * block + dy / 2) * stride); |
|
(mv->y) / 2) * stride); |
|
83 |
default: |
default: |
84 |
return refhv + (int) ((x * block + ((mv->x) - 1) / 2) + (y * block + |
return refhv + (int) ((x * block + (dx - 1) / 2) + (y * block + (dy - 1) / 2) * stride); |
|
((mv->y) - |
|
|
1) / 2) * stride); |
|
85 |
} |
} |
|
|
|
86 |
} |
} |
87 |
|
|
88 |
void MotionEstimationBVOP(MBParam * const pParam, |
void MotionEstimationBVOP(MBParam * const pParam, |
89 |
FRAMEINFO * const frame, |
FRAMEINFO * const frame, |
90 |
// forward (past) reference |
/* 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 |
/* backward (future) reference */ |
99 |
const MACROBLOCK * const b_mbs, |
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, |
117 |
const IMAGE * const b_refhv, |
const IMAGE * const b_refhv, |
118 |
int16_t * dct_codes); |
int16_t * dct_codes); |
119 |
|
|
|
void |
|
|
MotionEstimationHinted( MBParam * const pParam, |
|
|
FRAMEINFO * const current, |
|
|
FRAMEINFO * const reference, |
|
|
const IMAGE * const pRefH, |
|
|
const IMAGE * const pRefV, |
|
|
const IMAGE * const pRefHV); |
|
120 |
|
|
121 |
int |
/* GMC stuff. Maybe better put it into a separate file */ |
|
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); |
|
122 |
|
|
123 |
/* used internally only */ |
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 |
static VECTOR |
void |
131 |
GlobalMotionEst(const MACROBLOCK * const pMBs, |
generate_GMCimage( const GMC_DATA *const gmc_data, /* [input] precalculated data */ |
132 |
const MBParam * const pParam, const uint32_t iFcode); |
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_ */ |