Parent Directory | Revision Log
Revision 1.15 - (view) (download)
1 : | edgomez | 1.14 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - Prediction module - | ||
5 : | * | ||
6 : | * Copyright (C) 2001-2003 Michael Militzer <isibaar@xvid.org> | ||
7 : | * 2001-2003 Peter Ross <pross@xvid.org> | ||
8 : | * | ||
9 : | * This program is free software ; you can redistribute it and/or modify | ||
10 : | * it under the terms of the GNU General Public License as published by | ||
11 : | * the Free Software Foundation ; either version 2 of the License, or | ||
12 : | * (at your option) any later version. | ||
13 : | * | ||
14 : | * This program is distributed in the hope that it will be useful, | ||
15 : | * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
16 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 : | * GNU General Public License for more details. | ||
18 : | * | ||
19 : | * You should have received a copy of the GNU General Public License | ||
20 : | * along with this program ; if not, write to the Free Software | ||
21 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 : | * | ||
23 : | * $Id$ | ||
24 : | * | ||
25 : | ****************************************************************************/ | ||
26 : | |||
27 : | #include <stdlib.h> | ||
28 : | Isibaar | 1.1 | |
29 : | edgomez | 1.13 | #include "../global.h" |
30 : | Isibaar | 1.1 | #include "../encoder.h" |
31 : | #include "mbprediction.h" | ||
32 : | #include "../utils/mbfunctions.h" | ||
33 : | #include "../bitstream/cbp.h" | ||
34 : | edgomez | 1.13 | #include "../bitstream/mbcoding.h" |
35 : | #include "../bitstream/zigzag.h" | ||
36 : | Isibaar | 1.1 | |
37 : | |||
38 : | edgomez | 1.4 | static int __inline |
39 : | rescale(int predict_quant, | ||
40 : | int current_quant, | ||
41 : | int coeff) | ||
42 : | Isibaar | 1.1 | { |
43 : | edgomez | 1.4 | return (coeff != 0) ? DIV_DIV((coeff) * (predict_quant), |
44 : | (current_quant)) : 0; | ||
45 : | Isibaar | 1.1 | } |
46 : | |||
47 : | |||
48 : | edgomez | 1.4 | static const int16_t default_acdc_values[15] = { |
49 : | Isibaar | 1.1 | 1024, |
50 : | edgomez | 1.2 | 0, 0, 0, 0, 0, 0, 0, |
51 : | 0, 0, 0, 0, 0, 0, 0 | ||
52 : | Isibaar | 1.1 | }; |
53 : | edgomez | 1.8 | |
54 : | |||
55 : | Isibaar | 1.1 | /* get dc/ac prediction direction for a single block and place |
56 : | predictor values into MB->pred_values[j][..] | ||
57 : | */ | ||
58 : | |||
59 : | |||
60 : | edgomez | 1.4 | void |
61 : | predict_acdc(MACROBLOCK * pMBs, | ||
62 : | uint32_t x, | ||
63 : | uint32_t y, | ||
64 : | uint32_t mb_width, | ||
65 : | uint32_t block, | ||
66 : | int16_t qcoeff[64], | ||
67 : | uint32_t current_quant, | ||
68 : | int32_t iDcScaler, | ||
69 : | suxen_drol | 1.5 | int16_t predictors[8], |
70 : | edgomez | 1.15 | const int bound, |
71 : | const int bsversion) | ||
72 : | suxen_drol | 1.5 | |
73 : | Isibaar | 1.1 | { |
74 : | suxen_drol | 1.6 | const int mbpos = (y * mb_width) + x; |
75 : | edgomez | 1.2 | int16_t *left, *top, *diag, *current; |
76 : | Isibaar | 1.1 | |
77 : | edgomez | 1.2 | int32_t left_quant = current_quant; |
78 : | int32_t top_quant = current_quant; | ||
79 : | Isibaar | 1.1 | |
80 : | edgomez | 1.2 | const int16_t *pLeft = default_acdc_values; |
81 : | const int16_t *pTop = default_acdc_values; | ||
82 : | const int16_t *pDiag = default_acdc_values; | ||
83 : | Isibaar | 1.1 | |
84 : | edgomez | 1.14 | uint32_t index = x + y * mb_width; /* current macroblock */ |
85 : | edgomez | 1.4 | int *acpred_direction = &pMBs[index].acpred_directions[block]; |
86 : | Isibaar | 1.1 | uint32_t i; |
87 : | |||
88 : | left = top = diag = current = 0; | ||
89 : | |||
90 : | edgomez | 1.14 | /* grab left,top and diag macroblocks */ |
91 : | Isibaar | 1.1 | |
92 : | edgomez | 1.14 | /* left macroblock */ |
93 : | Isibaar | 1.1 | |
94 : | suxen_drol | 1.5 | if (x && mbpos >= bound + 1 && |
95 : | edgomez | 1.4 | (pMBs[index - 1].mode == MODE_INTRA || |
96 : | pMBs[index - 1].mode == MODE_INTRA_Q)) { | ||
97 : | Isibaar | 1.1 | |
98 : | left = pMBs[index - 1].pred_values[0]; | ||
99 : | left_quant = pMBs[index - 1].quant; | ||
100 : | } | ||
101 : | edgomez | 1.14 | /* top macroblock */ |
102 : | edgomez | 1.4 | |
103 : | suxen_drol | 1.6 | if (mbpos >= bound + (int)mb_width && |
104 : | edgomez | 1.4 | (pMBs[index - mb_width].mode == MODE_INTRA || |
105 : | pMBs[index - mb_width].mode == MODE_INTRA_Q)) { | ||
106 : | Isibaar | 1.1 | |
107 : | top = pMBs[index - mb_width].pred_values[0]; | ||
108 : | top_quant = pMBs[index - mb_width].quant; | ||
109 : | edgomez | 1.2 | } |
110 : | edgomez | 1.14 | /* diag macroblock */ |
111 : | edgomez | 1.4 | |
112 : | suxen_drol | 1.6 | if (x && mbpos >= bound + (int)mb_width + 1 && |
113 : | edgomez | 1.4 | (pMBs[index - 1 - mb_width].mode == MODE_INTRA || |
114 : | pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) { | ||
115 : | Isibaar | 1.1 | |
116 : | diag = pMBs[index - 1 - mb_width].pred_values[0]; | ||
117 : | } | ||
118 : | |||
119 : | edgomez | 1.2 | current = pMBs[index].pred_values[0]; |
120 : | Isibaar | 1.1 | |
121 : | edgomez | 1.14 | /* now grab pLeft, pTop, pDiag _blocks_ */ |
122 : | edgomez | 1.4 | |
123 : | Isibaar | 1.1 | switch (block) { |
124 : | edgomez | 1.4 | |
125 : | case 0: | ||
126 : | if (left) | ||
127 : | Isibaar | 1.1 | pLeft = left + MBPRED_SIZE; |
128 : | edgomez | 1.4 | |
129 : | if (top) | ||
130 : | Isibaar | 1.1 | pTop = top + (MBPRED_SIZE << 1); |
131 : | edgomez | 1.4 | |
132 : | if (diag) | ||
133 : | Isibaar | 1.1 | pDiag = diag + 3 * MBPRED_SIZE; |
134 : | edgomez | 1.4 | |
135 : | Isibaar | 1.1 | break; |
136 : | edgomez | 1.4 | |
137 : | Isibaar | 1.1 | case 1: |
138 : | pLeft = current; | ||
139 : | left_quant = current_quant; | ||
140 : | edgomez | 1.4 | |
141 : | if (top) { | ||
142 : | Isibaar | 1.1 | pTop = top + 3 * MBPRED_SIZE; |
143 : | pDiag = top + (MBPRED_SIZE << 1); | ||
144 : | } | ||
145 : | break; | ||
146 : | edgomez | 1.4 | |
147 : | Isibaar | 1.1 | case 2: |
148 : | edgomez | 1.4 | if (left) { |
149 : | Isibaar | 1.1 | pLeft = left + 3 * MBPRED_SIZE; |
150 : | pDiag = left + MBPRED_SIZE; | ||
151 : | } | ||
152 : | edgomez | 1.4 | |
153 : | Isibaar | 1.1 | pTop = current; |
154 : | top_quant = current_quant; | ||
155 : | |||
156 : | break; | ||
157 : | edgomez | 1.4 | |
158 : | Isibaar | 1.1 | case 3: |
159 : | pLeft = current + (MBPRED_SIZE << 1); | ||
160 : | left_quant = current_quant; | ||
161 : | edgomez | 1.4 | |
162 : | Isibaar | 1.1 | pTop = current + MBPRED_SIZE; |
163 : | top_quant = current_quant; | ||
164 : | edgomez | 1.4 | |
165 : | Isibaar | 1.1 | pDiag = current; |
166 : | edgomez | 1.4 | |
167 : | Isibaar | 1.1 | break; |
168 : | edgomez | 1.4 | |
169 : | Isibaar | 1.1 | case 4: |
170 : | edgomez | 1.4 | if (left) |
171 : | Isibaar | 1.1 | pLeft = left + (MBPRED_SIZE << 2); |
172 : | edgomez | 1.4 | if (top) |
173 : | Isibaar | 1.1 | pTop = top + (MBPRED_SIZE << 2); |
174 : | edgomez | 1.4 | if (diag) |
175 : | Isibaar | 1.1 | pDiag = diag + (MBPRED_SIZE << 2); |
176 : | break; | ||
177 : | edgomez | 1.4 | |
178 : | Isibaar | 1.1 | case 5: |
179 : | edgomez | 1.4 | if (left) |
180 : | Isibaar | 1.1 | pLeft = left + 5 * MBPRED_SIZE; |
181 : | edgomez | 1.4 | if (top) |
182 : | Isibaar | 1.1 | pTop = top + 5 * MBPRED_SIZE; |
183 : | edgomez | 1.4 | if (diag) |
184 : | Isibaar | 1.1 | pDiag = diag + 5 * MBPRED_SIZE; |
185 : | break; | ||
186 : | } | ||
187 : | |||
188 : | edgomez | 1.15 | /* determine ac prediction direction & ac/dc predictor place rescaled ac/dc |
189 : | * predictions into predictors[] for later use */ | ||
190 : | |||
191 : | /* Workaround: Bitstream versions <= 32 used to have a wrong predictor | ||
192 : | * stored as it wasn't clipped to the [-2048, 2047] range. We only | ||
193 : | * use the right predictors for bs versions > 32 */ | ||
194 : | #define BUGGY_CLIPPING_BS_VERSION 32 | ||
195 : | edgomez | 1.14 | if (abs(pLeft[0] - pDiag[0]) < abs(pDiag[0] - pTop[0])) { |
196 : | *acpred_direction = 1; /* vertical */ | ||
197 : | edgomez | 1.13 | predictors[0] = DIV_DIV(pTop[0], iDcScaler); |
198 : | edgomez | 1.15 | if (bsversion == 0 || bsversion > BUGGY_CLIPPING_BS_VERSION) |
199 : | predictors[0] = CLIP(predictors[0], -2048, 2047); | ||
200 : | edgomez | 1.4 | for (i = 1; i < 8; i++) { |
201 : | Isibaar | 1.1 | predictors[i] = rescale(top_quant, current_quant, pTop[i]); |
202 : | } | ||
203 : | edgomez | 1.4 | } else { |
204 : | edgomez | 1.14 | *acpred_direction = 2; /* horizontal */ |
205 : | edgomez | 1.13 | predictors[0] = DIV_DIV(pLeft[0], iDcScaler); |
206 : | edgomez | 1.15 | if (bsversion == 0 || bsversion > BUGGY_CLIPPING_BS_VERSION) |
207 : | predictors[0] = CLIP(predictors[0], -2048, 2047); | ||
208 : | edgomez | 1.4 | for (i = 1; i < 8; i++) { |
209 : | Isibaar | 1.1 | predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]); |
210 : | } | ||
211 : | } | ||
212 : | } | ||
213 : | |||
214 : | |||
215 : | /* decoder: add predictors to dct_codes[] and | ||
216 : | edgomez | 1.14 | store current coeffs to pred_values[] for future prediction |
217 : | Isibaar | 1.1 | */ |
218 : | |||
219 : | |||
220 : | edgomez | 1.4 | void |
221 : | add_acdc(MACROBLOCK * pMB, | ||
222 : | uint32_t block, | ||
223 : | int16_t dct_codes[64], | ||
224 : | uint32_t iDcScaler, | ||
225 : | int16_t predictors[8]) | ||
226 : | Isibaar | 1.1 | { |
227 : | uint8_t acpred_direction = pMB->acpred_directions[block]; | ||
228 : | edgomez | 1.4 | int16_t *pCurrent = pMB->pred_values[block]; |
229 : | Isibaar | 1.1 | uint32_t i; |
230 : | |||
231 : | edgomez | 1.14 | DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]); |
232 : | suxen_drol | 1.6 | |
233 : | edgomez | 1.14 | dct_codes[0] += predictors[0]; /* dc prediction */ |
234 : | edgomez | 1.13 | pCurrent[0] = dct_codes[0] * iDcScaler; |
235 : | Isibaar | 1.1 | |
236 : | edgomez | 1.4 | if (acpred_direction == 1) { |
237 : | for (i = 1; i < 8; i++) { | ||
238 : | Isibaar | 1.1 | int level = dct_codes[i] + predictors[i]; |
239 : | edgomez | 1.4 | |
240 : | edgomez | 1.14 | DPRINTF(XVID_DEBUG_COEFF,"predictor[%i] %i\n",i, predictors[i]); |
241 : | suxen_drol | 1.6 | |
242 : | Isibaar | 1.1 | dct_codes[i] = level; |
243 : | pCurrent[i] = level; | ||
244 : | edgomez | 1.4 | pCurrent[i + 7] = dct_codes[i * 8]; |
245 : | Isibaar | 1.1 | } |
246 : | edgomez | 1.4 | } else if (acpred_direction == 2) { |
247 : | for (i = 1; i < 8; i++) { | ||
248 : | int level = dct_codes[i * 8] + predictors[i]; | ||
249 : | edgomez | 1.14 | DPRINTF(XVID_DEBUG_COEFF,"predictor[%i] %i\n",i*8, predictors[i]); |
250 : | edgomez | 1.4 | |
251 : | dct_codes[i * 8] = level; | ||
252 : | pCurrent[i + 7] = level; | ||
253 : | Isibaar | 1.1 | pCurrent[i] = dct_codes[i]; |
254 : | } | ||
255 : | edgomez | 1.4 | } else { |
256 : | for (i = 1; i < 8; i++) { | ||
257 : | Isibaar | 1.1 | pCurrent[i] = dct_codes[i]; |
258 : | edgomez | 1.4 | pCurrent[i + 7] = dct_codes[i * 8]; |
259 : | Isibaar | 1.1 | } |
260 : | } | ||
261 : | } | ||
262 : | |||
263 : | |||
264 : | |||
265 : | edgomez | 1.14 | /***************************************************************************** |
266 : | ****************************************************************************/ | ||
267 : | Isibaar | 1.1 | |
268 : | /* encoder: subtract predictors from qcoeff[] and calculate S1/S2 | ||
269 : | |||
270 : | edgomez | 1.13 | returns sum of coeefficients *saved* if prediction is enabled |
271 : | |||
272 : | edgomez | 1.2 | S1 = sum of all (qcoeff - prediction) |
273 : | S2 = sum of all qcoeff | ||
274 : | */ | ||
275 : | Isibaar | 1.1 | |
276 : | edgomez | 1.13 | int |
277 : | calc_acdc_coeff(MACROBLOCK * pMB, | ||
278 : | edgomez | 1.4 | uint32_t block, |
279 : | int16_t qcoeff[64], | ||
280 : | uint32_t iDcScaler, | ||
281 : | int16_t predictors[8]) | ||
282 : | Isibaar | 1.1 | { |
283 : | edgomez | 1.4 | int16_t *pCurrent = pMB->pred_values[block]; |
284 : | Isibaar | 1.1 | uint32_t i; |
285 : | edgomez | 1.13 | int S1 = 0, S2 = 0; |
286 : | Isibaar | 1.1 | |
287 : | |||
288 : | /* store current coeffs to pred_values[] for future prediction */ | ||
289 : | |||
290 : | edgomez | 1.13 | pCurrent[0] = qcoeff[0] * iDcScaler; |
291 : | edgomez | 1.4 | for (i = 1; i < 8; i++) { |
292 : | Isibaar | 1.1 | pCurrent[i] = qcoeff[i]; |
293 : | pCurrent[i + 7] = qcoeff[i * 8]; | ||
294 : | edgomez | 1.2 | } |
295 : | Isibaar | 1.1 | |
296 : | /* subtract predictors and store back in predictors[] */ | ||
297 : | |||
298 : | qcoeff[0] = qcoeff[0] - predictors[0]; | ||
299 : | |||
300 : | edgomez | 1.4 | if (pMB->acpred_directions[block] == 1) { |
301 : | for (i = 1; i < 8; i++) { | ||
302 : | Isibaar | 1.1 | int16_t level; |
303 : | |||
304 : | level = qcoeff[i]; | ||
305 : | edgomez | 1.14 | S2 += abs(level); |
306 : | Isibaar | 1.1 | level -= predictors[i]; |
307 : | edgomez | 1.14 | S1 += abs(level); |
308 : | Isibaar | 1.1 | predictors[i] = level; |
309 : | } | ||
310 : | edgomez | 1.14 | } else /* acpred_direction == 2 */ |
311 : | Isibaar | 1.1 | { |
312 : | edgomez | 1.4 | for (i = 1; i < 8; i++) { |
313 : | Isibaar | 1.1 | int16_t level; |
314 : | |||
315 : | edgomez | 1.4 | level = qcoeff[i * 8]; |
316 : | edgomez | 1.14 | S2 += abs(level); |
317 : | Isibaar | 1.1 | level -= predictors[i]; |
318 : | edgomez | 1.14 | S1 += abs(level); |
319 : | Isibaar | 1.1 | predictors[i] = level; |
320 : | } | ||
321 : | |||
322 : | edgomez | 1.2 | } |
323 : | Isibaar | 1.1 | |
324 : | edgomez | 1.4 | |
325 : | edgomez | 1.2 | return S2 - S1; |
326 : | Isibaar | 1.1 | } |
327 : | |||
328 : | |||
329 : | edgomez | 1.13 | |
330 : | /* returns the bits *saved* if prediction is enabled */ | ||
331 : | |||
332 : | int | ||
333 : | calc_acdc_bits(MACROBLOCK * pMB, | ||
334 : | uint32_t block, | ||
335 : | int16_t qcoeff[64], | ||
336 : | uint32_t iDcScaler, | ||
337 : | int16_t predictors[8]) | ||
338 : | { | ||
339 : | const int direction = pMB->acpred_directions[block]; | ||
340 : | int16_t *pCurrent = pMB->pred_values[block]; | ||
341 : | int16_t tmp[8]; | ||
342 : | unsigned int i; | ||
343 : | int Z1, Z2; | ||
344 : | |||
345 : | /* store current coeffs to pred_values[] for future prediction */ | ||
346 : | pCurrent[0] = qcoeff[0] * iDcScaler; | ||
347 : | for (i = 1; i < 8; i++) { | ||
348 : | pCurrent[i] = qcoeff[i]; | ||
349 : | pCurrent[i + 7] = qcoeff[i * 8]; | ||
350 : | } | ||
351 : | |||
352 : | |||
353 : | /* dc prediction */ | ||
354 : | qcoeff[0] = qcoeff[0] - predictors[0]; | ||
355 : | |||
356 : | /* calc cost before ac prediction */ | ||
357 : | Z2 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[0]); | ||
358 : | |||
359 : | /* apply ac prediction & calc cost*/ | ||
360 : | if (direction == 1) { | ||
361 : | for (i = 1; i < 8; i++) { | ||
362 : | tmp[i] = qcoeff[i]; | ||
363 : | qcoeff[i] -= predictors[i]; | ||
364 : | predictors[i] = qcoeff[i]; | ||
365 : | } | ||
366 : | edgomez | 1.14 | }else{ /* acpred_direction == 2 */ |
367 : | edgomez | 1.13 | for (i = 1; i < 8; i++) { |
368 : | tmp[i] = qcoeff[i*8]; | ||
369 : | qcoeff[i*8] -= predictors[i]; | ||
370 : | predictors[i] = qcoeff[i*8]; | ||
371 : | } | ||
372 : | } | ||
373 : | |||
374 : | Z1 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]); | ||
375 : | |||
376 : | /* undo prediction */ | ||
377 : | if (direction == 1) { | ||
378 : | edgomez | 1.14 | for (i = 1; i < 8; i++) |
379 : | edgomez | 1.13 | qcoeff[i] = tmp[i]; |
380 : | edgomez | 1.14 | }else{ /* acpred_direction == 2 */ |
381 : | for (i = 1; i < 8; i++) | ||
382 : | edgomez | 1.13 | qcoeff[i*8] = tmp[i]; |
383 : | } | ||
384 : | |||
385 : | return Z2-Z1; | ||
386 : | } | ||
387 : | |||
388 : | Isibaar | 1.1 | /* apply predictors[] to qcoeff */ |
389 : | |||
390 : | edgomez | 1.4 | void |
391 : | apply_acdc(MACROBLOCK * pMB, | ||
392 : | uint32_t block, | ||
393 : | int16_t qcoeff[64], | ||
394 : | int16_t predictors[8]) | ||
395 : | Isibaar | 1.1 | { |
396 : | edgomez | 1.13 | unsigned int i; |
397 : | Isibaar | 1.1 | |
398 : | edgomez | 1.4 | if (pMB->acpred_directions[block] == 1) { |
399 : | edgomez | 1.14 | for (i = 1; i < 8; i++) |
400 : | Isibaar | 1.1 | qcoeff[i] = predictors[i]; |
401 : | edgomez | 1.4 | } else { |
402 : | edgomez | 1.14 | for (i = 1; i < 8; i++) |
403 : | edgomez | 1.4 | qcoeff[i * 8] = predictors[i]; |
404 : | edgomez | 1.2 | } |
405 : | Isibaar | 1.1 | } |
406 : | |||
407 : | |||
408 : | edgomez | 1.4 | void |
409 : | MBPrediction(FRAMEINFO * frame, | ||
410 : | uint32_t x, | ||
411 : | uint32_t y, | ||
412 : | uint32_t mb_width, | ||
413 : | int16_t qcoeff[6 * 64]) | ||
414 : | Isibaar | 1.1 | { |
415 : | edgomez | 1.2 | |
416 : | int32_t j; | ||
417 : | edgomez | 1.14 | int32_t iDcScaler, iQuant; |
418 : | edgomez | 1.13 | int S = 0; |
419 : | Isibaar | 1.1 | int16_t predictors[6][8]; |
420 : | |||
421 : | suxen_drol | 1.3 | MACROBLOCK *pMB = &frame->mbs[x + y * mb_width]; |
422 : | edgomez | 1.14 | iQuant = pMB->quant; |
423 : | Isibaar | 1.1 | |
424 : | edgomez | 1.2 | if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) { |
425 : | edgomez | 1.4 | |
426 : | for (j = 0; j < 6; j++) { | ||
427 : | edgomez | 1.13 | iDcScaler = get_dc_scaler(iQuant, j<4); |
428 : | Isibaar | 1.1 | |
429 : | edgomez | 1.4 | predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64], |
430 : | edgomez | 1.15 | iQuant, iDcScaler, predictors[j], 0, 0); |
431 : | edgomez | 1.4 | |
432 : | edgomez | 1.14 | if ((frame->vop_flags & XVID_VOP_HQACPRED)) |
433 : | edgomez | 1.13 | S += calc_acdc_bits(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]); |
434 : | else | ||
435 : | S += calc_acdc_coeff(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]); | ||
436 : | edgomez | 1.2 | |
437 : | Isibaar | 1.1 | } |
438 : | |||
439 : | edgomez | 1.14 | if (S<=0) { /* dont predict */ |
440 : | edgomez | 1.13 | for (j = 0; j < 6; j++) |
441 : | Isibaar | 1.1 | pMB->acpred_directions[j] = 0; |
442 : | edgomez | 1.13 | }else{ |
443 : | edgomez | 1.14 | for (j = 0; j < 6; j++) |
444 : | edgomez | 1.4 | apply_acdc(pMB, j, &qcoeff[j * 64], predictors[j]); |
445 : | Isibaar | 1.1 | } |
446 : | edgomez | 1.14 | |
447 : | Isibaar | 1.1 | pMB->cbp = calc_cbp(qcoeff); |
448 : | } | ||
449 : | edgomez | 1.14 | } |
450 : | |||
451 : | static const VECTOR zeroMV = { 0, 0 }; | ||
452 : | |||
453 : | VECTOR | ||
454 : | get_pmv2(const MACROBLOCK * const mbs, | ||
455 : | const int mb_width, | ||
456 : | const int bound, | ||
457 : | const int x, | ||
458 : | const int y, | ||
459 : | const int block) | ||
460 : | { | ||
461 : | int lx, ly, lz; /* left */ | ||
462 : | int tx, ty, tz; /* top */ | ||
463 : | int rx, ry, rz; /* top-right */ | ||
464 : | int lpos, tpos, rpos; | ||
465 : | int num_cand = 0, last_cand = 1; | ||
466 : | |||
467 : | VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ | ||
468 : | |||
469 : | switch (block) { | ||
470 : | case 0: | ||
471 : | lx = x - 1; ly = y; lz = 1; | ||
472 : | tx = x; ty = y - 1; tz = 2; | ||
473 : | rx = x + 1; ry = y - 1; rz = 2; | ||
474 : | break; | ||
475 : | case 1: | ||
476 : | lx = x; ly = y; lz = 0; | ||
477 : | tx = x; ty = y - 1; tz = 3; | ||
478 : | rx = x + 1; ry = y - 1; rz = 2; | ||
479 : | break; | ||
480 : | case 2: | ||
481 : | lx = x - 1; ly = y; lz = 3; | ||
482 : | tx = x; ty = y; tz = 0; | ||
483 : | rx = x; ry = y; rz = 1; | ||
484 : | break; | ||
485 : | default: | ||
486 : | lx = x; ly = y; lz = 2; | ||
487 : | tx = x; ty = y; tz = 0; | ||
488 : | rx = x; ry = y; rz = 1; | ||
489 : | } | ||
490 : | |||
491 : | lpos = lx + ly * mb_width; | ||
492 : | rpos = rx + ry * mb_width; | ||
493 : | tpos = tx + ty * mb_width; | ||
494 : | |||
495 : | if (lpos >= bound && lx >= 0) { | ||
496 : | num_cand++; | ||
497 : | pmv[1] = mbs[lpos].mvs[lz]; | ||
498 : | } else pmv[1] = zeroMV; | ||
499 : | |||
500 : | if (tpos >= bound) { | ||
501 : | num_cand++; | ||
502 : | last_cand = 2; | ||
503 : | pmv[2] = mbs[tpos].mvs[tz]; | ||
504 : | } else pmv[2] = zeroMV; | ||
505 : | |||
506 : | if (rpos >= bound && rx < mb_width) { | ||
507 : | num_cand++; | ||
508 : | last_cand = 3; | ||
509 : | pmv[3] = mbs[rpos].mvs[rz]; | ||
510 : | } else pmv[3] = zeroMV; | ||
511 : | |||
512 : | /* If there're more than one candidate, we return the median vector */ | ||
513 : | |||
514 : | if (num_cand > 1) { | ||
515 : | /* set median */ | ||
516 : | pmv[0].x = | ||
517 : | MIN(MAX(pmv[1].x, pmv[2].x), | ||
518 : | MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); | ||
519 : | pmv[0].y = | ||
520 : | MIN(MAX(pmv[1].y, pmv[2].y), | ||
521 : | MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); | ||
522 : | return pmv[0]; | ||
523 : | } | ||
524 : | |||
525 : | return pmv[last_cand]; /* no point calculating median mv */ | ||
526 : | } | ||
527 : | |||
528 : | VECTOR | ||
529 : | get_qpmv2(const MACROBLOCK * const mbs, | ||
530 : | const int mb_width, | ||
531 : | const int bound, | ||
532 : | const int x, | ||
533 : | const int y, | ||
534 : | const int block) | ||
535 : | { | ||
536 : | int lx, ly, lz; /* left */ | ||
537 : | int tx, ty, tz; /* top */ | ||
538 : | int rx, ry, rz; /* top-right */ | ||
539 : | int lpos, tpos, rpos; | ||
540 : | int num_cand = 0, last_cand = 1; | ||
541 : | |||
542 : | VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ | ||
543 : | |||
544 : | switch (block) { | ||
545 : | case 0: | ||
546 : | lx = x - 1; ly = y; lz = 1; | ||
547 : | tx = x; ty = y - 1; tz = 2; | ||
548 : | rx = x + 1; ry = y - 1; rz = 2; | ||
549 : | break; | ||
550 : | case 1: | ||
551 : | lx = x; ly = y; lz = 0; | ||
552 : | tx = x; ty = y - 1; tz = 3; | ||
553 : | rx = x + 1; ry = y - 1; rz = 2; | ||
554 : | break; | ||
555 : | case 2: | ||
556 : | lx = x - 1; ly = y; lz = 3; | ||
557 : | tx = x; ty = y; tz = 0; | ||
558 : | rx = x; ry = y; rz = 1; | ||
559 : | break; | ||
560 : | default: | ||
561 : | lx = x; ly = y; lz = 2; | ||
562 : | tx = x; ty = y; tz = 0; | ||
563 : | rx = x; ry = y; rz = 1; | ||
564 : | } | ||
565 : | |||
566 : | lpos = lx + ly * mb_width; | ||
567 : | rpos = rx + ry * mb_width; | ||
568 : | tpos = tx + ty * mb_width; | ||
569 : | |||
570 : | if (lpos >= bound && lx >= 0) { | ||
571 : | num_cand++; | ||
572 : | pmv[1] = mbs[lpos].qmvs[lz]; | ||
573 : | } else pmv[1] = zeroMV; | ||
574 : | |||
575 : | if (tpos >= bound) { | ||
576 : | num_cand++; | ||
577 : | last_cand = 2; | ||
578 : | pmv[2] = mbs[tpos].qmvs[tz]; | ||
579 : | } else pmv[2] = zeroMV; | ||
580 : | |||
581 : | if (rpos >= bound && rx < mb_width) { | ||
582 : | num_cand++; | ||
583 : | last_cand = 3; | ||
584 : | pmv[3] = mbs[rpos].qmvs[rz]; | ||
585 : | } else pmv[3] = zeroMV; | ||
586 : | |||
587 : | /* If there're more than one candidate, we return the median vector */ | ||
588 : | |||
589 : | if (num_cand > 1) { | ||
590 : | /* set median */ | ||
591 : | pmv[0].x = | ||
592 : | MIN(MAX(pmv[1].x, pmv[2].x), | ||
593 : | MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); | ||
594 : | pmv[0].y = | ||
595 : | MIN(MAX(pmv[1].y, pmv[2].y), | ||
596 : | MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); | ||
597 : | return pmv[0]; | ||
598 : | } | ||
599 : | edgomez | 1.2 | |
600 : | edgomez | 1.14 | return pmv[last_cand]; /* no point calculating median mv */ |
601 : | suxen_drol | 1.6 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |