51 |
|
|
52 |
#include <stdio.h> |
#include <stdio.h> |
53 |
#include <stdlib.h> |
#include <stdlib.h> |
54 |
|
#include <string.h> |
55 |
|
|
56 |
#include "../portab.h" |
#include "../portab.h" |
57 |
#include "../global.h" |
#include "../global.h" |
58 |
#include "bitstream.h" |
#include "bitstream.h" |
500 |
{ |
{ |
501 |
if ((level = qcoeff[zigzag[i++]]) != 0) |
if ((level = qcoeff[zigzag[i++]]) != 0) |
502 |
{ |
{ |
503 |
abs_level = ABS(prev_level); |
abs_level = abs(prev_level); |
504 |
abs_level = abs_level < 64 ? abs_level : 0; |
abs_level = abs_level < 64 ? abs_level : 0; |
505 |
code = coeff_VLC[1][0][abs_level][prev_run].code; |
code = coeff_VLC[1][0][abs_level][prev_run].code; |
506 |
len = coeff_VLC[1][0][abs_level][prev_run].len; |
len = coeff_VLC[1][0][abs_level][prev_run].len; |
520 |
run++; |
run++; |
521 |
} |
} |
522 |
|
|
523 |
abs_level = ABS(prev_level); |
abs_level = abs(prev_level); |
524 |
abs_level = abs_level < 64 ? abs_level : 0; |
abs_level = abs_level < 64 ? abs_level : 0; |
525 |
code = coeff_VLC[1][1][abs_level][prev_run].code; |
code = coeff_VLC[1][1][abs_level][prev_run].code; |
526 |
len = coeff_VLC[1][1][abs_level][prev_run].len; |
len = coeff_VLC[1][1][abs_level][prev_run].len; |
561 |
{ |
{ |
562 |
if ((level = qcoeff[zigzag[i++]]) != 0) |
if ((level = qcoeff[zigzag[i++]]) != 0) |
563 |
{ |
{ |
564 |
abs_level = ABS(prev_level); |
abs_level = abs(prev_level); |
565 |
abs_level = abs_level < 64 ? abs_level : 0; |
abs_level = abs_level < 64 ? abs_level : 0; |
566 |
len = coeff_VLC[1][0][abs_level][prev_run].len; |
len = coeff_VLC[1][0][abs_level][prev_run].len; |
567 |
bits += len!=128 ? len : 30; |
bits += len!=128 ? len : 30; |
574 |
run++; |
run++; |
575 |
} |
} |
576 |
|
|
577 |
abs_level = ABS(prev_level); |
abs_level = abs(prev_level); |
578 |
abs_level = abs_level < 64 ? abs_level : 0; |
abs_level = abs_level < 64 ? abs_level : 0; |
579 |
len = coeff_VLC[1][1][abs_level][prev_run].len; |
len = coeff_VLC[1][1][abs_level][prev_run].len; |
580 |
bits += len!=128 ? len : 30; |
bits += len!=128 ? len : 30; |
666 |
BitstreamPutBits(bs, 0, 1); |
BitstreamPutBits(bs, 0, 1); |
667 |
|
|
668 |
// write cbpy |
// write cbpy |
669 |
BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); |
BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len); |
670 |
|
|
671 |
// write dquant |
// write dquant |
672 |
if (pMB->mode == MODE_INTRA_Q) |
if (pMB->mode == MODE_INTRA_Q) |
673 |
BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2); |
BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2); |
674 |
|
|
675 |
// write interlacing |
// write interlacing |
676 |
if (frame->vol_flags & XVID_INTERLACING) { |
if (frame->vol_flags & XVID_VOL_INTERLACING) { |
677 |
BitstreamPutBit(bs, pMB->field_dct); |
BitstreamPutBit(bs, pMB->field_dct); |
678 |
} |
} |
679 |
// code block coeffs |
// code block coeffs |
687 |
|
|
688 |
if (pMB->cbp & (1 << (5 - i))) { |
if (pMB->cbp & (1 << (5 - i))) { |
689 |
const uint16_t *scan_table = |
const uint16_t *scan_table = |
690 |
frame->vop_flags & XVID_ALTERNATESCAN ? |
frame->vop_flags & XVID_VOP_ALTERNATESCAN ? |
691 |
scan_tables[2] : scan_tables[pMB->acpred_directions[i]]; |
scan_tables[2] : scan_tables[pMB->acpred_directions[i]]; |
692 |
|
|
693 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
728 |
BitstreamPutBit(bs, pMB->mcsel); // mcsel: '0'=local motion, '1'=GMC |
BitstreamPutBit(bs, pMB->mcsel); // mcsel: '0'=local motion, '1'=GMC |
729 |
|
|
730 |
// write cbpy |
// write cbpy |
731 |
BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); |
BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len); |
732 |
|
|
733 |
// write dquant |
// write dquant |
734 |
if (pMB->mode == MODE_INTER_Q) |
if (pMB->mode == MODE_INTER_Q) |
735 |
BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2); |
BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2); |
736 |
|
|
737 |
// interlacing |
// interlacing |
738 |
if (frame->vol_flags & XVID_INTERLACING) { |
if (frame->vol_flags & XVID_VOL_INTERLACING) { |
739 |
if (pMB->cbp) { |
if (pMB->cbp) { |
740 |
BitstreamPutBit(bs, pMB->field_dct); |
BitstreamPutBit(bs, pMB->field_dct); |
741 |
DPRINTF(DPRINTF_MB,"codep: field_dct: %i", pMB->field_dct); |
DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct); |
742 |
} |
} |
743 |
|
|
744 |
// if inter block, write field ME flag |
// if inter block, write field ME flag |
745 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
746 |
BitstreamPutBit(bs, pMB->field_pred); |
BitstreamPutBit(bs, pMB->field_pred); |
747 |
DPRINTF(DPRINTF_MB,"codep: field_pred: %i", pMB->field_pred); |
DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred); |
748 |
|
|
749 |
// write field prediction references |
// write field prediction references |
750 |
if (pMB->field_pred) { |
if (pMB->field_pred) { |
767 |
if (pMB->cbp & (1 << (5 - i))) |
if (pMB->cbp & (1 << (5 - i))) |
768 |
{ |
{ |
769 |
const uint16_t *scan_table = |
const uint16_t *scan_table = |
770 |
frame->vop_flags & XVID_ALTERNATESCAN ? |
frame->vop_flags & XVID_VOP_ALTERNATESCAN ? |
771 |
scan_tables[2] : scan_tables[0]; |
scan_tables[2] : scan_tables[0]; |
772 |
|
|
773 |
#ifdef BIGLUT |
#ifdef BIGLUT |
1061 |
return data; |
return data; |
1062 |
|
|
1063 |
res = BitstreamGetBits(bs, fcode - 1); |
res = BitstreamGetBits(bs, fcode - 1); |
1064 |
mv = ((ABS(data) - 1) * scale_fac) + res + 1; |
mv = ((abs(data) - 1) * scale_fac) + res + 1; |
1065 |
|
|
1066 |
return data < 0 ? -mv : mv; |
return data < 0 ? -mv : mv; |
1067 |
|
|
1162 |
level = BitstreamGetBits(bs, 8); |
level = BitstreamGetBits(bs, 8); |
1163 |
|
|
1164 |
if (level == 0 || level == 128) |
if (level == 0 || level == 128) |
1165 |
DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level); |
DPRINTF(XVID_DEBUG_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d\n", level); |
1166 |
|
|
1167 |
return (level << 24) >> 24; |
return (level << 24) >> 24; |
1168 |
} |
} |
1218 |
do { |
do { |
1219 |
level = get_coeff(bs, &run, &last, 1, 0); |
level = get_coeff(bs, &run, &last, 1, 0); |
1220 |
if (run == -1) { |
if (run == -1) { |
1221 |
DPRINTF(DPRINTF_ERROR,"fatal: invalid run"); |
DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run"); |
1222 |
break; |
break; |
1223 |
} |
} |
1224 |
coeff += run; |
coeff += run; |
1225 |
block[scan[coeff]] = level; |
block[scan[coeff]] = level; |
1226 |
|
|
1227 |
DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level); |
DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level); |
1228 |
//DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); |
//DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[coeff], level, BitstreamShowBits(bs, 32)); |
1229 |
|
|
1230 |
if (level < -2047 || level > 2047) { |
if (level < -2047 || level > 2047) { |
1231 |
DPRINTF(DPRINTF_ERROR,"warning: intra_overflow %i", level); |
DPRINTF(XVID_DEBUG_ERROR,"warning: intra_overflow %i\n", level); |
1232 |
} |
} |
1233 |
coeff++; |
coeff++; |
1234 |
} while (!last); |
} while (!last); |
1251 |
do { |
do { |
1252 |
level = get_coeff(bs, &run, &last, 0, 0); |
level = get_coeff(bs, &run, &last, 0, 0); |
1253 |
if (run == -1) { |
if (run == -1) { |
1254 |
DPRINTF(DPRINTF_ERROR,"fatal: invalid run"); |
DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run"); |
1255 |
break; |
break; |
1256 |
} |
} |
1257 |
p += run; |
p += run; |
1258 |
|
|
1259 |
block[scan[p]] = level; |
block[scan[p]] = level; |
1260 |
|
|
1261 |
DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level); |
DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[p], level); |
1262 |
// DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32)); |
// DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[p], level, BitstreamShowBits(bs, 32)); |
1263 |
|
|
1264 |
if (level < -2047 || level > 2047) { |
if (level < -2047 || level > 2047) { |
1265 |
DPRINTF(DPRINTF_ERROR,"warning: inter overflow %i", level); |
DPRINTF(XVID_DEBUG_ERROR,"warning: inter overflow %i\n", level); |
1266 |
} |
} |
1267 |
p++; |
p++; |
1268 |
} while (!last); |
} while (!last); |
1269 |
|
|
1270 |
} |
} |
1271 |
|
|
1272 |
|
|
1273 |
/***************************************************************************** |
/***************************************************************************** |
1274 |
* VLC tables and other constant arrays |
* VLC tables and other constant arrays |
1275 |
****************************************************************************/ |
****************************************************************************/ |
1628 |
{5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9} |
{5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9} |
1629 |
}; |
}; |
1630 |
|
|
1631 |
const VLC cbpy_tab[16] = { |
const VLC xvid_cbpy_tab[16] = { |
1632 |
{3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4}, |
{3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4}, |
1633 |
{2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2} |
{2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2} |
1634 |
}; |
}; |