12 |
* editors and their companies, will have no liability for use of this |
* editors and their companies, will have no liability for use of this |
13 |
* software or modifications or derivatives thereof. |
* software or modifications or derivatives thereof. |
14 |
* |
* |
15 |
* This program is free software; you can redistribute it and/or modify |
* This program is xvid_free software; you can redistribute it and/or modify |
16 |
* 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 |
17 |
* the Free Software Foundation; either version 2 of the License, or |
* the xvid_free Software Foundation; either version 2 of the License, or |
18 |
* (at your option) any later version. |
* (at your option) any later version. |
19 |
* |
* |
20 |
* This program is distributed in the hope that it will be useful, |
* This program is distributed in the hope that it will be useful, |
23 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
24 |
* |
* |
25 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the xvid_free Software |
27 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
28 |
* |
* |
29 |
*************************************************************************/ |
*************************************************************************/ |
32 |
* |
* |
33 |
* History: |
* History: |
34 |
* |
* |
35 |
|
* 26.03.2002 interlacing support - moved transfers outside decode loop |
36 |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
37 |
* 22.12.2001 block based interpolation |
* 22.12.2001 block based interpolation |
38 |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
55 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
56 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
57 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
58 |
|
#include "utils/mbfunctions.h" |
59 |
|
|
60 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
61 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
64 |
|
|
65 |
#include "image/image.h" |
#include "image/image.h" |
66 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
67 |
|
#include "utils/mem_align.h" |
68 |
|
|
69 |
int decoder_create(XVID_DEC_PARAM * param) |
int decoder_create(XVID_DEC_PARAM * param) |
70 |
{ |
{ |
71 |
DECODER * dec; |
DECODER * dec; |
72 |
|
|
73 |
dec = malloc(sizeof(DECODER)); |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
74 |
if (dec == NULL) |
if (dec == NULL) |
75 |
{ |
{ |
76 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
88 |
|
|
89 |
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) |
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) |
90 |
{ |
{ |
91 |
free(dec); |
xvid_free(dec); |
92 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
93 |
} |
} |
94 |
|
|
95 |
if (image_create(&dec->refn, dec->edged_width, dec->edged_height)) |
if (image_create(&dec->refn, dec->edged_width, dec->edged_height)) |
96 |
{ |
{ |
97 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
98 |
free(dec); |
xvid_free(dec); |
99 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
100 |
} |
} |
101 |
|
|
102 |
dec->mbs = malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE); |
103 |
if (dec->mbs == NULL) |
if (dec->mbs == NULL) |
104 |
{ |
{ |
105 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
106 |
free(dec); |
xvid_free(dec); |
107 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
108 |
} |
} |
109 |
|
|
116 |
|
|
117 |
int decoder_destroy(DECODER * dec) |
int decoder_destroy(DECODER * dec) |
118 |
{ |
{ |
119 |
free(dec->mbs); |
xvid_free(dec->mbs); |
120 |
image_destroy(&dec->refn, dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn, dec->edged_width, dec->edged_height); |
121 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
122 |
free(dec); |
xvid_free(dec); |
123 |
|
|
124 |
destroy_vlc_tables(); |
destroy_vlc_tables(); |
125 |
|
|
137 |
|
|
138 |
// decode an intra macroblock |
// decode an intra macroblock |
139 |
|
|
140 |
void decoder_mbintra(DECODER * dec, MACROBLOCK * mb, int x, int y, uint32_t acpred_flag, uint32_t cbp, Bitstream * bs, int quant, int intra_dc_threshold) |
void decoder_mbintra(DECODER * dec, |
141 |
|
MACROBLOCK * pMB, |
142 |
|
const uint32_t x_pos, |
143 |
|
const uint32_t y_pos, |
144 |
|
const uint32_t acpred_flag, |
145 |
|
const uint32_t cbp, |
146 |
|
Bitstream * bs, |
147 |
|
const uint32_t quant, |
148 |
|
const uint32_t intra_dc_threshold) |
149 |
{ |
{ |
|
uint32_t k; |
|
150 |
|
|
151 |
for (k = 0; k < 6; k++) |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
152 |
|
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
153 |
|
|
154 |
|
const uint32_t stride = dec->edged_width; |
155 |
|
uint32_t i; |
156 |
|
uint32_t iQuant = pMB->quant; |
157 |
|
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
158 |
|
|
159 |
|
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
160 |
|
pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
161 |
|
pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
162 |
|
|
163 |
|
memset(block, 0, 6*64*sizeof(int16_t)); // clear |
164 |
|
|
165 |
|
for (i = 0; i < 6; i++) |
166 |
{ |
{ |
167 |
uint32_t dcscalar; |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
|
int16_t block[64]; |
|
|
int16_t data[64]; |
|
168 |
int16_t predictors[8]; |
int16_t predictors[8]; |
169 |
int start_coeff; |
int start_coeff; |
170 |
|
|
|
dcscalar = get_dc_scaler(mb->quant, k < 4); |
|
|
|
|
171 |
start_timer(); |
start_timer(); |
172 |
predict_acdc(dec->mbs, x, y, dec->mb_width, k, block, mb->quant, dcscalar, predictors); |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i*64], iQuant, iDcScaler, predictors); |
173 |
if (!acpred_flag) |
if (!acpred_flag) |
174 |
{ |
{ |
175 |
mb->acpred_directions[k] = 0; |
pMB->acpred_directions[i] = 0; |
176 |
} |
} |
177 |
stop_prediction_timer(); |
stop_prediction_timer(); |
178 |
|
|
|
memset(block, 0, 64*sizeof(int16_t)); // clear |
|
|
|
|
179 |
if (quant < intra_dc_threshold) |
if (quant < intra_dc_threshold) |
180 |
{ |
{ |
181 |
int dc_size; |
int dc_size; |
182 |
int dc_dif; |
int dc_dif; |
183 |
|
|
184 |
dc_size = k < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs); |
dc_size = i < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs); |
185 |
dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ; |
dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ; |
186 |
|
|
187 |
if (dc_size > 8) |
if (dc_size > 8) |
189 |
BitstreamSkip(bs, 1); // marker |
BitstreamSkip(bs, 1); // marker |
190 |
} |
} |
191 |
|
|
192 |
block[0] = dc_dif; |
block[i*64 + 0] = dc_dif; |
193 |
start_coeff = 1; |
start_coeff = 1; |
194 |
} |
} |
195 |
else |
else |
198 |
} |
} |
199 |
|
|
200 |
start_timer(); |
start_timer(); |
201 |
if (cbp & (1 << (5-k))) // coded |
if (cbp & (1 << (5-i))) // coded |
202 |
{ |
{ |
203 |
get_intra_block(bs, block, mb->acpred_directions[k], start_coeff); |
get_intra_block(bs, &block[i*64], pMB->acpred_directions[i], start_coeff); |
204 |
} |
} |
205 |
stop_coding_timer(); |
stop_coding_timer(); |
206 |
|
|
207 |
start_timer(); |
start_timer(); |
208 |
add_acdc(mb, k, block, dcscalar, predictors); |
add_acdc(pMB, i, &block[i*64], iDcScaler, predictors); |
209 |
stop_prediction_timer(); |
stop_prediction_timer(); |
210 |
|
|
211 |
start_timer(); |
start_timer(); |
212 |
if (dec->quant_type == 0) |
if (dec->quant_type == 0) |
213 |
{ |
{ |
214 |
dequant_intra(data, block, mb->quant, dcscalar); |
dequant_intra(&data[i*64], &block[i*64], iQuant, iDcScaler); |
215 |
} |
} |
216 |
else |
else |
217 |
{ |
{ |
218 |
dequant4_intra(data, block, mb->quant, dcscalar); |
dequant4_intra(&data[i*64], &block[i*64], iQuant, iDcScaler); |
219 |
} |
} |
220 |
stop_iquant_timer(); |
stop_iquant_timer(); |
221 |
|
|
222 |
start_timer(); |
start_timer(); |
223 |
idct(data); |
idct(&data[i*64]); |
224 |
stop_idct_timer(); |
stop_idct_timer(); |
225 |
|
} |
226 |
|
|
227 |
start_timer(); |
start_timer(); |
228 |
if (k < 4) |
if (dec->interlacing && pMB->field_dct) |
|
{ |
|
|
transfer_16to8copy(dec->cur.y + (16*y*dec->edged_width) + 16*x + (4*(k&2)*dec->edged_width) + 8*(k&1), data, dec->edged_width); |
|
|
} |
|
|
else if (k == 4) |
|
229 |
{ |
{ |
230 |
transfer_16to8copy(dec->cur.u+ 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2)); |
MBFieldToFrame(data); |
|
} |
|
|
else // if (k == 5) |
|
|
{ |
|
|
transfer_16to8copy(dec->cur.v + 8*y*(dec->edged_width/2) + 8*x, data, (dec->edged_width/2)); |
|
231 |
} |
} |
232 |
|
stop_interlacing_timer(); |
233 |
|
|
234 |
|
start_timer(); |
235 |
|
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
236 |
|
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
237 |
|
transfer_16to8copy(pY_Cur + 8 * stride, &data[2*64], stride); |
238 |
|
transfer_16to8copy(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
239 |
|
transfer_16to8copy(pU_Cur, &data[4*64], stride / 2); |
240 |
|
transfer_16to8copy(pV_Cur, &data[5*64], stride / 2); |
241 |
stop_transfer_timer(); |
stop_transfer_timer(); |
242 |
} |
} |
|
} |
|
243 |
|
|
244 |
|
|
245 |
|
|
253 |
|
|
254 |
// decode an inter macroblock |
// decode an inter macroblock |
255 |
|
|
256 |
void decoder_mbinter(DECODER * dec, MACROBLOCK * mb, int x, int y, uint32_t acpred_flag, uint32_t cbp, Bitstream * bs, int quant, int rounding) |
void decoder_mbinter(DECODER * dec, |
257 |
|
const MACROBLOCK * pMB, |
258 |
|
const uint32_t x_pos, |
259 |
|
const uint32_t y_pos, |
260 |
|
const uint32_t acpred_flag, |
261 |
|
const uint32_t cbp, |
262 |
|
Bitstream * bs, |
263 |
|
const uint32_t quant, |
264 |
|
const uint32_t rounding) |
265 |
{ |
{ |
266 |
|
|
267 |
|
DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE); |
268 |
|
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
269 |
|
|
270 |
const uint32_t stride = dec->edged_width; |
const uint32_t stride = dec->edged_width; |
271 |
const uint32_t stride2 = dec->edged_width / 2; |
const uint32_t stride2 = dec->edged_width / 2; |
272 |
|
uint32_t i; |
273 |
|
uint32_t iQuant = pMB->quant; |
274 |
|
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
275 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
|
uint32_t k; |
|
276 |
|
|
277 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
278 |
|
pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
279 |
|
pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
280 |
|
|
281 |
|
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) |
282 |
{ |
{ |
283 |
uv_dx = mb->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
284 |
uv_dy = mb->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
285 |
|
|
286 |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
287 |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
289 |
else |
else |
290 |
{ |
{ |
291 |
int sum; |
int sum; |
292 |
sum = mb->mvs[0].x + mb->mvs[1].x + mb->mvs[2].x + mb->mvs[3].x; |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
293 |
uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) ); |
uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) ); |
294 |
|
|
295 |
sum = mb->mvs[0].y + mb->mvs[1].y + mb->mvs[2].y + mb->mvs[3].y; |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
296 |
uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) ); |
uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) ); |
297 |
} |
} |
298 |
|
|
299 |
start_timer(); |
start_timer(); |
300 |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x, 16*y , mb->mvs[0].x, mb->mvs[0].y, stride, rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos, 16*y_pos , pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
301 |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x + 8, 16*y , mb->mvs[1].x, mb->mvs[1].y, stride, rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos + 8, 16*y_pos , pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
302 |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x, 16*y + 8, mb->mvs[2].x, mb->mvs[2].y, stride, rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos, 16*y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
303 |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x + 8, 16*y + 8, mb->mvs[3].x, mb->mvs[3].y, stride, rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos + 8, 16*y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
304 |
interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x, 8*y, uv_dx, uv_dy, stride2, rounding); |
interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding); |
305 |
interpolate8x8_switch(dec->cur.v, dec->refn.v, 8*x, 8*y, uv_dx, uv_dy, stride2, rounding); |
interpolate8x8_switch(dec->cur.v, dec->refn.v, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding); |
306 |
stop_comp_timer(); |
stop_comp_timer(); |
307 |
|
|
308 |
|
for (i = 0; i < 6; i++) |
|
for (k = 0; k < 6; k++) |
|
309 |
{ |
{ |
310 |
int16_t block[64]; |
if (cbp & (1 << (5-i))) // coded |
|
int16_t data[64]; |
|
|
|
|
|
if (cbp & (1 << (5-k))) // coded |
|
311 |
{ |
{ |
312 |
memset(block, 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i*64], 0, 64 * sizeof(int16_t)); // clear |
313 |
|
|
314 |
start_timer(); |
start_timer(); |
315 |
get_inter_block(bs, block); |
get_inter_block(bs, &block[i*64]); |
316 |
stop_coding_timer(); |
stop_coding_timer(); |
317 |
|
|
318 |
start_timer(); |
start_timer(); |
319 |
if (dec->quant_type == 0) |
if (dec->quant_type == 0) |
320 |
{ |
{ |
321 |
dequant_inter(data, block, mb->quant); |
dequant_inter(&data[i*64], &block[i*64], iQuant); |
322 |
} |
} |
323 |
else |
else |
324 |
{ |
{ |
325 |
dequant4_inter(data, block, mb->quant); |
dequant4_inter(&data[i*64], &block[i*64], iQuant); |
326 |
} |
} |
327 |
stop_iquant_timer(); |
stop_iquant_timer(); |
328 |
|
|
329 |
start_timer(); |
start_timer(); |
330 |
idct(data); |
idct(&data[i*64]); |
331 |
stop_idct_timer(); |
stop_idct_timer(); |
|
|
|
|
start_timer(); |
|
|
if (k < 4) |
|
|
{ |
|
|
transfer_16to8add(dec->cur.y + (16*y + 4*(k&2))*stride + 16*x + 8*(k&1), data, stride); |
|
332 |
} |
} |
|
else if (k == 4) |
|
|
{ |
|
|
transfer_16to8add(dec->cur.u + 8*y*stride2 + 8*x, data, stride2); |
|
333 |
} |
} |
334 |
else // k == 5 |
|
335 |
|
start_timer(); |
336 |
|
if (pMB->field_dct) |
337 |
{ |
{ |
338 |
transfer_16to8add(dec->cur.v + 8*y*stride2 + 8*x, data, stride2); |
MBFieldToFrame(data); |
339 |
} |
} |
340 |
|
stop_interlacing_timer(); |
341 |
|
|
342 |
|
start_timer(); |
343 |
|
if (cbp & 32) |
344 |
|
transfer_16to8add(pY_Cur, &data[0*64], stride); |
345 |
|
if (cbp & 16) |
346 |
|
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
347 |
|
if (cbp & 8) |
348 |
|
transfer_16to8add(pY_Cur + 8 * stride, &data[2*64], stride); |
349 |
|
if (cbp & 4) |
350 |
|
transfer_16to8add(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
351 |
|
if (cbp & 2) |
352 |
|
transfer_16to8add(pU_Cur, &data[4*64], stride / 2); |
353 |
|
if (cbp & 1) |
354 |
|
transfer_16to8add(pV_Cur, &data[5*64], stride / 2); |
355 |
stop_transfer_timer(); |
stop_transfer_timer(); |
356 |
} |
} |
|
} |
|
|
} |
|
|
|
|
357 |
|
|
358 |
|
|
359 |
void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold) |
void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold) |
360 |
{ |
{ |
361 |
|
|
362 |
uint32_t x, y; |
uint32_t x, y; |
363 |
|
|
364 |
for (y = 0; y < dec->mb_height; y++) |
for (y = 0; y < dec->mb_height; y++) |
402 |
} |
} |
403 |
mb->quant = quant; |
mb->quant = quant; |
404 |
|
|
405 |
|
if (dec->interlacing) |
406 |
|
{ |
407 |
|
mb->field_dct = BitstreamGetBit(bs); |
408 |
|
DEBUG1("deci: field_dct: ", mb->field_dct); |
409 |
|
} |
410 |
|
|
411 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold); |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold); |
412 |
} |
} |
413 |
} |
} |
414 |
|
|
415 |
} |
} |
416 |
|
|
417 |
|
|
418 |
void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode) |
void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode) |
419 |
{ |
{ |
420 |
|
|
421 |
int scale_fac = 1 << (fcode - 1); |
int scale_fac = 1 << (fcode - 1); |
422 |
int high = (32 * scale_fac) - 1; |
int high = (32 * scale_fac) - 1; |
423 |
int low = ((-32) * scale_fac); |
int low = ((-32) * scale_fac); |
467 |
|
|
468 |
void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold) |
void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold) |
469 |
{ |
{ |
470 |
|
|
471 |
uint32_t x, y; |
uint32_t x, y; |
472 |
|
|
473 |
image_swap(&dec->cur, &dec->refn); |
image_swap(&dec->cur, &dec->refn); |
474 |
|
|
475 |
start_timer(); |
start_timer(); |
476 |
image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height); |
image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
477 |
stop_edges_timer(); |
stop_edges_timer(); |
478 |
|
|
479 |
for (y = 0; y < dec->mb_height; y++) |
for (y = 0; y < dec->mb_height; y++) |
494 |
mcbpc = get_mcbpc_inter(bs); |
mcbpc = get_mcbpc_inter(bs); |
495 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
496 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
497 |
|
acpred_flag = 0; |
498 |
|
|
499 |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
500 |
|
|
526 |
} |
} |
527 |
mb->quant = quant; |
mb->quant = quant; |
528 |
|
|
529 |
|
if (dec->interlacing) |
530 |
|
{ |
531 |
|
mb->field_dct = BitstreamGetBit(bs); |
532 |
|
DEBUG1("decp: field_dct: ", mb->field_dct); |
533 |
|
|
534 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
535 |
{ |
{ |
536 |
|
mb->field_pred = BitstreamGetBit(bs); |
537 |
|
DEBUG1("decp: field_pred: ", mb->field_pred); |
538 |
|
|
539 |
|
if (mb->field_pred) |
540 |
|
{ |
541 |
|
mb->field_for_top = BitstreamGetBit(bs); |
542 |
|
DEBUG1("decp: field_for_top: ", mb->field_for_top); |
543 |
|
mb->field_for_bot = BitstreamGetBit(bs); |
544 |
|
DEBUG1("decp: field_for_bot: ", mb->field_for_bot); |
545 |
|
} |
546 |
|
} |
547 |
|
} |
548 |
|
|
549 |
|
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
550 |
|
{ |
551 |
|
if (dec->interlacing && mb->field_pred) |
552 |
|
{ |
553 |
|
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); |
554 |
|
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode); |
555 |
|
} |
556 |
|
else |
557 |
|
{ |
558 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); |
559 |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
560 |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
561 |
} |
} |
562 |
|
} |
563 |
else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */) |
else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */) |
564 |
{ |
{ |
565 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); |
620 |
|
|
621 |
int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame) |
int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame) |
622 |
{ |
{ |
623 |
|
|
624 |
Bitstream bs; |
Bitstream bs; |
625 |
uint32_t rounding; |
uint32_t rounding; |
626 |
uint32_t quant; |
uint32_t quant; |
664 |
stop_global_timer(); |
stop_global_timer(); |
665 |
|
|
666 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
667 |
|
|
668 |
} |
} |