1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Motion sad header - |
* - Motion module header - |
5 |
|
* |
6 |
|
* Copyright(C) 2002-2003 Radoslaw Czyz <xvid@syskin.cjb.net> |
7 |
|
* 2002 Michael Militzer <michael@xvid.org> |
8 |
* |
* |
|
* This program is an implementation of a part of one or more MPEG-4 |
|
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
9 |
* |
* |
10 |
* This program is free software; you can redistribute it and/or modify |
* 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 |
* it under the terms of the GNU General Public License as published by |
31 |
#include "../portab.h" |
#include "../portab.h" |
32 |
#include "../global.h" |
#include "../global.h" |
33 |
|
|
|
// fast ((A)/2)*2 |
|
|
#define EVEN(A) (((A)<0?(A)+1:(A)) & ~1) |
|
|
|
|
|
#define MVzero(A) ( ((A).x)==(0) && ((A).y)==(0) ) |
|
|
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
|
|
|
|
34 |
/***************************************************************************** |
/***************************************************************************** |
35 |
* Modified rounding tables -- defined in motion_est.c |
* Modified rounding tables -- defined in estimation_common.c |
36 |
* Original tables see ISO spec tables 7-6 -> 7-9 |
* Original tables see ISO spec tables 7-6 -> 7-9 |
37 |
****************************************************************************/ |
****************************************************************************/ |
38 |
|
|
44 |
/* K = 1 */ |
/* K = 1 */ |
45 |
extern const uint32_t roundtab_79[4]; |
extern const uint32_t roundtab_79[4]; |
46 |
|
|
|
/* |
|
|
* getref: calculate reference image pointer |
|
|
* the decision to use interpolation h/v/hv or the normal image is |
|
|
* based on dx & dy. |
|
|
*/ |
|
|
|
|
|
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 int32_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); |
|
|
} |
|
|
} |
|
47 |
|
|
48 |
void MotionEstimationBVOP(MBParam * const pParam, |
/** MotionEstimation **/ |
49 |
|
|
50 |
|
void MotionEstimation(MBParam * const pParam, |
51 |
|
FRAMEINFO * const current, |
52 |
|
FRAMEINFO * const reference, |
53 |
|
const IMAGE * const pRefH, |
54 |
|
const IMAGE * const pRefV, |
55 |
|
const IMAGE * const pRefHV, |
56 |
|
const IMAGE * const pGMC, |
57 |
|
const uint32_t iLimit, |
58 |
|
const int num_slices); |
59 |
|
|
60 |
|
void |
61 |
|
MotionEstimationBVOP(MBParam * const pParam, |
62 |
FRAMEINFO * const frame, |
FRAMEINFO * const frame, |
|
// forward (past) reference |
|
63 |
const int32_t time_bp, |
const int32_t time_bp, |
64 |
const int32_t time_pp, |
const int32_t time_pp, |
65 |
const MACROBLOCK * const f_mbs, |
const MACROBLOCK * const f_mbs, |
67 |
const IMAGE * const f_refH, |
const IMAGE * const f_refH, |
68 |
const IMAGE * const f_refV, |
const IMAGE * const f_refV, |
69 |
const IMAGE * const f_refHV, |
const IMAGE * const f_refHV, |
|
// backward (future) reference |
|
70 |
const FRAMEINFO * const b_reference, |
const FRAMEINFO * const b_reference, |
71 |
const IMAGE * const b_ref, |
const IMAGE * const b_ref, |
72 |
const IMAGE * const b_refH, |
const IMAGE * const b_refH, |
73 |
const IMAGE * const b_refV, |
const IMAGE * const b_refV, |
74 |
const IMAGE * const b_refHV); |
const IMAGE * const b_refHV, |
75 |
|
const int num_slices); |
76 |
|
|
77 |
void MBMotionCompensationBVOP(MBParam * pParam, |
void |
78 |
MACROBLOCK * const mb, |
GMEanalysis(const MBParam * const pParam, |
79 |
const uint32_t i, |
const FRAMEINFO * const current, |
80 |
const uint32_t j, |
const FRAMEINFO * const reference, |
81 |
IMAGE * const cur, |
const IMAGE * const pRefH, |
82 |
const IMAGE * const f_ref, |
const IMAGE * const pRefV, |
83 |
const IMAGE * const f_refh, |
const IMAGE * const pRefHV, |
84 |
const IMAGE * const f_refv, |
const int num_slices); |
|
const IMAGE * const f_refhv, |
|
|
const IMAGE * const b_ref, |
|
|
const IMAGE * const b_refh, |
|
|
const IMAGE * const b_refv, |
|
|
const IMAGE * const b_refhv, |
|
|
int16_t * dct_codes); |
|
85 |
|
|
86 |
|
WARPPOINTS |
87 |
|
GlobalMotionEst(MACROBLOCK * const pMBs, |
88 |
|
const MBParam * const pParam, |
89 |
|
const FRAMEINFO * const current, |
90 |
|
const FRAMEINFO * const reference, |
91 |
|
const IMAGE * const pRefH, |
92 |
|
const IMAGE * const pRefV, |
93 |
|
const IMAGE * const pRefHV, |
94 |
|
const int num_slices); |
95 |
|
|
96 |
/* GMC stuff. Maybe better put it into a separate file */ |
int |
97 |
|
GlobalMotionEstRefine( |
98 |
|
WARPPOINTS *const startwp, |
99 |
|
MACROBLOCK * const pMBs, |
100 |
|
const MBParam * const pParam, |
101 |
|
const FRAMEINFO * const current, |
102 |
|
const FRAMEINFO * const reference, |
103 |
|
const IMAGE * const pCurr, |
104 |
|
const IMAGE * const pRef, |
105 |
|
const IMAGE * const pRefH, |
106 |
|
const IMAGE * const pRefV, |
107 |
|
const IMAGE * const pRefHV); |
108 |
|
|
109 |
void |
int |
110 |
generate_GMCparameters( const int num_wp, // [input]: number of warppoints |
globalSAD(const WARPPOINTS *const wp, |
111 |
const int res, // [input]: resolution |
const MBParam * const pParam, |
112 |
const WARPPOINTS *const warp, // [input]: warp points |
const MACROBLOCK * const pMBs, |
113 |
const int width, const int height, // [input]: without edges! |
const FRAMEINFO * const current, |
114 |
GMC_DATA *const gmc); // [output] precalculated parameters |
const IMAGE * const pRef, |
115 |
|
const IMAGE * const pCurr, |
116 |
|
uint8_t *const GMCblock); |
117 |
|
|
|
void |
|
|
generate_GMCimage( const GMC_DATA *const gmc_data, // [input] precalculated data |
|
|
const IMAGE *const pRef, // [input] |
|
|
const int mb_width, |
|
|
const int mb_height, |
|
|
const int stride, |
|
|
const int stride2, |
|
|
const int fcode, // [input] some parameters... |
|
|
const int32_t quarterpel, // [input] for rounding avgMV |
|
|
const int reduced_resolution, // [input] ignored |
|
|
const int32_t rounding, // [input] for rounding image data |
|
|
MACROBLOCK *const pMBs, // [output] average motion vectors |
|
|
IMAGE *const pGMC); // [output] full warped image |
|
|
|
|
|
VECTOR generate_GMCimageMB( const GMC_DATA *const gmc_data, /* [input] all precalc data */ |
|
|
const IMAGE *const pRef, // [input] |
|
|
const int mi, const int mj, /* [input] MB position */ |
|
|
const int stride, /* [input] Lumi stride */ |
|
|
const int stride2, /* [input] chroma stride */ |
|
|
const int quarterpel, /* [input] for rounding of AvgMV */ |
|
|
const int rounding, |
|
|
IMAGE *const pGMC); /* [outut] generate image */ |
|
118 |
|
|
119 |
int |
int |
120 |
MEanalysis( const IMAGE * const pRef, |
MEanalysis( const IMAGE * const pRef, |
123 |
const int maxIntra, |
const int maxIntra, |
124 |
const int intraCount, |
const int intraCount, |
125 |
const int bCount, |
const int bCount, |
126 |
const int b_thresh); |
const int b_thresh, |
127 |
|
const MACROBLOCK * const prev_mbs); |
128 |
|
|
129 |
|
/** MotionCompensation **/ |
130 |
|
|
131 |
|
void |
132 |
|
MBMotionCompensation(MACROBLOCK * const mb, |
133 |
|
const uint32_t i, |
134 |
|
const uint32_t j, |
135 |
|
const IMAGE * const ref, |
136 |
|
const IMAGE * const refh, |
137 |
|
const IMAGE * const refv, |
138 |
|
const IMAGE * const refhv, |
139 |
|
const IMAGE * const refGMC, |
140 |
|
IMAGE * const cur, |
141 |
|
int16_t * dct_codes, |
142 |
|
const uint32_t width, |
143 |
|
const uint32_t height, |
144 |
|
const uint32_t edged_width, |
145 |
|
const int32_t quarterpel, |
146 |
|
const int32_t rounding, |
147 |
|
const uint8_t * const tmp); |
148 |
|
|
149 |
|
void |
150 |
|
MBMotionCompensationBVOP(MBParam * pParam, |
151 |
|
MACROBLOCK * const mb, |
152 |
|
const uint32_t i, |
153 |
|
const uint32_t j, |
154 |
|
IMAGE * const cur, |
155 |
|
const IMAGE * const f_ref, |
156 |
|
const IMAGE * const f_refh, |
157 |
|
const IMAGE * const f_refv, |
158 |
|
const IMAGE * const f_refhv, |
159 |
|
const IMAGE * const b_ref, |
160 |
|
const IMAGE * const b_refh, |
161 |
|
const IMAGE * const b_refv, |
162 |
|
const IMAGE * const b_refhv, |
163 |
|
int16_t * dct_codes, |
164 |
|
const uint8_t * const tmp); |
165 |
|
|
166 |
#endif /* _MOTION_H_ */ |
#endif /* _MOTION_H_ */ |