--- mbtransquant.c 2003/03/30 13:16:41 1.21.2.6 +++ mbtransquant.c 2003/04/27 19:47:48 1.21.2.9 @@ -21,11 +21,12 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: mbtransquant.c,v 1.21.2.6 2003/03/30 13:16:41 edgomez Exp $ + * $Id: mbtransquant.c,v 1.21.2.9 2003/04/27 19:47:48 chl Exp $ * ****************************************************************************/ #include +#include #include "../portab.h" #include "mbfunctions.h" @@ -33,6 +34,7 @@ #include "../global.h" #include "mem_transfer.h" #include "timer.h" +#include "../bitstream/mbcoding.h" #include "../dct/fdct.h" #include "../dct/idct.h" #include "../quant/quant_mpeg4.h" @@ -68,13 +70,13 @@ /* Performs Forward DCT on all blocks */ static __inline void -MBfDCT(const MBParam * pParam, - FRAMEINFO * frame, - MACROBLOCK * pMB, +MBfDCT(const MBParam * const pParam, + const FRAMEINFO * const frame, + MACROBLOCK * const pMB, uint32_t x_pos, uint32_t y_pos, int16_t data[6 * 64]) -{ +{ /* Handles interlacing */ start_timer(); pMB->field_dct = 0; @@ -114,8 +116,9 @@ /* Quantize all blocks -- Intra mode */ static __inline void MBQuantIntra(const MBParam * pParam, + const FRAMEINFO * const frame, const MACROBLOCK * pMB, - int16_t qcoeff[6 * 64], + int16_t qcoeff[6 * 64], int16_t data[6*64]) { int i; @@ -125,10 +128,11 @@ /* Quantize the block */ start_timer(); - if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) + if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) { quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); - else + } else { quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler); + } stop_quant_timer(); } } @@ -157,6 +161,7 @@ /* Quantize all blocks -- Inter mode */ static __inline uint8_t MBQuantInter(const MBParam * pParam, + const FRAMEINFO * const frame, const MACROBLOCK * pMB, int16_t data[6 * 64], int16_t qcoeff[6 * 64], @@ -170,13 +175,20 @@ int code_block; for (i = 0; i < 6; i++) { - + /* Quantize the block */ start_timer(); - if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) - sum = quant_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); - else + if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) { + sum = quant_inter(&qcoeff[i*64], &data[i*64], pMB->quant); + if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) { + sum = dct_quantize_trellis_inter_h263_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1; + limit = 1; + } + } else { sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant); +// if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) +// sum = dct_quantize_trellis_inter_mpeg_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1; + } stop_quant_timer(); /* @@ -201,14 +213,13 @@ /* Set the corresponding cbp bit */ cbp |= code_block << (5 - i); - } return(cbp); } /* DeQuantize all blocks -- Inter mode */ -static __inline void +static __inline void MBDeQuantInter(const MBParam * pParam, const int iQuant, int16_t data[6 * 64], @@ -218,7 +229,7 @@ int i; for (i = 0; i < 6; i++) { - if (cbp & (1 << (5 - i))) { + if (cbp & (1 << (5 - i))) { start_timer(); if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); @@ -234,9 +245,9 @@ static __inline void -MBTrans8to16(const MBParam * pParam, - FRAMEINFO * frame, - MACROBLOCK * pMB, +MBTrans8to16(const MBParam * const pParam, + const FRAMEINFO * const frame, + const MACROBLOCK * const pMB, const uint32_t x_pos, const uint32_t y_pos, int16_t data[6 * 64]) @@ -244,9 +255,9 @@ uint32_t stride = pParam->edged_width; uint32_t stride2 = stride / 2; uint32_t next_block = stride * 8; - int32_t cst; + int32_t cst; uint8_t *pY_Cur, *pU_Cur, *pV_Cur; - IMAGE *pCurrent = &frame->image; + const IMAGE * const pCurrent = &frame->image; transfer_operation_8to16_t *transfer_op = NULL; if ((frame->vop_flags & XVID_VOP_REDUCED)) { @@ -284,12 +295,12 @@ transfer_op(&data[4 * 64], pU_Cur, stride2); transfer_op(&data[5 * 64], pV_Cur, stride2); stop_transfer_timer(); -} +} static __inline void -MBTrans16to8(const MBParam * pParam, - FRAMEINFO * frame, - MACROBLOCK * pMB, +MBTrans16to8(const MBParam * const pParam, + const FRAMEINFO * const frame, + const MACROBLOCK * const pMB, const uint32_t x_pos, const uint32_t y_pos, int16_t data[6 * 64], @@ -300,8 +311,8 @@ uint32_t stride = pParam->edged_width; uint32_t stride2 = stride / 2; uint32_t next_block = stride * 8; - uint32_t cst; - IMAGE *pCurrent = &frame->image; + uint32_t cst; + const IMAGE * const pCurrent = &frame->image; transfer_operation_16to8_t *transfer_op = NULL; if (pMB->field_dct) { @@ -356,10 +367,10 @@ * Module functions ****************************************************************************/ -void -MBTransQuantIntra(const MBParam * pParam, - FRAMEINFO * frame, - MACROBLOCK * pMB, +void +MBTransQuantIntra(const MBParam * const pParam, + const FRAMEINFO * const frame, + MACROBLOCK * const pMB, const uint32_t x_pos, const uint32_t y_pos, int16_t data[6 * 64], @@ -373,7 +384,7 @@ MBfDCT(pParam, frame, pMB, x_pos, y_pos, data); /* Quantize the block */ - MBQuantIntra(pParam, pMB, data, qcoeff); + MBQuantIntra(pParam, frame, pMB, data, qcoeff); /* DeQuantize the block */ MBDeQuantIntra(pParam, pMB->quant, data, qcoeff); @@ -387,9 +398,9 @@ uint8_t -MBTransQuantInter(const MBParam * pParam, - FRAMEINFO * frame, - MACROBLOCK * pMB, +MBTransQuantInter(const MBParam * const pParam, + const FRAMEINFO * const frame, + MACROBLOCK * const pMB, const uint32_t x_pos, const uint32_t y_pos, int16_t data[6 * 64], @@ -410,7 +421,7 @@ limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0); /* Quantize the block */ - cbp = MBQuantInter(pParam, pMB, data, qcoeff, 0, limit); + cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 0, limit); /* DeQuantize the block */ MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp); @@ -420,7 +431,7 @@ /* Transfer back the data -- Add the data */ MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp); - + return(cbp); } @@ -435,7 +446,7 @@ { uint8_t cbp; uint32_t limit; - + /* * There is no MBTrans8to16 for Inter block, that's done in motion compensation * already @@ -448,7 +459,7 @@ limit = BVOP_TOOSMALL_LIMIT; /* Quantize the block */ - cbp = MBQuantInter(pParam, pMB, data, qcoeff, 1, limit); + cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 1, limit); /* * History comment: @@ -486,25 +497,25 @@ for (i = 0; i < 7; ++i) { for (j = 0; j < 8; ++j) { frame += - 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]); frame += - 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]); frame += - 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]); frame += - 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]); field += - ABS(data[blocks[i + 1] + lines[i + 1] + j] - + abs(data[blocks[i + 1] + lines[i + 1] + j] - data[blocks[i] + lines[i] + j]); field += - ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - + abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] - data[blocks[i] + lines[i] + 8 + j]); field += - ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - + abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] - data[blocks[i] + 64 + lines[i] + j]); field += - ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - + abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - data[blocks[i] + 64 + lines[i] + 8 + j]); } } @@ -516,7 +527,7 @@ /* deinterlace Y blocks vertically */ #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) -#define LINE(X,Y) &data[X*64 + Y*8] +#define LINE(X,Y) &data[X*64 + Y*8] void MBFrameToField(int16_t data[6 * 64])