21 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: mbtransquant.c,v 1.23 2004-03-22 22:36:24 edgomez Exp $ |
* $Id: mbtransquant.c,v 1.24 2004-04-15 19:44:06 edgomez Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
183 |
int Q, |
int Q, |
184 |
const uint16_t * const Zigzag, |
const uint16_t * const Zigzag, |
185 |
const uint16_t * const QuantMatrix, |
const uint16_t * const QuantMatrix, |
186 |
int Non_Zero); |
int Non_Zero, |
187 |
|
int Sum); |
188 |
|
|
189 |
/* Quantize all blocks -- Inter mode */ |
/* Quantize all blocks -- Inter mode */ |
190 |
static __inline uint8_t |
static __inline uint8_t |
235 |
sum = dct_quantize_trellis_c(&qcoeff[i*64], &data[i*64], |
sum = dct_quantize_trellis_c(&qcoeff[i*64], &data[i*64], |
236 |
pMB->quant, &scan_tables[0][0], |
pMB->quant, &scan_tables[0][0], |
237 |
matrix, |
matrix, |
238 |
63); |
63, |
239 |
|
sum); |
240 |
} |
} |
241 |
stop_quant_timer(); |
stop_quant_timer(); |
242 |
|
|
783 |
return -1; |
return -1; |
784 |
} |
} |
785 |
|
|
|
static int __inline |
|
|
Compute_Sum(const int16_t *C, int last) |
|
|
{ |
|
|
int sum = 0; |
|
|
|
|
|
while(last--) |
|
|
sum += abs(C[last]); |
|
|
|
|
|
return(sum); |
|
|
} |
|
|
|
|
786 |
/* this routine has been strippen of all debug code */ |
/* this routine has been strippen of all debug code */ |
787 |
static int |
static int |
788 |
dct_quantize_trellis_c(int16_t *const Out, |
dct_quantize_trellis_c(int16_t *const Out, |
790 |
int Q, |
int Q, |
791 |
const uint16_t * const Zigzag, |
const uint16_t * const Zigzag, |
792 |
const uint16_t * const QuantMatrix, |
const uint16_t * const QuantMatrix, |
793 |
int Non_Zero) |
int Non_Zero, |
794 |
|
int Sum) |
795 |
{ |
{ |
796 |
|
|
797 |
/* Note: We should search last non-zero coeffs on *real* DCT input coeffs |
/* Note: We should search last non-zero coeffs on *real* DCT input coeffs |
814 |
int Last_Node = -1; |
int Last_Node = -1; |
815 |
uint32_t Last_Cost = 0; |
uint32_t Last_Cost = 0; |
816 |
|
|
817 |
int i, j, sum; |
int i, j; |
818 |
|
|
819 |
/* source (w/ CBP penalty) */ |
/* source (w/ CBP penalty) */ |
820 |
Run_Costs[-1] = 2<<TL_SHIFT; |
Run_Costs[-1] = 2<<TL_SHIFT; |
994 |
} |
} |
995 |
} |
} |
996 |
|
|
997 |
/* It seems trellis doesn't give good results... just compute the Out sum |
/* It seems trellis doesn't give good results... just leave the block untouched |
998 |
* and quit */ |
* and return the original sum value */ |
999 |
if (Last_Node<0) |
if (Last_Node<0) |
1000 |
return Compute_Sum(Out, Non_Zero); |
return Sum; |
1001 |
|
|
1002 |
/* reconstruct optimal sequence backward with surviving paths */ |
/* reconstruct optimal sequence backward with surviving paths */ |
1003 |
memset(Out, 0x00, 64*sizeof(*Out)); |
memset(Out, 0x00, 64*sizeof(*Out)); |
1004 |
Out[Zigzag[Last_Node]] = Last.Level; |
Out[Zigzag[Last_Node]] = Last.Level; |
1005 |
i = Last_Node - Last.Run; |
i = Last_Node - Last.Run; |
1006 |
sum = 0; |
Sum = 0; |
1007 |
while(i>=0) { |
while(i>=0) { |
1008 |
Out[Zigzag[i]] = Nodes[i].Level; |
Out[Zigzag[i]] = Nodes[i].Level; |
1009 |
sum += abs(Nodes[i].Level); |
Sum += abs(Nodes[i].Level); |
1010 |
i -= Nodes[i].Run; |
i -= Nodes[i].Run; |
1011 |
} |
} |
1012 |
|
|
1013 |
return sum; |
return Sum; |
1014 |
} |
} |
1015 |
|
|
1016 |
/* original version including heavy debugging info */ |
/* original version including heavy debugging info */ |