--- vlc_codes.h 2002/06/12 20:38:40 1.6 +++ vlc_codes.h 2002/09/10 21:28:17 1.10 @@ -1,3 +1,38 @@ +/***************************************************************************** + * + * XVID MPEG-4 VIDEO CODEC + * - Vector Length Coding tables - + * + * Copyright(C) 2002 Michael Militzer + * + * + * This program 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. + * + * 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: vlc_codes.h,v 1.10 2002/09/10 21:28:17 edgomez Exp $ + * + ****************************************************************************/ + #ifndef _VLC_CODES_H_ #define _VLC_CODES_H_ @@ -7,6 +42,10 @@ #define VLC_ERROR (-1) #define ESCAPE 7167 +/***************************************************************************** + * The Vector Length Coding structure + ****************************************************************************/ + typedef struct { uint32_t code; @@ -17,13 +56,14 @@ static VLC *DCT3D[2]; -/****************************************************************** - * common tables between encoder/decoder * - ******************************************************************/ +/***************************************************************************** + * common tables between encoder/decoder + ****************************************************************************/ /* constants taken from momusys/vm_common/inlcude/max_level.h */ -static char max_level[4][64] = { - { // intra, last = 0 +static char const max_level[4][64] = { + /* intra, last = 0 */ + { 27, 10, 5, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -31,10 +71,11 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }, - { // intra, last = 1 + /* intra, last = 1 */ + { 8, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, @@ -42,10 +83,11 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }, - { // inter, last = 0 + /* inter, last = 0 */ + { 12, 6, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -53,10 +95,11 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }, - { // inter, last = 1 + /* inter, last = 1 */ + { 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -64,12 +107,13 @@ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 } }; -static char max_run[4][256] = { - { // intra, last = 0 +static char const max_run[4][256] = { + /* intra, last = 0 */ + { 0, 14, 9, 7, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -101,10 +145,11 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }, - { // intra, last = 1 + /* intra, last = 1 */ + { 0, 20, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -136,10 +181,11 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }, - { // inter, last = 0 + /* inter, last = 0 */ + { 0, 26, 10, 6, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -171,10 +217,11 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }, - { // inter, last = 1 + /* inter, 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, @@ -206,7 +253,7 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 } }; @@ -220,300 +267,193 @@ /* first part of coeffs for last = 0. Indexed by [run][level-1] */ -static VLC coeff_tab0[2][12] = { - /* - run = 0 - */ - { - {0x02, 2}, {0x0f, 4}, {0x15, 6}, {0x17, 7}, - {0x1f, 8}, {0x25, 9}, {0x24, 9}, {0x21, 10}, - {0x20, 10}, {0x07, 11}, {0x06, 11}, {0x20, 11} - }, - /* - run = 1 - */ +static VLC const coeff_tab0[2][12] = { + /* run = 0 */ { - {0x06, 3}, {0x14, 6}, {0x1e, 8}, {0x0f, 10}, - {0x21, 11}, {0x50, 12}, {0x00, 0}, {0x00, 0}, - {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0} - } + {0x02, 2}, {0x0f, 4}, {0x15, 6}, {0x17, 7}, + {0x1f, 8}, {0x25, 9}, {0x24, 9}, {0x21, 10}, + {0x20, 10}, {0x07, 11}, {0x06, 11}, {0x20, 11} + }, + + /* run = 1 */ + { + {0x06, 3}, {0x14, 6}, {0x1e, 8}, {0x0f, 10}, + {0x21, 11}, {0x50, 12}, {0x00, 0}, {0x00, 0}, + {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0} + } }; /* rest of coeffs for last = 0. indexing by [run-2][level-1] */ -static VLC coeff_tab1[25][4] = { - /* - run = 2 - */ - { - {0x0e, 4}, {0x1d, 8}, {0x0e, 10}, {0x51, 12} - }, - /* - run = 3 - */ - { - {0x0d, 5}, {0x23, 9}, {0x0d, 10}, {0x00, 0} - }, - /* - run = 4-26 - */ - { - {0x0c, 5}, {0x22, 9}, {0x52, 12}, {0x00, 0} - }, - { - {0x0b, 5}, {0x0c, 10}, {0x53, 12}, {0x00, 0} - }, - { - {0x13, 6}, {0x0b, 10}, {0x54, 12}, {0x00, 0} - }, - { - {0x12, 6}, {0x0a, 10}, {0x00, 0}, {0x00, 0} - }, - { - {0x11, 6}, {0x09, 10}, {0x00, 0}, {0x00, 0} - }, - { - {0x10, 6}, {0x08, 10}, {0x00, 0}, {0x00, 0} - }, - { - {0x16, 7}, {0x55, 12}, {0x00, 0}, {0x00, 0} - }, - { - {0x15, 7}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x14, 7}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1c, 8}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1b, 8}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x21, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x20, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1f, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1e, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1d, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1c, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1b, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x1a, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x22, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x23, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x56, 12}, {0x00, 0}, {0x00, 0}, {0x00, 0} - }, - { - {0x57, 12}, {0x00, 0}, {0x00, 0}, {0x00, 0} - } +static VLC const coeff_tab1[25][4] = { + /* First row is run=2, then each row is run 2 + index */ + {{0x0e, 4}, {0x1d, 8}, {0x0e, 10}, {0x51, 12}}, + {{0x0d, 5}, {0x23, 9}, {0x0d, 10}, {0x00, 0}}, + {{0x0c, 5}, {0x22, 9}, {0x52, 12}, {0x00, 0}}, + {{0x0b, 5}, {0x0c, 10}, {0x53, 12}, {0x00, 0}}, + {{0x13, 6}, {0x0b, 10}, {0x54, 12}, {0x00, 0}}, + {{0x12, 6}, {0x0a, 10}, {0x00, 0}, {0x00, 0}}, + {{0x11, 6}, {0x09, 10}, {0x00, 0}, {0x00, 0}}, + {{0x10, 6}, {0x08, 10}, {0x00, 0}, {0x00, 0}}, + {{0x16, 7}, {0x55, 12}, {0x00, 0}, {0x00, 0}}, + {{0x15, 7}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x14, 7}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1c, 8}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1b, 8}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x21, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x20, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1f, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1e, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1d, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1c, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1b, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x1a, 9}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x22, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x23, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x56, 12}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + {{0x57, 12}, {0x00, 0}, {0x00, 0}, {0x00, 0}} + }; /* first coeffs of last = 1. indexing by [run][level-1] */ -static VLC coeff_tab2[2][3] = { - /* - run = 0 - */ - { - {0x07, 4}, {0x19, 9}, {0x05, 11} - }, - /* - run = 1 - */ - { - {0x0f, 6}, {0x04, 11}, {0x00, 0} - } +static VLC const coeff_tab2[2][3] = { + /* run = 0 */ + {{0x07, 4}, {0x19, 9}, {0x05, 11}}, + /* run = 1 */ + {{0x0f, 6}, {0x04, 11}, {0x00, 0}} }; /* rest of coeffs for last = 1. indexing by [run-2] */ -static VLC coeff_tab3[40][1] = { - {{0x0e, 6}}, {{0x0d, 6}}, {{0x0c, 6}}, - {{0x13, 7}}, {{0x12, 7}}, {{0x11, 7}}, {{0x10, 7}}, - {{0x1a, 8}}, {{0x19, 8}}, {{0x18, 8}}, {{0x17, 8}}, - {{0x16, 8}}, {{0x15, 8}}, {{0x14, 8}}, {{0x13, 8}}, - {{0x18, 9}}, {{0x17, 9}}, {{0x16, 9}}, {{0x15, 9}}, - {{0x14, 9}}, {{0x13, 9}}, {{0x12, 9}}, {{0x11, 9}}, - {{0x07, 10}}, {{0x06, 10}}, {{0x05, 10}}, {{0x04, 10}}, - {{0x24, 11}}, {{0x25, 11}}, {{0x26, 11}}, {{0x27, 11}}, - {{0x58, 12}}, {{0x59, 12}}, {{0x5a, 12}}, {{0x5b, 12}}, - {{0x5c, 12}}, {{0x5d, 12}}, {{0x5e, 12}}, {{0x5f, 12}}, - {{0x00, 0}} -}; - -/* New tables for Intra luminance coefficients. Same codewords, - different meaning */ +static VLC const coeff_tab3[40][1] = { + {{0x0e, 6}}, {{0x0d, 6}}, {{0x0c, 6}}, {{0x13, 7}}, + {{0x12, 7}}, {{0x11, 7}}, {{0x10, 7}}, {{0x1a, 8}}, + {{0x19, 8}}, {{0x18, 8}}, {{0x17, 8}}, {{0x16, 8}}, + {{0x15, 8}}, {{0x14, 8}}, {{0x13, 8}}, {{0x18, 9}}, + {{0x17, 9}}, {{0x16, 9}}, {{0x15, 9}}, {{0x14, 9}}, + {{0x13, 9}}, {{0x12, 9}}, {{0x11, 9}}, {{0x07, 10}}, + {{0x06, 10}}, {{0x05, 10}}, {{0x04, 10}}, {{0x24, 11}}, + {{0x25, 11}}, {{0x26, 11}}, {{0x27, 11}}, {{0x58, 12}}, + {{0x59, 12}}, {{0x5a, 12}}, {{0x5b, 12}}, {{0x5c, 12}}, + {{0x5d, 12}}, {{0x5e, 12}}, {{0x5f, 12}}, {{0x00, 0}} +}; + +/* + * New tables for Intra luminance coefficients. Same codewords, + * different meaning + */ /* Coeffs for last = 0, run = 0. Indexed by [level-1] */ -static VLC coeff_tab4[27] = { - /* - run = 0 - */ - {0x02, 2}, {0x06, 3}, {0x0f, 4}, {0x0d, 5}, - {0x0c, 5}, {0x15, 6}, {0x13, 6}, {0x12, 6}, - {0x17, 7}, {0x1f, 8}, {0x1e, 8}, {0x1d, 8}, - {0x25, 9}, {0x24, 9}, {0x23, 9}, {0x21, 9}, - {0x21, 10}, {0x20, 10}, {0x0f, 10}, {0x0e, 10}, - {0x07, 11}, {0x06, 11}, {0x20, 11}, {0x21, 11}, +static VLC const coeff_tab4[27] = { + /* run = 0 */ + {0x02, 2}, {0x06, 3}, {0x0f, 4}, + {0x0d, 5}, {0x0c, 5}, {0x15, 6}, + {0x13, 6}, {0x12, 6}, {0x17, 7}, + {0x1f, 8}, {0x1e, 8}, {0x1d, 8}, + {0x25, 9}, {0x24, 9}, {0x23, 9}, + {0x21, 9}, {0x21, 10}, {0x20, 10}, + {0x0f, 10}, {0x0e, 10}, {0x07, 11}, + {0x06, 11}, {0x20, 11}, {0x21, 11}, {0x50, 12}, {0x51, 12}, {0x52, 12} }; /* Coeffs for last = 0, run = 1. Indexed by [level-1] */ -static VLC coeff_tab5[10] = { - {0x0e, 4}, {0x14, 6}, {0x16, 7}, {0x1c, 8}, - {0x20, 9}, {0x1f, 9}, {0x0d, 10}, {0x22, 11}, - {0x53, 12}, {0x55, 12} +static VLC const coeff_tab5[10] = { + {0x0e, 4}, {0x14, 6}, {0x16, 7}, {0x1c, 8}, {0x20, 9}, + {0x1f, 9}, {0x0d, 10}, {0x22, 11}, {0x53, 12}, {0x55, 12} }; /* Coeffs for last = 0, run = 2 -> 9. Indexed by [run-2][level-1] */ static VLC coeff_tab6[8][5] = { - /* - run = 2 - */ - { - {0x0b, 5}, {0x15, 7}, {0x1e, 9}, {0x0c, 10}, - {0x56, 12} - }, - /* - run = 3 - */ - { - {0x11, 6}, {0x1b, 8}, {0x1d, 9}, {0x0b, 10}, - {0x00, 0} - }, - /* - run = 4 - */ - { - {0x10, 6}, {0x22, 9}, {0x0a, 10}, {0x00, 0}, - {0x00, 0} - }, - /* - run = 5 - */ - { - {0x0d, 6}, {0x1c, 9}, {0x08, 10}, {0x00, 0}, - {0x00, 0} - }, - /* - run = 6 - */ - { - {0x12, 7}, {0x1b, 9}, {0x54, 12}, {0x00, 0}, - {0x00, 0} - }, - /* - run = 7 - */ - { - {0x14, 7}, {0x1a, 9}, {0x57, 12}, {0x00, 0}, - {0x00, 0} - }, - /* - run = 8 - */ - { - {0x19, 8}, {0x09, 10}, {0x00, 0}, {0x00, 0}, - {0x00, 0} - }, - /* - run = 9 - */ - { - {0x18, 8}, {0x23, 11}, {0x00, 0}, {0x00, 0}, - {0x00, 0} - } + /* run = 2 */ + {{0x0b, 5}, {0x15, 7}, {0x1e, 9}, {0x0c, 10}, {0x56, 12}}, + + /* run = 3 */ + {{0x11, 6}, {0x1b, 8}, {0x1d, 9}, {0x0b, 10}, {0x00, 0}}, + + /* run = 4 */ + {{0x10, 6}, {0x22, 9}, {0x0a, 10}, {0x00, 0}, {0x00, 0}}, + + /* run = 5 */ + {{0x0d, 6}, {0x1c, 9}, {0x08, 10}, {0x00, 0}, {0x00, 0}}, + + /* run = 6 */ + {{0x12, 7}, {0x1b, 9}, {0x54, 12}, {0x00, 0}, {0x00, 0}}, + + /* run = 7 */ + {{0x14, 7}, {0x1a, 9}, {0x57, 12}, {0x00, 0}, {0x00, 0}}, + + /* run = 8 */ + {{0x19, 8}, {0x09, 10}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, + + /* run = 9 */ + {{0x18, 8}, {0x23, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0}} }; /* Coeffs for last = 0, run = 10 -> 14. Indexed by [run-10] */ -static VLC coeff_tab7[5][1] = { - {{0x17, 8}}, {{0x19, 9}}, {{0x18, 9}}, {{0x07, 10}}, +static VLC const coeff_tab7[5][1] = { + {{0x17, 8}}, + {{0x19, 9}}, + {{0x18, 9}}, + {{0x07, 10}}, {{0x58, 12}} }; /* Coeffs for last = 1, run = 0. Indexed by [level-1] */ -static VLC coeff_tab8[8] = { - {0x07, 4}, {0x0c, 6}, {0x16, 8}, {0x17, 9}, +static VLC const coeff_tab8[8] = { + {0x07, 4}, {0x0c, 6}, {0x16, 8}, {0x17, 9}, {0x06, 10}, {0x05, 11}, {0x04, 11}, {0x59, 12} }; /* Coeffs for last = 1, run = 1 -> 6. Indexed by [run-1][level-1] */ -static VLC coeff_tab9[6][3] = { - /* - run = 1 - */ - { - {0x0f, 6}, {0x16, 9}, {0x05, 10} - }, - /* - run = 2 - */ - { - {0x0e, 6}, {0x04, 10}, {0x00, 0} - }, - /* - run = 3 - */ - { - {0x11, 7}, {0x24, 11}, {0x00, 0} - }, - /* - run = 4 - */ - { - {0x10, 7}, {0x25, 11}, {0x00, 0} - }, - /* - run = 5 - */ - { - {0x13, 7}, {0x5a, 12}, {0x00, 0} - }, - /* - run = 6 - */ - { - {0x15, 8}, {0x5b, 12}, {0x00, 0} - } +static VLC const coeff_tab9[6][3] = { + /* run = 1 */ + {{0x0f, 6}, {0x16, 9}, {0x05, 10}}, + + /* run = 2 */ + {{0x0e, 6}, {0x04, 10}, {0x00, 0}}, + + /* run = 3 */ + {{0x11, 7}, {0x24, 11}, {0x00, 0}}, + + /* run = 4 */ + {{0x10, 7}, {0x25, 11}, {0x00, 0}}, + + /* run = 5 */ + {{0x13, 7}, {0x5a, 12}, {0x00, 0}}, + + /* run = 6 */ + {{0x15, 8}, {0x5b, 12}, {0x00, 0}} }; /* Coeffs for last = 1, run = 7 -> 20. Indexed by [run-7] */ -static VLC coeff_tab10[14][1] = { - {{0x14, 8}}, {{0x13, 8}}, {{0x1a, 8}}, {{0x15, 9}}, - {{0x14, 9}}, {{0x13, 9}}, {{0x12, 9}}, {{0x11, 9}}, - {{0x26, 11}}, {{0x27, 11}}, {{0x5c, 12}}, {{0x5d, 12}}, - {{0x5e, 12}}, {{0x5f, 12}} +static VLC const coeff_tab10[14][1] = { + {{0x14, 8}}, + {{0x13, 8}}, + {{0x1a, 8}}, + {{0x15, 9}}, + {{0x14, 9}}, + {{0x13, 9}}, + {{0x12, 9}}, + {{0x11, 9}}, + {{0x26, 11}}, + {{0x27, 11}}, + {{0x5c, 12}}, + {{0x5d, 12}}, + {{0x5e, 12}}, + {{0x5f, 12}} }; -static VLC *coeff_intra_last0[15] = { +static VLC const *coeff_intra_last0[15] = { coeff_tab4, coeff_tab5, coeff_tab6[0], @@ -531,7 +471,7 @@ coeff_tab7[4] }; -static VLC *coeff_intra_last1[21] = { +static VLC const *coeff_intra_last1[21] = { coeff_tab8, coeff_tab9[0], coeff_tab9[1], @@ -555,7 +495,7 @@ coeff_tab10[13], }; -static VLC *coeff_inter_last0[27] = { +static VLC const *coeff_inter_last0[27] = { coeff_tab0[0], coeff_tab0[1], coeff_tab1[0], @@ -585,7 +525,7 @@ coeff_tab1[24], }; -static VLC *coeff_inter_last1[42] = { +static VLC const *coeff_inter_last1[42] = { coeff_tab2[0], coeff_tab2[1], coeff_tab3[0], @@ -630,18 +570,20 @@ coeff_tab3[39], }; -static VLC **coeff_vlc[4] = { +static VLC const **coeff_vlc[4] = { coeff_intra_last0, coeff_intra_last1, coeff_inter_last0, coeff_inter_last1, }; -/* MCBPC Indexing by cbpc in first two bits, mode in last two. - CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10. - Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */ +/* + * MCBPC Indexing by cbpc in first two bits, mode in last two. + * CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10. + * Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. + */ -static VLC mcbpc_intra_tab[15] = { +static VLC const mcbpc_intra_tab[15] = { {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0}, {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0}, {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0}, @@ -651,19 +593,19 @@ /* MCBPC inter. Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */ -static VLC mcbpc_inter_tab[29] = { +static VLC const mcbpc_inter_tab[29] = { {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0}, {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0}, {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0}, {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9} }; -static const VLC cbpy_tab[16] = { +static VLC const cbpy_tab[16] = { {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4}, {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2} }; -static const VLC dcy_tab[511] = { +static VLC const dcy_tab[511] = { {0x100, 15}, {0x101, 15}, {0x102, 15}, {0x103, 15}, {0x104, 15}, {0x105, 15}, {0x106, 15}, {0x107, 15}, {0x108, 15}, {0x109, 15}, {0x10a, 15}, {0x10b, 15}, @@ -794,7 +736,7 @@ {0x1fd, 15}, {0x1fe, 15}, {0x1ff, 15}, }; -static const VLC dcc_tab[511] = { +static VLC const dcc_tab[511] = { {0x100, 16}, {0x101, 16}, {0x102, 16}, {0x103, 16}, {0x104, 16}, {0x105, 16}, {0x106, 16}, {0x107, 16}, {0x108, 16}, {0x109, 16}, {0x10a, 16}, {0x10b, 16}, @@ -926,7 +868,7 @@ }; -static const VLC mb_motion_table[65] = { +static VLC const mb_motion_table[65] = { {0x05, 13}, {0x07, 13}, {0x05, 12}, {0x07, 12}, {0x09, 12}, {0x0b, 12}, {0x0d, 12}, {0x0f, 12}, {0x09, 11}, {0x0b, 11}, {0x0d, 11}, {0x0f, 11}, @@ -951,147 +893,134 @@ * decoder tables * ******************************************************************/ -static const VLC mcbpc_intra_table[64] = { - {-1, 0}, - {20, 6}, {36, 6}, {52, 6}, {4, 4}, {4, 4}, {4, 4}, - {4, 4}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, - {19, 3}, {19, 3}, {19, 3}, {35, 3}, {35, 3}, {35, 3}, - {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {51, 3}, - {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, - {51, 3}, {3, 1}, - {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, - {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, - {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, - {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, - {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, - {3, 1} +static VLC const mcbpc_intra_table[64] = { + {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, + {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, + {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, + {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, + {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, + {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, + {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, + {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1} }; -static const VLC mcbpc_inter_table[257] = { - {VLC_ERROR, 0}, - {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8}, {19, 8}, - {19, 8}, - {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7}, {34, 7}, {34, 7}, - {34, 7}, - {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7}, {33, 7}, {33, 7}, {33, 7}, - {33, 7}, - {17, 7}, {17, 7}, {17, 7}, {17, 7}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, - {4, 6}, {4, 6}, {4, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, - 6}, - {48, 6}, {48, 6}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, - {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, +static VLC const mcbpc_inter_table[257] = { + {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8}, + {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7}, + {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7}, + {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, + {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, + {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, + {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, + {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, + {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, - {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, - {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, - {32, 4}, - {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {16, 4}, {16, 4}, {16, 4}, - {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, - {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, - {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, - {16, 4}, - {16, 4}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, - {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, - {1, 3}, {1, 3}, {1, 3}, {0, 1} -}; - -static const VLC cbpy_table[64] = { - {-1, 0}, {-1, 0}, {6, 6}, {9, 6}, {8, 5}, {8, 5}, {4, 5}, {4, 5}, - {2, 5}, {2, 5}, {1, 5}, {1, 5}, {0, 4}, {0, 4}, {0, 4}, {0, 4}, + {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, + {0, 1} +}; + +static VLC const cbpy_table[64] = { + {-1, 0}, {-1, 0}, {6, 6}, {9, 6}, {8, 5}, {8, 5}, {4, 5}, {4, 5}, + {2, 5}, {2, 5}, {1, 5}, {1, 5}, {0, 4}, {0, 4}, {0, 4}, {0, 4}, {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4}, - {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, - {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4}, {3, 4}, {3, 4}, {3, 4}, - {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4}, {7, 4}, {7, 4}, {7, 4}, - {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, - {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, - {15, 2}, {15, 2} -}; - - -VLC TMNMVtab0[] = { - {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2}, {1, 2}, {1, 2}, - {1, 2}, - {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2} -}; - -VLC TMNMVtab1[] = { - {12, 10}, {-12, 10}, {11, 10}, {-11, 10}, {10, 9}, {10, 9}, {-10, 9}, {-10, - 9}, - {9, 9}, {9, 9}, {-9, 9}, {-9, 9}, {8, 9}, {8, 9}, {-8, 9}, {-8, 9}, {7, 7}, - {7, 7}, - {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {-7, 7}, {-7, 7}, {-7, 7}, - {-7, 7}, - {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, - {6, 7}, - {6, 7}, {6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, {-6, - 7}, - {-6, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, - {-5, 7}, - {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, {4, 6}, {4, - 6}, - {4, 6}, - {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, - 6}, - {4, 6}, - {4, 6}, {4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, - 6}, - {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, - {-4, 6} -}; - -VLC TMNMVtab2[] = { - {32, 12}, {-32, 12}, {31, 12}, {-31, 12}, {30, 11}, {30, 11}, {-30, 11}, - {-30, 11}, - {29, 11}, {29, 11}, {-29, 11}, {-29, 11}, {28, 11}, {28, 11}, {-28, 11}, - {-28, 11}, - {27, 11}, {27, 11}, {-27, 11}, {-27, 11}, {26, 11}, {26, 11}, {-26, 11}, - {-26, 11}, - {25, 11}, {25, 11}, {-25, 11}, {-25, 11}, {24, 10}, {24, 10}, {24, 10}, - {24, 10}, - {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10}, {23, 10}, {23, 10}, {23, 10}, - {23, 10}, - {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10}, {22, 10}, {22, 10}, {22, 10}, - {22, 10}, - {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10}, {21, 10}, {21, 10}, {21, 10}, - {21, 10}, - {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10}, {20, 10}, {20, 10}, {20, 10}, - {20, 10}, - {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10}, {19, 10}, {19, 10}, {19, 10}, - {19, 10}, - {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10}, {18, 10}, {18, 10}, {18, 10}, - {18, 10}, - {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10}, {17, 10}, {17, 10}, {17, 10}, - {17, 10}, - {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10}, {16, 10}, {16, 10}, {16, 10}, - {16, 10}, - {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10}, {15, 10}, {15, 10}, {15, 10}, - {15, 10}, - {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10}, {14, 10}, {14, 10}, {14, 10}, - {14, 10}, - {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10}, {13, 10}, {13, 10}, {13, 10}, - {13, 10}, + {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, + {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4}, {3, 4}, {3, 4}, {3, 4}, + {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4}, {7, 4}, {7, 4}, {7, 4}, + {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, + {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2} +}; + + +static VLC const TMNMVtab0[] = { + {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2}, + {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2} +}; + +static VLC const TMNMVtab1[] = { + {12, 10}, {-12, 10}, {11, 10}, {-11, 10}, + {10, 9}, {10, 9}, {-10, 9}, {-10, 9}, + {9, 9}, {9, 9}, {-9, 9}, {-9, 9}, + {8, 9}, {8, 9}, {-8, 9}, {-8, 9}, + {7, 7}, {7, 7}, {7, 7}, {7, 7}, + {7, 7}, {7, 7}, {7, 7}, {7, 7}, + {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7}, + {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7}, + {6, 7}, {6, 7}, {6, 7}, {6, 7}, + {6, 7}, {6, 7}, {6, 7}, {6, 7}, + {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, + {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7}, + {5, 7}, {5, 7}, {5, 7}, {5, 7}, + {5, 7}, {5, 7}, {5, 7}, {5, 7}, + {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, + {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7}, + {4, 6}, {4, 6}, {4, 6}, {4, 6}, + {4, 6}, {4, 6}, {4, 6}, {4, 6}, + {4, 6}, {4, 6}, {4, 6}, {4, 6}, + {4, 6}, {4, 6}, {4, 6}, {4, 6}, + {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, + {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, + {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}, + {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6} +}; + +static VLC const TMNMVtab2[] = { + {32, 12}, {-32, 12}, {31, 12}, {-31, 12}, + {30, 11}, {30, 11}, {-30, 11}, {-30, 11}, + {29, 11}, {29, 11}, {-29, 11}, {-29, 11}, + {28, 11}, {28, 11}, {-28, 11}, {-28, 11}, + {27, 11}, {27, 11}, {-27, 11}, {-27, 11}, + {26, 11}, {26, 11}, {-26, 11}, {-26, 11}, + {25, 11}, {25, 11}, {-25, 11}, {-25, 11}, + {24, 10}, {24, 10}, {24, 10}, {24, 10}, + {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10}, + {23, 10}, {23, 10}, {23, 10}, {23, 10}, + {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10}, + {22, 10}, {22, 10}, {22, 10}, {22, 10}, + {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10}, + {21, 10}, {21, 10}, {21, 10}, {21, 10}, + {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10}, + {20, 10}, {20, 10}, {20, 10}, {20, 10}, + {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10}, + {19, 10}, {19, 10}, {19, 10}, {19, 10}, + {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10}, + {18, 10}, {18, 10}, {18, 10}, {18, 10}, + {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10}, + {17, 10}, {17, 10}, {17, 10}, {17, 10}, + {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10}, + {16, 10}, {16, 10}, {16, 10}, {16, 10}, + {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10}, + {15, 10}, {15, 10}, {15, 10}, {15, 10}, + {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10}, + {14, 10}, {14, 10}, {14, 10}, {14, 10}, + {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10}, + {13, 10}, {13, 10}, {13, 10}, {13, 10}, {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10} }; -VLC DCT3Dtab0[] = { +static VLC const DCT3Dtab0[] = { {4225, 7}, {4209, 7}, {4193, 7}, {4177, 7}, {193, 7}, {177, 7}, {161, 7}, {4, 7}, {4161, 6}, {4161, 6}, {4145, 6}, {4145, 6}, {4129, 6}, {4129, 6}, {4113, 6}, {4113, 6}, {145, 6}, {145, 6}, @@ -1114,7 +1043,7 @@ }; -VLC DCT3Dtab1[] = { +static VLC const DCT3Dtab1[] = { {9, 10}, {8, 10}, {4481, 9}, {4481, 9}, {4465, 9}, {4465, 9}, {4449, 9}, {4449, 9}, {4433, 9}, {4433, 9}, {4417, 9}, {4417, 9}, {4401, 9}, {4401, 9}, {4385, 9}, {4385, 9}, {4369, 9}, {4369, 9}, @@ -1133,7 +1062,7 @@ {19, 8}, {19, 8}, {5, 8}, {5, 8}, {5, 8}, {5, 8} }; -VLC DCT3Dtab2[] = { +static VLC const DCT3Dtab2[] = { {4114, 11}, {4114, 11}, {4099, 11}, {4099, 11}, {11, 11}, {11, 11}, {10, 11}, {10, 11}, {4545, 10}, {4545, 10}, {4545, 10}, {4545, 10}, {4529, 10}, {4529, 10}, {4529, 10}, {4529, 10}, {4513, 10}, {4513, 10}, @@ -1160,7 +1089,7 @@ /* New tables for Intra luminance blocks */ -VLC DCT3Dtab3[] = { +static VLC const DCT3Dtab3[] = { {0x10401, 7}, {0x10301, 7}, {0x00601, 7}, {0x10501, 7}, {0x00701, 7}, {0x00202, 7}, {0x00103, 7}, {0x00009, 7}, {0x10002, 6}, {0x10002, 6}, {0x00501, 6}, {0x00501, 6}, @@ -1192,7 +1121,7 @@ }; -VLC DCT3Dtab4[] = { +static VLC const DCT3Dtab4[] = { {0x00012, 10}, {0x00011, 10}, {0x10e01, 9}, {0x10e01, 9}, {0x10d01, 9}, {0x10d01, 9}, {0x10c01, 9}, {0x10c01, 9}, {0x10b01, 9}, {0x10b01, 9}, {0x10a01, 9}, {0x10a01, 9}, @@ -1219,7 +1148,7 @@ {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8} }; -VLC DCT3Dtab5[] = { +static VLC const DCT3Dtab5[] = { {0x10007, 11}, {0x10007, 11}, {0x10006, 11}, {0x10006, 11}, {0x00016, 11}, {0x00016, 11}, {0x00015, 11}, {0x00015, 11}, {0x10202, 10}, {0x10202, 10}, {0x10202, 10}, {0x10202, 10}, @@ -1252,7 +1181,19 @@ {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7} }; -VLC ERRtab[] = { +static short const dc_threshold[] = { + 26708, 29545, 25120, 28265, 29281, 8313, 29557, 29541, + 18208, 21838, 18208, 19536, 29472, 26223, 30580, 29281, + 8293, 25956, 26994, 25974, 8292, 29286, 28015, 22560, + 18774, 8260, 20557, 18245, 8244, 26664, 29812, 14960, + 12079, 30583, 11895, 30328, 25705, 28462, 26482, 29472, + 30063, 25458, 29541, 8233, 29505, 8299, 28518, 8306, + 26740, 8293, 28531, 29301, 25955, 8307, 28532, 31008, + 30063, 8306, 26980, 29811, 26994, 30050, 28532, 2674 +}; + + +static VLC const ERRtab[] = { {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}, @@ -1260,101 +1201,9 @@ {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0} }; -static const VLC dc_lum_tab[] = { - {0, 0}, - {4, 3}, {3, 3}, {0, 3}, +static VLC const dc_lum_tab[] = { + {0, 0}, {4, 3}, {3, 3}, {0, 3}, {2, 2}, {2, 2}, {1, 2}, {1, 2}, }; -static __inline int -get_coeff(Bitstream * bs, - int *run, - int *last, - int intra, - int short_video_header) -{ - - uint32_t mode; - const VLC *tab; - int32_t level; - - if (short_video_header) // inter-VLCs will be used for both intra and inter blocks - intra = 0; - - tab = &DCT3D[intra][BitstreamShowBits(bs, 12)]; - - if (tab->code == -1) - goto error; - - BitstreamSkip(bs, tab->len); - - if (tab->code != ESCAPE) { - if (!intra) { - *run = (tab->code >> 4) & 255; - level = tab->code & 15; - *last = (tab->code >> 12) & 1; - } else { - *run = (tab->code >> 8) & 255; - level = tab->code & 255; - *last = (tab->code >> 16) & 1; - } - return BitstreamGetBit(bs) ? -level : level; - } - - if (short_video_header) { - // escape mode 4 - H.263 type, only used if short_video_header = 1 - *last = BitstreamGetBit(bs); - *run = BitstreamGetBits(bs, 6); - level = BitstreamGetBits(bs, 8); - - if (level == 0 || level == 128) - DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level); - - return (level >= 128 ? -(256 - level) : level); - } - - mode = BitstreamShowBits(bs, 2); - - if (mode < 3) { - BitstreamSkip(bs, (mode == 2) ? 2 : 1); - - tab = &DCT3D[intra][BitstreamShowBits(bs, 12)]; - if (tab->code == -1) - goto error; - - BitstreamSkip(bs, tab->len); - - if (!intra) { - *run = (tab->code >> 4) & 255; - level = tab->code & 15; - *last = (tab->code >> 12) & 1; - } else { - *run = (tab->code >> 8) & 255; - level = tab->code & 255; - *last = (tab->code >> 16) & 1; - } - - if (mode < 2) // first escape mode, level is offset - level += max_level[*last + (!intra << 1)][*run]; // need to add back the max level - else if (mode == 2) // second escape mode, run is offset - *run += max_run[*last + (!intra << 1)][level] + 1; - - return BitstreamGetBit(bs) ? -level : level; - } - // third escape mode - fixed length codes - BitstreamSkip(bs, 2); - *last = BitstreamGetBits(bs, 1); - *run = BitstreamGetBits(bs, 6); - BitstreamSkip(bs, 1); // marker - level = BitstreamGetBits(bs, 12); - BitstreamSkip(bs, 1); // marker - - return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level; - - error: - *run = VLC_ERROR; - return 0; - -} - -#endif /* _VLC_CODES_H */ +#endif /* _VLC_CODES_H */