Parent Directory
|
Revision Log
Revision 1.11 - (view) (download)
1 : | edgomez | 1.5 | /************************************************************************** |
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 : | suxen_drol | 1.11 | * $Id: mbprediction.h,v 1.10 2002/06/28 15:14:40 suxen_drol Exp $ |
30 : | edgomez | 1.5 | * |
31 : | *************************************************************************/ | ||
32 : | |||
33 : | suxen_drol | 1.10 | /****************************************************************************** |
34 : | * * | ||
35 : | * Revision history: * | ||
36 : | * * | ||
37 : | * 29.06.2002 get_pmvdata() bounding * | ||
38 : | * * | ||
39 : | ******************************************************************************/ | ||
40 : | |||
41 : | |||
42 : | Isibaar | 1.1 | #ifndef _MBPREDICTION_H_ |
43 : | #define _MBPREDICTION_H_ | ||
44 : | |||
45 : | #include "../portab.h" | ||
46 : | #include "../decoder.h" | ||
47 : | #include "../global.h" | ||
48 : | |||
49 : | #define MIN(X, Y) ((X)<(Y)?(X):(Y)) | ||
50 : | #define MAX(X, Y) ((X)>(Y)?(X):(Y)) | ||
51 : | |||
52 : | edgomez | 1.5 | /* very large value */ |
53 : | Isibaar | 1.1 | #define MV_MAX_ERROR (4096 * 256) |
54 : | |||
55 : | #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) | ||
56 : | |||
57 : | edgomez | 1.9 | void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */ |
58 : | |||
59 : | uint32_t x_pos, /* <-- The x position of the MB to be searched */ | ||
60 : | |||
61 : | uint32_t y_pos, /* <-- The y position of the MB to be searched */ | ||
62 : | |||
63 : | uint32_t x_dim, /* <-- Number of macroblocks in a row */ | ||
64 : | |||
65 : | int16_t * qcoeff); /* <-> The quantized DCT coefficients */ | ||
66 : | |||
67 : | void add_acdc(MACROBLOCK * pMB, | ||
68 : | uint32_t block, | ||
69 : | int16_t dct_codes[64], | ||
70 : | uint32_t iDcScaler, | ||
71 : | int16_t predictors[8]); | ||
72 : | |||
73 : | |||
74 : | void predict_acdc(MACROBLOCK * pMBs, | ||
75 : | uint32_t x, | ||
76 : | uint32_t y, | ||
77 : | uint32_t mb_width, | ||
78 : | uint32_t block, | ||
79 : | int16_t qcoeff[64], | ||
80 : | uint32_t current_quant, | ||
81 : | int32_t iDcScaler, | ||
82 : | suxen_drol | 1.10 | int16_t predictors[8], |
83 : | suxen_drol | 1.11 | const int bound); |
84 : | suxen_drol | 1.10 | |
85 : | Isibaar | 1.1 | |
86 : | chl | 1.4 | /* get_pmvdata returns the median predictor and nothing else */ |
87 : | |||
88 : | edgomez | 1.9 | static __inline VECTOR |
89 : | get_pmv(const MACROBLOCK * const pMBs, | ||
90 : | const uint32_t x, | ||
91 : | const uint32_t y, | ||
92 : | const uint32_t x_dim, | ||
93 : | const uint32_t block) | ||
94 : | chl | 1.4 | { |
95 : | |||
96 : | edgomez | 1.5 | int xin1, xin2, xin3; |
97 : | int yin1, yin2, yin3; | ||
98 : | int vec1, vec2, vec3; | ||
99 : | edgomez | 1.9 | VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */ |
100 : | edgomez | 1.5 | VECTOR median; |
101 : | |||
102 : | edgomez | 1.9 | static VECTOR zeroMV = { 0, 0 }; |
103 : | edgomez | 1.5 | uint32_t index = x + y * x_dim; |
104 : | chl | 1.4 | |
105 : | edgomez | 1.5 | /* first row (special case) */ |
106 : | edgomez | 1.9 | if (y == 0 && (block == 0 || block == 1)) { |
107 : | if ((x == 0) && (block == 0)) // first column, first block | ||
108 : | { | ||
109 : | chl | 1.4 | return zeroMV; |
110 : | } | ||
111 : | edgomez | 1.9 | if (block == 1) // second block; has only a left neighbour |
112 : | chl | 1.4 | { |
113 : | return pMBs[index].mvs[0]; | ||
114 : | edgomez | 1.9 | } else { /* block==0, but x!=0, so again, there is a left neighbour */ |
115 : | |||
116 : | return pMBs[index - 1].mvs[1]; | ||
117 : | chl | 1.4 | } |
118 : | edgomez | 1.5 | } |
119 : | chl | 1.4 | |
120 : | /* | ||
121 : | edgomez | 1.5 | * MODE_INTER, vm18 page 48 |
122 : | * MODE_INTER4V vm18 page 51 | ||
123 : | * | ||
124 : | * (x,y-1) (x+1,y-1) | ||
125 : | * [ | ] [ | ] | ||
126 : | * [ 2 | 3 ] [ 2 | ] | ||
127 : | * | ||
128 : | * (x-1,y) (x,y) (x+1,y) | ||
129 : | * [ | 1 ] [ 0 | 1 ] [ 0 | ] | ||
130 : | * [ | 3 ] [ 2 | 3 ] [ | ] | ||
131 : | */ | ||
132 : | chl | 1.4 | |
133 : | edgomez | 1.9 | switch (block) { |
134 : | chl | 1.4 | case 0: |
135 : | edgomez | 1.9 | xin1 = x - 1; |
136 : | yin1 = y; | ||
137 : | vec1 = 1; /* left */ | ||
138 : | xin2 = x; | ||
139 : | yin2 = y - 1; | ||
140 : | vec2 = 2; /* top */ | ||
141 : | xin3 = x + 1; | ||
142 : | yin3 = y - 1; | ||
143 : | vec3 = 2; /* top right */ | ||
144 : | chl | 1.4 | break; |
145 : | case 1: | ||
146 : | edgomez | 1.9 | xin1 = x; |
147 : | yin1 = y; | ||
148 : | vec1 = 0; | ||
149 : | xin2 = x; | ||
150 : | yin2 = y - 1; | ||
151 : | vec2 = 3; | ||
152 : | xin3 = x + 1; | ||
153 : | yin3 = y - 1; | ||
154 : | vec3 = 2; | ||
155 : | edgomez | 1.5 | break; |
156 : | chl | 1.4 | case 2: |
157 : | edgomez | 1.9 | xin1 = x - 1; |
158 : | yin1 = y; | ||
159 : | vec1 = 3; | ||
160 : | xin2 = x; | ||
161 : | yin2 = y; | ||
162 : | vec2 = 0; | ||
163 : | xin3 = x; | ||
164 : | yin3 = y; | ||
165 : | vec3 = 1; | ||
166 : | edgomez | 1.5 | break; |
167 : | chl | 1.4 | default: |
168 : | edgomez | 1.9 | xin1 = x; |
169 : | yin1 = y; | ||
170 : | vec1 = 2; | ||
171 : | xin2 = x; | ||
172 : | yin2 = y; | ||
173 : | vec2 = 0; | ||
174 : | xin3 = x; | ||
175 : | yin3 = y; | ||
176 : | vec3 = 1; | ||
177 : | edgomez | 1.5 | } |
178 : | chl | 1.4 | |
179 : | |||
180 : | edgomez | 1.9 | if (xin1 < 0 || /* yin1 < 0 || */ xin1 >= (int32_t) x_dim) { |
181 : | lneigh = zeroMV; | ||
182 : | } else { | ||
183 : | lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; | ||
184 : | chl | 1.4 | } |
185 : | |||
186 : | edgomez | 1.9 | if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) { |
187 : | chl | 1.4 | tneigh = zeroMV; |
188 : | edgomez | 1.9 | } else { |
189 : | tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; | ||
190 : | chl | 1.4 | } |
191 : | |||
192 : | edgomez | 1.9 | if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) { |
193 : | chl | 1.4 | trneigh = zeroMV; |
194 : | edgomez | 1.9 | } else { |
195 : | chl | 1.4 | trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
196 : | } | ||
197 : | |||
198 : | edgomez | 1.5 | /* median,minimum */ |
199 : | edgomez | 1.9 | |
200 : | median.x = | ||
201 : | MIN(MAX(lneigh.x, tneigh.x), | ||
202 : | MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x))); | ||
203 : | median.y = | ||
204 : | MIN(MAX(lneigh.y, tneigh.y), | ||
205 : | MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y))); | ||
206 : | chl | 1.4 | return median; |
207 : | } | ||
208 : | |||
209 : | |||
210 : | suxen_drol | 1.11 | |
211 : | int | ||
212 : | get_pmvdata2(const MACROBLOCK * const pMBs, | ||
213 : | const uint32_t x, | ||
214 : | const uint32_t y, | ||
215 : | const uint32_t x_dim, | ||
216 : | const uint32_t block, | ||
217 : | VECTOR * const pmv, | ||
218 : | int32_t * const psad, | ||
219 : | const int bound); | ||
220 : | |||
221 : | |||
222 : | Isibaar | 1.1 | /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD |
223 : | instead of only Median MV */ | ||
224 : | |||
225 : | edgomez | 1.9 | static __inline int |
226 : | get_pmvdata(const MACROBLOCK * const pMBs, | ||
227 : | const uint32_t x, | ||
228 : | const uint32_t y, | ||
229 : | const uint32_t x_dim, | ||
230 : | const uint32_t block, | ||
231 : | VECTOR * const pmv, | ||
232 : | suxen_drol | 1.11 | int32_t * const psad) |
233 : | Isibaar | 1.1 | { |
234 : | edgomez | 1.5 | |
235 : | /* | ||
236 : | * pmv are filled with: | ||
237 : | * [0]: Median (or whatever is correct in a special case) | ||
238 : | * [1]: left neighbour | ||
239 : | * [2]: top neighbour | ||
240 : | * [3]: topright neighbour | ||
241 : | * psad are filled with: | ||
242 : | * [0]: minimum of [1] to [3] | ||
243 : | * [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed) | ||
244 : | * [2]: top neighbour's SAD | ||
245 : | * [3]: topright neighbour's SAD | ||
246 : | */ | ||
247 : | |||
248 : | int xin1, xin2, xin3; | ||
249 : | int yin1, yin2, yin3; | ||
250 : | int vec1, vec2, vec3; | ||
251 : | |||
252 : | uint32_t index = x + y * x_dim; | ||
253 : | edgomez | 1.9 | const VECTOR zeroMV = { 0, 0 }; |
254 : | Isibaar | 1.1 | |
255 : | chl | 1.8 | // first row of blocks (special case) |
256 : | suxen_drol | 1.11 | if (y == 0 && (block == 0 || block == 1)) { |
257 : | if ((x == 0) && (block == 0)) // first column, first block | ||
258 : | edgomez | 1.9 | { |
259 : | Isibaar | 1.1 | pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
260 : | chl | 1.8 | psad[0] = 0; |
261 : | psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; | ||
262 : | Isibaar | 1.1 | return 0; |
263 : | } | ||
264 : | edgomez | 1.9 | if (block == 1) // second block; has only a left neighbour |
265 : | Isibaar | 1.1 | { |
266 : | pmv[0] = pmv[1] = pMBs[index].mvs[0]; | ||
267 : | pmv[2] = pmv[3] = zeroMV; | ||
268 : | psad[0] = psad[1] = pMBs[index].sad8[0]; | ||
269 : | chl | 1.8 | psad[2] = psad[3] = MV_MAX_ERROR; |
270 : | Isibaar | 1.1 | return 0; |
271 : | edgomez | 1.9 | } else { /* block==0, but x!=0, so again, there is a left neighbour */ |
272 : | |||
273 : | pmv[0] = pmv[1] = pMBs[index - 1].mvs[1]; | ||
274 : | Isibaar | 1.1 | pmv[2] = pmv[3] = zeroMV; |
275 : | edgomez | 1.9 | psad[0] = psad[1] = pMBs[index - 1].sad8[1]; |
276 : | chl | 1.8 | psad[2] = psad[3] = MV_MAX_ERROR; |
277 : | Isibaar | 1.1 | return 0; |
278 : | } | ||
279 : | edgomez | 1.5 | } |
280 : | Isibaar | 1.1 | |
281 : | /* | ||
282 : | edgomez | 1.5 | * MODE_INTER, vm18 page 48 |
283 : | * MODE_INTER4V vm18 page 51 | ||
284 : | * | ||
285 : | * (x,y-1) (x+1,y-1) | ||
286 : | * [ | ] [ | ] | ||
287 : | * [ 2 | 3 ] [ 2 | ] | ||
288 : | * | ||
289 : | * (x-1,y) (x,y) (x+1,y) | ||
290 : | * [ | 1 ] [ 0 | 1 ] [ 0 | ] | ||
291 : | * [ | 3 ] [ 2 | 3 ] [ | ] | ||
292 : | */ | ||
293 : | Isibaar | 1.1 | |
294 : | edgomez | 1.9 | switch (block) { |
295 : | Isibaar | 1.1 | case 0: |
296 : | edgomez | 1.9 | xin1 = x - 1; |
297 : | yin1 = y; | ||
298 : | vec1 = 1; /* left */ | ||
299 : | xin2 = x; | ||
300 : | yin2 = y - 1; | ||
301 : | vec2 = 2; /* top */ | ||
302 : | xin3 = x + 1; | ||
303 : | yin3 = y - 1; | ||
304 : | vec3 = 2; /* top right */ | ||
305 : | Isibaar | 1.1 | break; |
306 : | case 1: | ||
307 : | edgomez | 1.9 | xin1 = x; |
308 : | yin1 = y; | ||
309 : | vec1 = 0; | ||
310 : | xin2 = x; | ||
311 : | yin2 = y - 1; | ||
312 : | vec2 = 3; | ||
313 : | xin3 = x + 1; | ||
314 : | yin3 = y - 1; | ||
315 : | vec3 = 2; | ||
316 : | edgomez | 1.5 | break; |
317 : | Isibaar | 1.1 | case 2: |
318 : | edgomez | 1.9 | xin1 = x - 1; |
319 : | yin1 = y; | ||
320 : | vec1 = 3; | ||
321 : | xin2 = x; | ||
322 : | yin2 = y; | ||
323 : | vec2 = 0; | ||
324 : | xin3 = x; | ||
325 : | yin3 = y; | ||
326 : | vec3 = 1; | ||
327 : | edgomez | 1.5 | break; |
328 : | Isibaar | 1.1 | default: |
329 : | edgomez | 1.9 | xin1 = x; |
330 : | yin1 = y; | ||
331 : | vec1 = 2; | ||
332 : | xin2 = x; | ||
333 : | yin2 = y; | ||
334 : | vec2 = 0; | ||
335 : | xin3 = x; | ||
336 : | yin3 = y; | ||
337 : | vec3 = 1; | ||
338 : | edgomez | 1.5 | } |
339 : | Isibaar | 1.1 | |
340 : | |||
341 : | edgomez | 1.9 | if (xin1 < 0 || xin1 >= (int32_t) x_dim) { |
342 : | chl | 1.7 | pmv[1] = zeroMV; |
343 : | Isibaar | 1.1 | psad[1] = MV_MAX_ERROR; |
344 : | edgomez | 1.9 | } else { |
345 : | pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; | ||
346 : | psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1]; | ||
347 : | Isibaar | 1.1 | } |
348 : | |||
349 : | edgomez | 1.9 | if (xin2 < 0 || xin2 >= (int32_t) x_dim) { |
350 : | Isibaar | 1.1 | pmv[2] = zeroMV; |
351 : | psad[2] = MV_MAX_ERROR; | ||
352 : | edgomez | 1.9 | } else { |
353 : | pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; | ||
354 : | psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2]; | ||
355 : | Isibaar | 1.1 | } |
356 : | |||
357 : | edgomez | 1.9 | if (xin3 < 0 || xin3 >= (int32_t) x_dim) { |
358 : | Isibaar | 1.1 | pmv[3] = zeroMV; |
359 : | psad[3] = MV_MAX_ERROR; | ||
360 : | edgomez | 1.9 | } else { |
361 : | Isibaar | 1.1 | pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
362 : | edgomez | 1.9 | psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3]; |
363 : | Isibaar | 1.1 | } |
364 : | |||
365 : | edgomez | 1.9 | if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
366 : | pmv[0] = pmv[1]; | ||
367 : | psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); | ||
368 : | chl | 1.7 | return 1; |
369 : | Isibaar | 1.1 | } |
370 : | |||
371 : | edgomez | 1.5 | /* median,minimum */ |
372 : | edgomez | 1.9 | |
373 : | pmv[0].x = | ||
374 : | MIN(MAX(pmv[1].x, pmv[2].x), | ||
375 : | MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); | ||
376 : | pmv[0].y = | ||
377 : | MIN(MAX(pmv[1].y, pmv[2].y), | ||
378 : | MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); | ||
379 : | psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); | ||
380 : | edgomez | 1.5 | |
381 : | Isibaar | 1.1 | return 0; |
382 : | } | ||
383 : | chl | 1.4 | |
384 : | Isibaar | 1.1 | |
385 : | |||
386 : | edgomez | 1.9 | #endif /* _MBPREDICTION_H_ */ |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |