Parent Directory
|
Revision Log
Revision 1.21 - (view) (download)
1 : | edgomez | 1.5 | /************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - MB prediction header file - | ||
5 : | * | ||
6 : | edgomez | 1.19 | * 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 : | edgomez | 1.5 | * (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 : | edgomez | 1.19 | * along with this program; if not, write to the xvid_free Software |
27 : | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 : | edgomez | 1.5 | * |
29 : | syskin | 1.21 | * $Id: mbprediction.h,v 1.20 2003/02/19 21:02:11 edgomez Exp $ |
30 : | edgomez | 1.5 | * |
31 : | *************************************************************************/ | ||
32 : | |||
33 : | syskin | 1.21 | /*************************************************************************** |
34 : | * * | ||
35 : | * Revision history: * | ||
36 : | * * | ||
37 : | * 29.06.2002 get_pmvdata() bounding * | ||
38 : | * * | ||
39 : | ***************************************************************************/ | ||
40 : | edgomez | 1.19 | |
41 : | Isibaar | 1.1 | #ifndef _MBPREDICTION_H_ |
42 : | #define _MBPREDICTION_H_ | ||
43 : | |||
44 : | #include "../portab.h" | ||
45 : | #include "../decoder.h" | ||
46 : | #include "../global.h" | ||
47 : | |||
48 : | #define MIN(X, Y) ((X)<(Y)?(X):(Y)) | ||
49 : | #define MAX(X, Y) ((X)>(Y)?(X):(Y)) | ||
50 : | |||
51 : | edgomez | 1.5 | /* very large value */ |
52 : | Isibaar | 1.1 | #define MV_MAX_ERROR (4096 * 256) |
53 : | |||
54 : | #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) | ||
55 : | |||
56 : | edgomez | 1.9 | void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */ |
57 : | syskin | 1.21 | uint32_t x_pos, /* <-- The x position of the MB to be searched */ |
58 : | uint32_t y_pos, /* <-- The y position of the MB to be searched */ | ||
59 : | uint32_t x_dim, /* <-- Number of macroblocks in a row */ | ||
60 : | int16_t * qcoeff); /* <-> The quantized DCT coefficients */ | ||
61 : | edgomez | 1.9 | |
62 : | void add_acdc(MACROBLOCK * pMB, | ||
63 : | syskin | 1.21 | uint32_t block, |
64 : | int16_t dct_codes[64], | ||
65 : | uint32_t iDcScaler, | ||
66 : | int16_t predictors[8]); | ||
67 : | edgomez | 1.9 | |
68 : | void predict_acdc(MACROBLOCK * pMBs, | ||
69 : | syskin | 1.21 | uint32_t x, |
70 : | uint32_t y, | ||
71 : | uint32_t mb_width, | ||
72 : | uint32_t block, | ||
73 : | int16_t qcoeff[64], | ||
74 : | uint32_t current_quant, | ||
75 : | int32_t iDcScaler, | ||
76 : | int16_t predictors[8], | ||
77 : | suxen_drol | 1.11 | const int bound); |
78 : | suxen_drol | 1.10 | |
79 : | syskin | 1.21 | static const VECTOR zeroMV = { 0, 0 }; |
80 : | edgomez | 1.19 | /* |
81 : | * MODE_INTER, vm18 page 48 | ||
82 : | * MODE_INTER4V vm18 page 51 | ||
83 : | * | ||
84 : | syskin | 1.21 | * (x,y-1) (x+1,y-1) |
85 : | * [ | ] [ | ] | ||
86 : | * [ 2 | 3 ] [ 2 | ] | ||
87 : | edgomez | 1.19 | * |
88 : | syskin | 1.21 | * (x-1,y) (x,y) (x+1,y) |
89 : | * [ | 1 ] [ 0 | 1 ] [ 0 | ] | ||
90 : | * [ | 3 ] [ 2 | 3 ] [ | ] | ||
91 : | edgomez | 1.19 | */ |
92 : | suxen_drol | 1.12 | |
93 : | static __inline VECTOR | ||
94 : | get_pmv2(const MACROBLOCK * const mbs, | ||
95 : | syskin | 1.21 | const int mb_width, |
96 : | const int bound, | ||
97 : | const int x, | ||
98 : | const int y, | ||
99 : | const int block) | ||
100 : | suxen_drol | 1.12 | { |
101 : | syskin | 1.21 | int lx, ly, lz; /* left */ |
102 : | int tx, ty, tz; /* top */ | ||
103 : | int rx, ry, rz; /* top-right */ | ||
104 : | int lpos, tpos, rpos; | ||
105 : | int num_cand = 0, last_cand = 1; | ||
106 : | suxen_drol | 1.12 | |
107 : | VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ | ||
108 : | |||
109 : | switch (block) { | ||
110 : | case 0: | ||
111 : | lx = x - 1; ly = y; lz = 1; | ||
112 : | tx = x; ty = y - 1; tz = 2; | ||
113 : | rx = x + 1; ry = y - 1; rz = 2; | ||
114 : | break; | ||
115 : | case 1: | ||
116 : | lx = x; ly = y; lz = 0; | ||
117 : | tx = x; ty = y - 1; tz = 3; | ||
118 : | rx = x + 1; ry = y - 1; rz = 2; | ||
119 : | break; | ||
120 : | case 2: | ||
121 : | lx = x - 1; ly = y; lz = 3; | ||
122 : | tx = x; ty = y; tz = 0; | ||
123 : | rx = x; ry = y; rz = 1; | ||
124 : | break; | ||
125 : | default: | ||
126 : | lx = x; ly = y; lz = 2; | ||
127 : | tx = x; ty = y; tz = 0; | ||
128 : | rx = x; ry = y; rz = 1; | ||
129 : | } | ||
130 : | |||
131 : | syskin | 1.21 | lpos = lx + ly * mb_width; |
132 : | rpos = rx + ry * mb_width; | ||
133 : | tpos = tx + ty * mb_width; | ||
134 : | |||
135 : | if (lpos >= bound && lx >= 0) { | ||
136 : | num_cand++; | ||
137 : | pmv[1] = mbs[lpos].mvs[lz]; | ||
138 : | } else pmv[1] = zeroMV; | ||
139 : | |||
140 : | if (tpos >= bound) { | ||
141 : | num_cand++; | ||
142 : | last_cand = 2; | ||
143 : | pmv[2] = mbs[tpos].mvs[tz]; | ||
144 : | } else pmv[2] = zeroMV; | ||
145 : | |||
146 : | if (rpos >= bound && rx < mb_width) { | ||
147 : | num_cand++; | ||
148 : | last_cand = 3; | ||
149 : | pmv[3] = mbs[rpos].mvs[rz]; | ||
150 : | } else pmv[3] = zeroMV; | ||
151 : | suxen_drol | 1.12 | |
152 : | syskin | 1.21 | /* If there're more than one candidate, we return the median vector */ |
153 : | |||
154 : | if (num_cand > 1) { | ||
155 : | edgomez | 1.19 | /* set median */ |
156 : | syskin | 1.21 | pmv[0].x = |
157 : | edgomez | 1.19 | MIN(MAX(pmv[1].x, pmv[2].x), |
158 : | MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); | ||
159 : | pmv[0].y = | ||
160 : | MIN(MAX(pmv[1].y, pmv[2].y), | ||
161 : | MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); | ||
162 : | return pmv[0]; | ||
163 : | syskin | 1.21 | } |
164 : | edgomez | 1.19 | |
165 : | syskin | 1.21 | return pmv[last_cand]; /* no point calculating median mv */ |
166 : | edgomez | 1.19 | } |
167 : | |||
168 : | static __inline VECTOR | ||
169 : | get_qpmv2(const MACROBLOCK * const mbs, | ||
170 : | syskin | 1.21 | const int mb_width, |
171 : | const int bound, | ||
172 : | const int x, | ||
173 : | const int y, | ||
174 : | const int block) | ||
175 : | edgomez | 1.19 | { |
176 : | syskin | 1.21 | int lx, ly, lz; /* left */ |
177 : | int tx, ty, tz; /* top */ | ||
178 : | int rx, ry, rz; /* top-right */ | ||
179 : | int lpos, tpos, rpos; | ||
180 : | int num_cand = 0, last_cand = 1; | ||
181 : | edgomez | 1.19 | |
182 : | VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ | ||
183 : | |||
184 : | switch (block) { | ||
185 : | case 0: | ||
186 : | lx = x - 1; ly = y; lz = 1; | ||
187 : | tx = x; ty = y - 1; tz = 2; | ||
188 : | rx = x + 1; ry = y - 1; rz = 2; | ||
189 : | break; | ||
190 : | case 1: | ||
191 : | lx = x; ly = y; lz = 0; | ||
192 : | tx = x; ty = y - 1; tz = 3; | ||
193 : | rx = x + 1; ry = y - 1; rz = 2; | ||
194 : | break; | ||
195 : | case 2: | ||
196 : | lx = x - 1; ly = y; lz = 3; | ||
197 : | tx = x; ty = y; tz = 0; | ||
198 : | rx = x; ry = y; rz = 1; | ||
199 : | break; | ||
200 : | default: | ||
201 : | lx = x; ly = y; lz = 2; | ||
202 : | tx = x; ty = y; tz = 0; | ||
203 : | rx = x; ry = y; rz = 1; | ||
204 : | } | ||
205 : | |||
206 : | syskin | 1.21 | lpos = lx + ly * mb_width; |
207 : | rpos = rx + ry * mb_width; | ||
208 : | tpos = tx + ty * mb_width; | ||
209 : | |||
210 : | if (lpos >= bound && lx >= 0) { | ||
211 : | num_cand++; | ||
212 : | pmv[1] = mbs[lpos].qmvs[lz]; | ||
213 : | } else pmv[1] = zeroMV; | ||
214 : | |||
215 : | if (tpos >= bound) { | ||
216 : | num_cand++; | ||
217 : | last_cand = 2; | ||
218 : | pmv[2] = mbs[tpos].qmvs[tz]; | ||
219 : | } else pmv[2] = zeroMV; | ||
220 : | |||
221 : | if (rpos >= bound && rx < mb_width) { | ||
222 : | num_cand++; | ||
223 : | last_cand = 3; | ||
224 : | pmv[3] = mbs[rpos].qmvs[rz]; | ||
225 : | } else pmv[3] = zeroMV; | ||
226 : | edgomez | 1.19 | |
227 : | syskin | 1.21 | /* If there're more than one candidate, we return the median vector */ |
228 : | |||
229 : | if (num_cand > 1) { | ||
230 : | suxen_drol | 1.12 | /* set median */ |
231 : | syskin | 1.21 | pmv[0].x = |
232 : | suxen_drol | 1.12 | MIN(MAX(pmv[1].x, pmv[2].x), |
233 : | MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); | ||
234 : | pmv[0].y = | ||
235 : | MIN(MAX(pmv[1].y, pmv[2].y), | ||
236 : | MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); | ||
237 : | return pmv[0]; | ||
238 : | syskin | 1.21 | } |
239 : | suxen_drol | 1.12 | |
240 : | syskin | 1.21 | return pmv[last_cand]; /* no point calculating median mv */ |
241 : | suxen_drol | 1.12 | } |
242 : | |||
243 : | edgomez | 1.19 | /* |
244 : | syskin | 1.21 | * pmv are filled with: |
245 : | edgomez | 1.19 | * [0]: Median (or whatever is correct in a special case) |
246 : | * [1]: left neighbour | ||
247 : | * [2]: top neighbour | ||
248 : | * [3]: topright neighbour | ||
249 : | * psad are filled with: | ||
250 : | * [0]: minimum of [1] to [3] | ||
251 : | syskin | 1.21 | * [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed) |
252 : | edgomez | 1.19 | * [2]: top neighbour's SAD |
253 : | * [3]: topright neighbour's SAD | ||
254 : | */ | ||
255 : | syskin | 1.21 | |
256 : | suxen_drol | 1.12 | static __inline int |
257 : | get_pmvdata2(const MACROBLOCK * const mbs, | ||
258 : | syskin | 1.21 | const int mb_width, |
259 : | const int bound, | ||
260 : | const int x, | ||
261 : | const int y, | ||
262 : | const int block, | ||
263 : | VECTOR * const pmv, | ||
264 : | int32_t * const psad) | ||
265 : | suxen_drol | 1.12 | { |
266 : | syskin | 1.21 | int lx, ly, lz; /* left */ |
267 : | int tx, ty, tz; /* top */ | ||
268 : | int rx, ry, rz; /* top-right */ | ||
269 : | int lpos, tpos, rpos; | ||
270 : | int num_cand = 0, last_cand = 1; | ||
271 : | suxen_drol | 1.12 | |
272 : | switch (block) { | ||
273 : | case 0: | ||
274 : | lx = x - 1; ly = y; lz = 1; | ||
275 : | tx = x; ty = y - 1; tz = 2; | ||
276 : | rx = x + 1; ry = y - 1; rz = 2; | ||
277 : | break; | ||
278 : | case 1: | ||
279 : | lx = x; ly = y; lz = 0; | ||
280 : | tx = x; ty = y - 1; tz = 3; | ||
281 : | rx = x + 1; ry = y - 1; rz = 2; | ||
282 : | break; | ||
283 : | case 2: | ||
284 : | lx = x - 1; ly = y; lz = 3; | ||
285 : | tx = x; ty = y; tz = 0; | ||
286 : | rx = x; ry = y; rz = 1; | ||
287 : | break; | ||
288 : | default: | ||
289 : | lx = x; ly = y; lz = 2; | ||
290 : | tx = x; ty = y; tz = 0; | ||
291 : | rx = x; ry = y; rz = 1; | ||
292 : | } | ||
293 : | |||
294 : | syskin | 1.21 | lpos = lx + ly * mb_width; |
295 : | rpos = rx + ry * mb_width; | ||
296 : | tpos = tx + ty * mb_width; | ||
297 : | |||
298 : | if (lpos >= bound && lx >= 0) { | ||
299 : | num_cand++; | ||
300 : | last_cand = 1; | ||
301 : | pmv[1] = mbs[lpos].mvs[lz]; | ||
302 : | suxen_drol | 1.12 | psad[1] = mbs[lpos].sad8[lz]; |
303 : | syskin | 1.21 | } else { |
304 : | pmv[1] = zeroMV; | ||
305 : | suxen_drol | 1.12 | psad[1] = MV_MAX_ERROR; |
306 : | syskin | 1.21 | } |
307 : | suxen_drol | 1.12 | |
308 : | syskin | 1.21 | if (tpos >= bound) { |
309 : | num_cand++; | ||
310 : | last_cand = 2; | ||
311 : | pmv[2]= mbs[tpos].mvs[tz]; | ||
312 : | psad[2] = mbs[tpos].sad8[tz]; | ||
313 : | } else { | ||
314 : | pmv[2] = zeroMV; | ||
315 : | suxen_drol | 1.12 | psad[2] = MV_MAX_ERROR; |
316 : | chl | 1.13 | } |
317 : | |||
318 : | syskin | 1.21 | if (rpos >= bound && rx < mb_width) { |
319 : | num_cand++; | ||
320 : | last_cand = 3; | ||
321 : | pmv[3] = mbs[rpos].mvs[rz]; | ||
322 : | psad[3] = mbs[rpos].sad8[rz]; | ||
323 : | } else { | ||
324 : | pmv[3] = zeroMV; | ||
325 : | psad[3] = MV_MAX_ERROR; | ||
326 : | chl | 1.13 | } |
327 : | |||
328 : | suxen_drol | 1.12 | /* original pmvdata() compatibility hack */ |
329 : | syskin | 1.21 | if (x == 0 && y == 0 && block == 0) { |
330 : | suxen_drol | 1.12 | pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
331 : | psad[0] = 0; | ||
332 : | psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; | ||
333 : | return 0; | ||
334 : | } | ||
335 : | |||
336 : | syskin | 1.21 | /* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
337 : | suxen_drol | 1.12 | if (num_cand == 1) { |
338 : | pmv[0] = pmv[last_cand]; | ||
339 : | psad[0] = psad[last_cand]; | ||
340 : | syskin | 1.21 | // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
341 : | |||
342 : | suxen_drol | 1.12 | /* original pmvdata() compatibility hack */ |
343 : | return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); | ||
344 : | } | ||
345 : | |||
346 : | if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { | ||
347 : | pmv[0] = pmv[1]; | ||
348 : | psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); | ||
349 : | return 1; | ||
350 : | } | ||
351 : | |||
352 : | /* set median, minimum */ | ||
353 : | |||
354 : | pmv[0].x = | ||
355 : | MIN(MAX(pmv[1].x, pmv[2].x), | ||
356 : | MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); | ||
357 : | pmv[0].y = | ||
358 : | MIN(MAX(pmv[1].y, pmv[2].y), | ||
359 : | MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); | ||
360 : | |||
361 : | psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); | ||
362 : | |||
363 : | syskin | 1.21 | return 0; |
364 : | suxen_drol | 1.12 | } |
365 : | Isibaar | 1.1 | |
366 : | edgomez | 1.9 | #endif /* _MBPREDICTION_H_ */ |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |