--- mbcoding.c 2003/06/09 01:17:20 1.44.2.11 +++ mbcoding.c 2003/10/03 13:47:00 1.44.2.15 @@ -1,53 +1,27 @@ - /****************************************************************************** - * * - * This file is part of XviD, a free MPEG-4 video encoder/decoder * - * * - * XviD is an implementation of a part of one or more MPEG-4 Video tools * - * as specified in ISO/IEC 14496-2 standard. Those intending to use this * - * software module in hardware or software products are advised that its * - * use may infringe existing patents or copyrights, and any such use * - * would be at such party's own risk. The original developer of this * - * software module and his/her company, and subsequent editors and their * - * companies, will have no liability for use of this software or * - * modifications or derivatives thereof. * - * * - * XviD is free software; you can redistribute it and/or modify it * - * under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * XviD is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - ******************************************************************************/ - - /****************************************************************************** - * * - * mbcoding.c * - * * - * Copyright (C) 2002 - Michael Militzer * - * * - * For more information visit the XviD homepage: http://www.xvid.org * - * * - ******************************************************************************/ - - /****************************************************************************** - * * - * Revision history: * - * * - * 28.10.2002 GMC support - gruel * - * 28.06.2002 added check_resync_marker() * - * 14.04.2002 bframe encoding * - * 08.03.2002 initial version; isibaar * - * * - ******************************************************************************/ - +/***************************************************************************** + * + * XVID MPEG-4 VIDEO CODEC + * - MB coding - + * + * Copyright (C) 2002 Michael Militzer + * + * This program is free software ; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation ; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY ; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program ; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: mbcoding.c,v 1.44.2.15 2003/10/03 13:47:00 syskin Exp $ + * + ****************************************************************************/ #include #include @@ -75,7 +49,7 @@ #ifdef BIGLUT static VLC coeff_VLC[2][2][4096][64]; VLC *intra_table; -static VLC *inter_table; +static VLC *inter_table; #else static VLC coeff_VLC[2][2][64][64]; #endif @@ -119,7 +93,7 @@ #ifdef BIGLUT intra_table = coeff_VLC[1]; - inter_table = coeff_VLC[0]; + inter_table = coeff_VLC[0]; #endif @@ -277,7 +251,7 @@ for (l=limit; l<= 2*limit-1; l++) { - sprite_trajectory_code[l+16384].code = l; + sprite_trajectory_code[l+16384].code = l; sprite_trajectory_code[l+16384].len = k+1; } } @@ -540,7 +514,7 @@ /* returns the number of bits required to encode qcoeff */ -int +int CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag) { int bits = 0; @@ -791,9 +765,9 @@ Bitstream * bs, Statistics * pStat) { - if (frame->coding_type != I_VOP) + if (frame->coding_type != I_VOP) BitstreamPutBit(bs, 0); /* not_coded */ - + if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); else @@ -801,16 +775,6 @@ } - -/* moved to mbcoding.h so that in can be 'static __inline' */ -#if 0 -void -MBSkip(Bitstream * bs) -{ - BitstreamPutBit(bs, 1); /* not coded */ -} -#endif - /*************************************************************** * bframe encoding start ***************************************************************/ @@ -874,17 +838,22 @@ void -MBCodingBVOP(const MACROBLOCK * mb, +MBCodingBVOP(const FRAMEINFO * const frame, + const MACROBLOCK * mb, const int16_t qcoeff[6 * 64], const int32_t fcode, const int32_t bcode, Bitstream * bs, - Statistics * pStat, - int direction) + Statistics * pStat) { int vcode = fcode; unsigned int i; + const uint16_t *scan_table = + frame->vop_flags & XVID_VOP_ALTERNATESCAN ? + scan_tables[2] : scan_tables[0]; + + /* ------------------------------------------------------------------ when a block is skipped it is decoded DIRECT(0,0) hence is interpolated from forward & backward frames @@ -913,6 +882,25 @@ put_bvop_dbquant(bs, 0); /* todo: mb->dquant = 0 */ } + if (frame->vol_flags & XVID_VOL_INTERLACING) { + if (mb->cbp) { + BitstreamPutBit(bs, mb->field_dct); + DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", mb->field_dct); + } + + /* if not direct block, write field ME flag */ + if (mb->mode != MODE_DIRECT) { + BitstreamPutBit(bs, 0 /*mb->field_pred*/); /* field ME not implemented */ + + /* write field prediction references */ + /* if (mb->field_pred) { + BitstreamPutBit(bs, mb->field_for_top); + BitstreamPutBit(bs, mb->field_for_bot); + }*/ + } + } + + switch (mb->mode) { case MODE_INTERPOLATE: CodeVector(bs, mb->pmvs[1].x, vcode, pStat); /* forward vector of interpolate mode */ @@ -953,7 +941,7 @@ * for BVOP addbits == max(fcode,bcode) - 1 * returns true or false */ -int +int check_resync_marker(Bitstream * bs, int addbits) { uint32_t nbits; @@ -993,7 +981,7 @@ { uint32_t index; - + index = MIN(BitstreamShowBits(bs, 9), 256); BitstreamSkip(bs, mcbpc_inter_table[index].len); @@ -1561,7 +1549,7 @@ 0, 0, 0, 0, 0, 0, 0, 0, }, /* intra = 0, last = 1 */ - { + { 0, 40, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1605,9 +1593,9 @@ VLC sprite_trajectory_code[32768]; VLC sprite_trajectory_len[15] = { - { 0x00 , 2}, - { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3}, - { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8}, + { 0x00 , 2}, + { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3}, + { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7E, 7}, { 0xFE, 8}, { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };