Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

putvlc.h

00001 /* vlc.h, variable length code tables (used by routines in putvlc.c)        */
00002 
00003 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
00004 
00005 /*
00006  * Disclaimer of Warranty
00007  *
00008  * These software programs are available to the user without any license fee or
00009  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
00010  * any and all warranties, whether express, implied, or statuary, including any
00011  * implied warranties or merchantability or of fitness for a particular
00012  * purpose.  In no event shall the copyright-holder be liable for any
00013  * incidental, punitive, or consequential damages of any kind whatsoever
00014  * arising from the use of these programs.
00015  *
00016  * This disclaimer of warranty extends to the user of these programs and user's
00017  * customers, employees, agents, transferees, successors, and assigns.
00018  *
00019  * The MPEG Software Simulation Group does not represent or warrant that the
00020  * programs furnished hereunder are free of infringement of any third-party
00021  * patents.
00022  *
00023  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
00024  * are subject to royalty fees to patent holders.  Many of these patents are
00025  * general enough such that they are unavoidable regardless of implementation
00026  * design.
00027  *
00028  */
00029 
00030 /* type definitions for variable length code table entries */
00031 
00032 typedef struct
00033 {
00034   unsigned char code; /* right justified */
00035   char len;
00036 } VLCtable;
00037 
00038 /* for codes longer than 8 bits (excluding leading zeroes) */
00039 typedef struct
00040 {
00041   unsigned short code; /* right justified */
00042   char len;
00043 } sVLCtable;
00044 
00045 
00046 /* data from ISO/IEC 13818-2 DIS, Annex B, variable length code tables */
00047 
00048 /* Table B-1, variable length codes for macroblock_address_increment
00049  *
00050  * indexed by [macroblock_address_increment-1]
00051  * 'macroblock_escape' is treated elsewhere
00052  */
00053 
00054 const static VLCtable addrinctab[33]=
00055 {
00056   {0x01,1},  {0x03,3},  {0x02,3},  {0x03,4},
00057   {0x02,4},  {0x03,5},  {0x02,5},  {0x07,7},
00058   {0x06,7},  {0x0b,8},  {0x0a,8},  {0x09,8},
00059   {0x08,8},  {0x07,8},  {0x06,8},  {0x17,10},
00060   {0x16,10}, {0x15,10}, {0x14,10}, {0x13,10},
00061   {0x12,10}, {0x23,11}, {0x22,11}, {0x21,11},
00062   {0x20,11}, {0x1f,11}, {0x1e,11}, {0x1d,11},
00063   {0x1c,11}, {0x1b,11}, {0x1a,11}, {0x19,11},
00064   {0x18,11}
00065 };
00066 
00067 
00068 /* Table B-2, B-3, B-4 variable length codes for macroblock_type
00069  *
00070  * indexed by [macroblock_type]
00071  */
00072 
00073 const static VLCtable mbtypetab[3][32]=
00074 {
00075  /* I */
00076  {
00077   {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
00078   {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
00079   {0,0}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
00080   {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}
00081  },
00082  /* P */
00083  {
00084   {0,0}, {3,5}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
00085   {1,3}, {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
00086   {0,0}, {1,6}, {1,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
00087   {0,0}, {0,0}, {2,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}
00088  },
00089  /* B */
00090  {
00091   {0,0}, {3,5}, {0,0}, {0,0}, {2,3}, {0,0}, {3,3}, {0,0},
00092   {2,4}, {0,0}, {3,4}, {0,0}, {2,2}, {0,0}, {3,2}, {0,0},
00093   {0,0}, {1,6}, {0,0}, {0,0}, {0,0}, {0,0}, {2,6}, {0,0},
00094   {0,0}, {0,0}, {3,6}, {0,0}, {0,0}, {0,0}, {2,5}, {0,0}
00095  }
00096 };
00097 
00098 
00099 /* Table B-5 ... B-8 variable length codes for macroblock_type in
00100  *  scalable sequences
00101  *
00102  * not implemented
00103  */
00104 
00105 /* Table B-9, variable length codes for coded_block_pattern
00106  *
00107  * indexed by [coded_block_pattern]
00108  */
00109 
00110 const static VLCtable cbptable[64]=
00111 {
00112   {0x01,9}, {0x0b,5}, {0x09,5}, {0x0d,6}, 
00113   {0x0d,4}, {0x17,7}, {0x13,7}, {0x1f,8}, 
00114   {0x0c,4}, {0x16,7}, {0x12,7}, {0x1e,8}, 
00115   {0x13,5}, {0x1b,8}, {0x17,8}, {0x13,8}, 
00116   {0x0b,4}, {0x15,7}, {0x11,7}, {0x1d,8}, 
00117   {0x11,5}, {0x19,8}, {0x15,8}, {0x11,8}, 
00118   {0x0f,6}, {0x0f,8}, {0x0d,8}, {0x03,9}, 
00119   {0x0f,5}, {0x0b,8}, {0x07,8}, {0x07,9}, 
00120   {0x0a,4}, {0x14,7}, {0x10,7}, {0x1c,8}, 
00121   {0x0e,6}, {0x0e,8}, {0x0c,8}, {0x02,9}, 
00122   {0x10,5}, {0x18,8}, {0x14,8}, {0x10,8}, 
00123   {0x0e,5}, {0x0a,8}, {0x06,8}, {0x06,9}, 
00124   {0x12,5}, {0x1a,8}, {0x16,8}, {0x12,8}, 
00125   {0x0d,5}, {0x09,8}, {0x05,8}, {0x05,9}, 
00126   {0x0c,5}, {0x08,8}, {0x04,8}, {0x04,9},
00127   {0x07,3}, {0x0a,5}, {0x08,5}, {0x0c,6}
00128 };
00129 
00130 
00131 /* Table B-14, DCT coefficients table zero
00132  *
00133  * indexed by [run][level-1]
00134  * split into two tables (dct_code_tab1, dct_code_tab2) to reduce size
00135  * 'first DCT coefficient' condition and 'End of Block' are treated elsewhere
00136  * codes do not include s (sign bit)
00137  */
00138 
00139 const static VLCtable dct_code_tab1[2][40]=
00140 {
00141  /* run = 0, level = 1...40 */
00142  {
00143   {0x03, 2}, {0x04, 4}, {0x05, 5}, {0x06, 7},
00144   {0x26, 8}, {0x21, 8}, {0x0a,10}, {0x1d,12},
00145   {0x18,12}, {0x13,12}, {0x10,12}, {0x1a,13},
00146   {0x19,13}, {0x18,13}, {0x17,13}, {0x1f,14},
00147   {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
00148   {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
00149   {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
00150   {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
00151   {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
00152   {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
00153  },
00154  /* run = 1, level = 1...18 */
00155  {
00156   {0x03, 3}, {0x06, 6}, {0x25, 8}, {0x0c,10},
00157   {0x1b,12}, {0x16,13}, {0x15,13}, {0x1f,15},
00158   {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
00159   {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
00160   {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
00161   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00162   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00163   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00164   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00165   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
00166  }
00167 };
00168 
00169 const static VLCtable dct_code_tab2[30][5]=
00170 {
00171   /* run = 2...31, level = 1...5 */
00172   {{0x05, 4}, {0x04, 7}, {0x0b,10}, {0x14,12}, {0x14,13}},
00173   {{0x07, 5}, {0x24, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
00174   {{0x06, 5}, {0x0f,10}, {0x12,12}, {0x00, 0}, {0x00, 0}},
00175   {{0x07, 6}, {0x09,10}, {0x12,13}, {0x00, 0}, {0x00, 0}},
00176   {{0x05, 6}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
00177   {{0x04, 6}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00178   {{0x07, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00179   {{0x05, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00180   {{0x27, 8}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00181   {{0x23, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00182   {{0x22, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00183   {{0x20, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00184   {{0x0e,10}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00185   {{0x0d,10}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00186   {{0x08,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00187   {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00188   {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00189   {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00190   {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00191   {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00192   {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00193   {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00194   {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00195   {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00196   {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00197   {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00198   {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00199   {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00200   {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00201   {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
00202 };
00203 
00204 
00205 /* Table B-15, DCT coefficients table one
00206  *
00207  * indexed by [run][level-1]
00208  * split into two tables (dct_code_tab1a, dct_code_tab2a) to reduce size
00209  * 'End of Block' is treated elsewhere
00210  * codes do not include s (sign bit)
00211  */
00212 
00213 const static VLCtable dct_code_tab1a[2][40]=
00214 {
00215  /* run = 0, level = 1...40 */
00216  {
00217   {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
00218   {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
00219   {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
00220   {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
00221   {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
00222   {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
00223   {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
00224   {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
00225   {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
00226   {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
00227  },
00228  /* run = 1, level = 1...18 */
00229  {
00230   {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
00231   {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
00232   {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
00233   {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
00234   {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
00235   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00236   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00237   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00238   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
00239   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
00240  }
00241 };
00242 
00243 const static VLCtable dct_code_tab2a[30][5]=
00244 {
00245   /* run = 2...31, level = 1...5 */
00246   {{0x05, 5}, {0x07, 7}, {0xfc, 8}, {0x0c,10}, {0x14,13}},
00247   {{0x07, 5}, {0x26, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
00248   {{0x06, 6}, {0xfd, 8}, {0x12,12}, {0x00, 0}, {0x00, 0}},
00249   {{0x07, 6}, {0x04, 9}, {0x12,13}, {0x00, 0}, {0x00, 0}},
00250   {{0x06, 7}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
00251   {{0x04, 7}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00252   {{0x05, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00253   {{0x78, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00254   {{0x7a, 7}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00255   {{0x21, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00256   {{0x25, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00257   {{0x24, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00258   {{0x05, 9}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00259   {{0x07, 9}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00260   {{0x0d,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00261   {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00262   {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00263   {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00264   {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00265   {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00266   {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00267   {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00268   {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00269   {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00270   {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00271   {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00272   {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00273   {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00274   {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
00275   {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
00276 };
00277 
00278 /* MPEG-4 matrices */
00279 static const uint8_t mpeg4_default_intra_matrix[64] = {
00280   8, 17, 18, 19, 21, 23, 25, 27,
00281  17, 18, 19, 21, 23, 25, 27, 28,
00282  20, 21, 22, 23, 24, 26, 28, 30,
00283  21, 22, 23, 24, 26, 28, 30, 32,
00284  22, 23, 24, 26, 28, 30, 32, 35,
00285  23, 24, 26, 28, 30, 32, 35, 38,
00286  25, 26, 28, 30, 32, 35, 38, 41,
00287  27, 28, 30, 32, 35, 38, 41, 45, 
00288 };
00289 
00290 static const uint8_t mpeg4_default_non_intra_matrix[64] = {
00291  16, 17, 18, 19, 20, 21, 22, 23,
00292  17, 18, 19, 20, 21, 22, 23, 24,
00293  18, 19, 20, 21, 22, 23, 24, 25,
00294  19, 20, 21, 22, 23, 24, 26, 27,
00295  20, 21, 22, 23, 25, 26, 27, 28,
00296  21, 22, 23, 24, 26, 27, 28, 30,
00297  22, 23, 24, 26, 27, 28, 30, 31,
00298  23, 24, 25, 27, 28, 30, 31, 33,
00299 };
00300 

Generated on Tue Dec 20 10:14:50 2005 for vlc-0.8.4a by  doxygen 1.4.2