26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
28 |
#include <string.h> |
#include <string.h> |
29 |
|
#include <stdlib.h> |
30 |
|
|
31 |
#include "../portab.h" |
#include "../portab.h" |
32 |
#include "mbfunctions.h" |
#include "mbfunctions.h" |
34 |
#include "../global.h" |
#include "../global.h" |
35 |
#include "mem_transfer.h" |
#include "mem_transfer.h" |
36 |
#include "timer.h" |
#include "timer.h" |
37 |
|
#include "../bitstream/mbcoding.h" |
38 |
#include "../dct/fdct.h" |
#include "../dct/fdct.h" |
39 |
#include "../dct/idct.h" |
#include "../dct/idct.h" |
40 |
#include "../quant/quant_mpeg4.h" |
#include "../quant/quant_mpeg4.h" |
70 |
|
|
71 |
/* Performs Forward DCT on all blocks */ |
/* Performs Forward DCT on all blocks */ |
72 |
static __inline void |
static __inline void |
73 |
MBfDCT(const MBParam * pParam, |
MBfDCT(const MBParam * const pParam, |
74 |
FRAMEINFO * frame, |
const FRAMEINFO * const frame, |
75 |
MACROBLOCK * pMB, |
MACROBLOCK * const pMB, |
76 |
uint32_t x_pos, |
uint32_t x_pos, |
77 |
uint32_t y_pos, |
uint32_t y_pos, |
78 |
int16_t data[6 * 64]) |
int16_t data[6 * 64]) |
116 |
/* Quantize all blocks -- Intra mode */ |
/* Quantize all blocks -- Intra mode */ |
117 |
static __inline void |
static __inline void |
118 |
MBQuantIntra(const MBParam * pParam, |
MBQuantIntra(const MBParam * pParam, |
119 |
|
const FRAMEINFO * const frame, |
120 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
121 |
int16_t qcoeff[6 * 64], |
int16_t qcoeff[6 * 64], |
122 |
int16_t data[6*64]) |
int16_t data[6*64]) |
128 |
|
|
129 |
/* Quantize the block */ |
/* Quantize the block */ |
130 |
start_timer(); |
start_timer(); |
131 |
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) |
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) { |
132 |
quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); |
quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); |
133 |
else |
} else { |
134 |
quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); |
quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); |
135 |
|
} |
136 |
stop_quant_timer(); |
stop_quant_timer(); |
137 |
} |
} |
138 |
} |
} |
161 |
/* Quantize all blocks -- Inter mode */ |
/* Quantize all blocks -- Inter mode */ |
162 |
static __inline uint8_t |
static __inline uint8_t |
163 |
MBQuantInter(const MBParam * pParam, |
MBQuantInter(const MBParam * pParam, |
164 |
|
const FRAMEINFO * const frame, |
165 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
166 |
int16_t data[6 * 64], |
int16_t data[6 * 64], |
167 |
int16_t qcoeff[6 * 64], |
int16_t qcoeff[6 * 64], |
178 |
|
|
179 |
/* Quantize the block */ |
/* Quantize the block */ |
180 |
start_timer(); |
start_timer(); |
181 |
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) |
if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) { |
182 |
sum = quant_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); |
sum = quant_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); |
183 |
else |
if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) { |
184 |
|
sum = dct_quantize_trellis_inter_h263_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1; |
185 |
|
limit = 1; |
186 |
|
} |
187 |
|
} else { |
188 |
sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); |
sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); |
189 |
|
// if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) |
190 |
|
// sum = dct_quantize_trellis_inter_mpeg_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1; |
191 |
|
} |
192 |
stop_quant_timer(); |
stop_quant_timer(); |
193 |
|
|
194 |
/* |
/* |
213 |
|
|
214 |
/* Set the corresponding cbp bit */ |
/* Set the corresponding cbp bit */ |
215 |
cbp |= code_block << (5 - i); |
cbp |= code_block << (5 - i); |
|
|
|
216 |
} |
} |
217 |
|
|
218 |
return(cbp); |
return(cbp); |
245 |
|
|
246 |
|
|
247 |
static __inline void |
static __inline void |
248 |
MBTrans8to16(const MBParam * pParam, |
MBTrans8to16(const MBParam * const pParam, |
249 |
FRAMEINFO * frame, |
const FRAMEINFO * const frame, |
250 |
MACROBLOCK * pMB, |
const MACROBLOCK * const pMB, |
251 |
const uint32_t x_pos, |
const uint32_t x_pos, |
252 |
const uint32_t y_pos, |
const uint32_t y_pos, |
253 |
int16_t data[6 * 64]) |
int16_t data[6 * 64]) |
257 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * 8; |
258 |
int32_t cst; |
int32_t cst; |
259 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
260 |
IMAGE *pCurrent = &frame->image; |
const IMAGE * const pCurrent = &frame->image; |
261 |
transfer_operation_8to16_t *transfer_op = NULL; |
transfer_operation_8to16_t *transfer_op = NULL; |
262 |
|
|
263 |
if ((frame->vop_flags & XVID_VOP_REDUCED)) { |
if ((frame->vop_flags & XVID_VOP_REDUCED)) { |
298 |
} |
} |
299 |
|
|
300 |
static __inline void |
static __inline void |
301 |
MBTrans16to8(const MBParam * pParam, |
MBTrans16to8(const MBParam * const pParam, |
302 |
FRAMEINFO * frame, |
const FRAMEINFO * const frame, |
303 |
MACROBLOCK * pMB, |
const MACROBLOCK * const pMB, |
304 |
const uint32_t x_pos, |
const uint32_t x_pos, |
305 |
const uint32_t y_pos, |
const uint32_t y_pos, |
306 |
int16_t data[6 * 64], |
int16_t data[6 * 64], |
312 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
313 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * 8; |
314 |
uint32_t cst; |
uint32_t cst; |
315 |
IMAGE *pCurrent = &frame->image; |
const IMAGE * const pCurrent = &frame->image; |
316 |
transfer_operation_16to8_t *transfer_op = NULL; |
transfer_operation_16to8_t *transfer_op = NULL; |
317 |
|
|
318 |
if (pMB->field_dct) { |
if (pMB->field_dct) { |
368 |
****************************************************************************/ |
****************************************************************************/ |
369 |
|
|
370 |
void |
void |
371 |
MBTransQuantIntra(const MBParam * pParam, |
MBTransQuantIntra(const MBParam * const pParam, |
372 |
FRAMEINFO * frame, |
const FRAMEINFO * const frame, |
373 |
MACROBLOCK * pMB, |
MACROBLOCK * const pMB, |
374 |
const uint32_t x_pos, |
const uint32_t x_pos, |
375 |
const uint32_t y_pos, |
const uint32_t y_pos, |
376 |
int16_t data[6 * 64], |
int16_t data[6 * 64], |
384 |
MBfDCT(pParam, frame, pMB, x_pos, y_pos, data); |
MBfDCT(pParam, frame, pMB, x_pos, y_pos, data); |
385 |
|
|
386 |
/* Quantize the block */ |
/* Quantize the block */ |
387 |
MBQuantIntra(pParam, pMB, data, qcoeff); |
MBQuantIntra(pParam, frame, pMB, data, qcoeff); |
388 |
|
|
389 |
/* DeQuantize the block */ |
/* DeQuantize the block */ |
390 |
MBDeQuantIntra(pParam, pMB->quant, data, qcoeff); |
MBDeQuantIntra(pParam, pMB->quant, data, qcoeff); |
398 |
|
|
399 |
|
|
400 |
uint8_t |
uint8_t |
401 |
MBTransQuantInter(const MBParam * pParam, |
MBTransQuantInter(const MBParam * const pParam, |
402 |
FRAMEINFO * frame, |
const FRAMEINFO * const frame, |
403 |
MACROBLOCK * pMB, |
MACROBLOCK * const pMB, |
404 |
const uint32_t x_pos, |
const uint32_t x_pos, |
405 |
const uint32_t y_pos, |
const uint32_t y_pos, |
406 |
int16_t data[6 * 64], |
int16_t data[6 * 64], |
421 |
limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0); |
limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0); |
422 |
|
|
423 |
/* Quantize the block */ |
/* Quantize the block */ |
424 |
cbp = MBQuantInter(pParam, pMB, data, qcoeff, 0, limit); |
cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 0, limit); |
425 |
|
|
426 |
/* DeQuantize the block */ |
/* DeQuantize the block */ |
427 |
MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp); |
MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp); |
459 |
limit = BVOP_TOOSMALL_LIMIT; |
limit = BVOP_TOOSMALL_LIMIT; |
460 |
|
|
461 |
/* Quantize the block */ |
/* Quantize the block */ |
462 |
cbp = MBQuantInter(pParam, pMB, data, qcoeff, 1, limit); |
cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 1, limit); |
463 |
|
|
464 |
/* |
/* |
465 |
* History comment: |
* History comment: |
497 |
for (i = 0; i < 7; ++i) { |
for (i = 0; i < 7; ++i) { |
498 |
for (j = 0; j < 8; ++j) { |
for (j = 0; j < 8; ++j) { |
499 |
frame += |
frame += |
500 |
ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
abs(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); |
501 |
frame += |
frame += |
502 |
ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]); |
abs(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]); |
503 |
frame += |
frame += |
504 |
ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]); |
abs(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]); |
505 |
frame += |
frame += |
506 |
ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
abs(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); |
507 |
|
|
508 |
field += |
field += |
509 |
ABS(data[blocks[i + 1] + lines[i + 1] + j] - |
abs(data[blocks[i + 1] + lines[i + 1] + j] - |
510 |
data[blocks[i] + lines[i] + j]); |
data[blocks[i] + lines[i] + j]); |
511 |
field += |
field += |
512 |
ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] - |
513 |
data[blocks[i] + lines[i] + 8 + j]); |
data[blocks[i] + lines[i] + 8 + j]); |
514 |
field += |
field += |
515 |
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] - |
516 |
data[blocks[i] + 64 + lines[i] + j]); |
data[blocks[i] + 64 + lines[i] + j]); |
517 |
field += |
field += |
518 |
ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - |
519 |
data[blocks[i] + 64 + lines[i] + 8 + j]); |
data[blocks[i] + 64 + lines[i] + 8 + j]); |
520 |
} |
} |
521 |
} |
} |