19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: mbcoding.c,v 1.51 2005-04-04 23:49:37 edgomez Exp $ |
* $Id: mbcoding.c,v 1.53 2006-01-19 22:25:23 Isibaar Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
572 |
#endif |
#endif |
573 |
} |
} |
574 |
} |
} |
575 |
|
|
576 |
|
bits = BitstreamPos(bs); |
577 |
|
|
578 |
/* code motion vector(s) if motion is local */ |
/* code motion vector(s) if motion is local */ |
579 |
if (!pMB->mcsel) |
if (!pMB->mcsel) |
580 |
for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { |
for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { |
582 |
CodeVector(bs, pMB->pmvs[i].y, frame->fcode); |
CodeVector(bs, pMB->pmvs[i].y, frame->fcode); |
583 |
} |
} |
584 |
|
|
585 |
|
bits = BitstreamPos(bs) - bits; |
586 |
|
pStat->iMVBits += bits; |
587 |
|
|
588 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
589 |
|
|
590 |
/* code block coeffs */ |
/* code block coeffs */ |
752 |
} |
} |
753 |
} |
} |
754 |
|
|
755 |
|
bits = BitstreamPos(bs); |
756 |
|
|
757 |
switch (mb->mode) { |
switch (mb->mode) { |
758 |
case MODE_INTERPOLATE: |
case MODE_INTERPOLATE: |
769 |
CodeVector(bs, mb->pmvs[3].y, 1); /* prediction is always (0,0) */ |
CodeVector(bs, mb->pmvs[3].y, 1); /* prediction is always (0,0) */ |
770 |
default: break; |
default: break; |
771 |
} |
} |
772 |
|
pStat->iMVBits += BitstreamPos(bs) - bits; |
773 |
|
|
774 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
775 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1080 |
break; |
break; |
1081 |
} |
} |
1082 |
coeff += run; |
coeff += run; |
1083 |
|
|
1084 |
|
#ifdef _DEBUG |
1085 |
|
if(coeff>=64) { |
1086 |
|
DPRINTF(XVID_DEBUG_ERROR,"error: overflow in coefficient index\n"); |
1087 |
|
return; |
1088 |
|
} |
1089 |
|
#endif |
1090 |
|
|
1091 |
block[scan[coeff]] = level; |
block[scan[coeff]] = level; |
1092 |
|
|
1093 |
DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level); |
DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level); |
1129 |
} |
} |
1130 |
p += run; |
p += run; |
1131 |
|
|
1132 |
|
#ifdef _DEBUG |
1133 |
|
if(p>=64) { |
1134 |
|
DPRINTF(XVID_DEBUG_ERROR,"error: overflow in coefficient index\n"); |
1135 |
|
return; |
1136 |
|
} |
1137 |
|
#endif |
1138 |
|
|
1139 |
if (level < 0) { |
if (level < 0) { |
1140 |
level = level*quant_m_2 - quant_add; |
level = level*quant_m_2 - quant_add; |
1141 |
block[scan[p]] = (level >= -2048 ? level : -2048); |
block[scan[p]] = (level >= -2048 ? level : -2048); |
1171 |
} |
} |
1172 |
p += run; |
p += run; |
1173 |
|
|
1174 |
|
#ifdef _DEBUG |
1175 |
|
if(p>=64) { |
1176 |
|
DPRINTF(XVID_DEBUG_ERROR,"error: overflow in coefficient index\n"); |
1177 |
|
return; |
1178 |
|
} |
1179 |
|
#endif |
1180 |
|
|
1181 |
if (level < 0) { |
if (level < 0) { |
1182 |
level = ((2 * -level + 1) * matrix[scan[p]] * quant) >> 4; |
level = ((2 * -level + 1) * matrix[scan[p]] * quant) >> 4; |
1183 |
block[scan[p]] = (level <= 2048 ? -level : -2048); |
block[scan[p]] = (level <= 2048 ? -level : -2048); |