vlc.h
上传用户:hkgotone
上传日期:2013-02-17
资源大小:293k
文件大小:11k
源码类别:

Windows Mobile

开发平台:

C/C++

  1. /* vlc.h, variable length code tables (used by routines in putvlc.c)        */
  2. /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
  3. /*
  4.  * Disclaimer of Warranty
  5.  *
  6.  * These software programs are available to the user without any license fee or
  7.  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
  8.  * any and all warranties, whether express, implied, or statuary, including any
  9.  * implied warranties or merchantability or of fitness for a particular
  10.  * purpose.  In no event shall the copyright-holder be liable for any
  11.  * incidental, punitive, or consequential damages of any kind whatsoever
  12.  * arising from the use of these programs.
  13.  *
  14.  * This disclaimer of warranty extends to the user of these programs and user's
  15.  * customers, employees, agents, transferees, successors, and assigns.
  16.  *
  17.  * The MPEG Software Simulation Group does not represent or warrant that the
  18.  * programs furnished hereunder are free of infringement of any third-party
  19.  * patents.
  20.  *
  21.  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
  22.  * are subject to royalty fees to patent holders.  Many of these patents are
  23.  * general enough such that they are unavoidable regardless of implementation
  24.  * design.
  25.  *
  26.  */
  27. /* type definitions for variable length code table entries */
  28. typedef struct
  29. {
  30.   unsigned char code; /* right justified */
  31.   char len;
  32. } VLCtable;
  33. /* for codes longer than 8 bits (excluding leading zeroes) */
  34. typedef struct
  35. {
  36.   unsigned short code; /* right justified */
  37.   char len;
  38. } sVLCtable;
  39. /* data from ISO/IEC 13818-2 DIS, Annex B, variable length code tables */
  40. /* Table B-1, variable length codes for macroblock_address_increment
  41.  *
  42.  * indexed by [macroblock_address_increment-1]
  43.  * 'macroblock_escape' is treated elsewhere
  44.  */
  45. static VLCtable addrinctab[33]=
  46. {
  47.   {0x01,1},  {0x03,3},  {0x02,3},  {0x03,4},
  48.   {0x02,4},  {0x03,5},  {0x02,5},  {0x07,7},
  49.   {0x06,7},  {0x0b,8},  {0x0a,8},  {0x09,8},
  50.   {0x08,8},  {0x07,8},  {0x06,8},  {0x17,10},
  51.   {0x16,10}, {0x15,10}, {0x14,10}, {0x13,10},
  52.   {0x12,10}, {0x23,11}, {0x22,11}, {0x21,11},
  53.   {0x20,11}, {0x1f,11}, {0x1e,11}, {0x1d,11},
  54.   {0x1c,11}, {0x1b,11}, {0x1a,11}, {0x19,11},
  55.   {0x18,11}
  56. };
  57. /* Table B-2, B-3, B-4 variable length codes for macroblock_type
  58.  *
  59.  * indexed by [macroblock_type]
  60.  */
  61. static VLCtable mbtypetab[3][32]=
  62. {
  63.  /* I */
  64.  {
  65.   {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  66.   {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  67.   {0,0}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  68.   {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}
  69.  },
  70.  /* P */
  71.  {
  72.   {0,0}, {3,5}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  73.   {1,3}, {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  74.   {0,0}, {1,6}, {1,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  75.   {0,0}, {0,0}, {2,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}
  76.  },
  77.  /* B */
  78.  {
  79.   {0,0}, {3,5}, {0,0}, {0,0}, {2,3}, {0,0}, {3,3}, {0,0},
  80.   {2,4}, {0,0}, {3,4}, {0,0}, {2,2}, {0,0}, {3,2}, {0,0},
  81.   {0,0}, {1,6}, {0,0}, {0,0}, {0,0}, {0,0}, {2,6}, {0,0},
  82.   {0,0}, {0,0}, {3,6}, {0,0}, {0,0}, {0,0}, {2,5}, {0,0}
  83.  }
  84. };
  85. /* Table B-5 ... B-8 variable length codes for macroblock_type in
  86.  *  scalable sequences
  87.  *
  88.  * not implemented
  89.  */
  90. /* Table B-9, variable length codes for coded_block_pattern
  91.  *
  92.  * indexed by [coded_block_pattern]
  93.  */
  94. static VLCtable cbptable[64]=
  95. {
  96.   {0x01,9}, {0x0b,5}, {0x09,5}, {0x0d,6}, 
  97.   {0x0d,4}, {0x17,7}, {0x13,7}, {0x1f,8}, 
  98.   {0x0c,4}, {0x16,7}, {0x12,7}, {0x1e,8}, 
  99.   {0x13,5}, {0x1b,8}, {0x17,8}, {0x13,8}, 
  100.   {0x0b,4}, {0x15,7}, {0x11,7}, {0x1d,8}, 
  101.   {0x11,5}, {0x19,8}, {0x15,8}, {0x11,8}, 
  102.   {0x0f,6}, {0x0f,8}, {0x0d,8}, {0x03,9}, 
  103.   {0x0f,5}, {0x0b,8}, {0x07,8}, {0x07,9}, 
  104.   {0x0a,4}, {0x14,7}, {0x10,7}, {0x1c,8}, 
  105.   {0x0e,6}, {0x0e,8}, {0x0c,8}, {0x02,9}, 
  106.   {0x10,5}, {0x18,8}, {0x14,8}, {0x10,8}, 
  107.   {0x0e,5}, {0x0a,8}, {0x06,8}, {0x06,9}, 
  108.   {0x12,5}, {0x1a,8}, {0x16,8}, {0x12,8}, 
  109.   {0x0d,5}, {0x09,8}, {0x05,8}, {0x05,9}, 
  110.   {0x0c,5}, {0x08,8}, {0x04,8}, {0x04,9},
  111.   {0x07,3}, {0x0a,5}, {0x08,5}, {0x0c,6}
  112. };
  113. /* Table B-10, variable length codes for motion_code
  114.  *
  115.  * indexed by [abs(motion_code)]
  116.  * sign of motion_code is treated elsewhere
  117.  */
  118. static VLCtable motionvectab[17]=
  119. {
  120.   {0x01,1},  {0x01,2},  {0x01,3},  {0x01,4},
  121.   {0x03,6},  {0x05,7},  {0x04,7},  {0x03,7},
  122.   {0x0b,9},  {0x0a,9},  {0x09,9},  {0x11,10},
  123.   {0x10,10}, {0x0f,10}, {0x0e,10}, {0x0d,10},
  124.   {0x0c,10}
  125. };
  126. /* Table B-11, variable length codes for dmvector
  127.  *
  128.  * treated elsewhere
  129.  */
  130. /* Table B-12, variable length codes for dct_dc_size_luminance
  131.  *
  132.  * indexed by [dct_dc_size_luminance]
  133.  */
  134. static sVLCtable DClumtab[12]=
  135. {
  136.   {0x0004,3}, {0x0000,2}, {0x0001,2}, {0x0005,3}, {0x0006,3}, {0x000e,4},
  137.   {0x001e,5}, {0x003e,6}, {0x007e,7}, {0x00fe,8}, {0x01fe,9}, {0x01ff,9}
  138. };
  139. /* Table B-13, variable length codes for dct_dc_size_chrominance
  140.  *
  141.  * indexed by [dct_dc_size_chrominance]
  142.  */
  143. static sVLCtable DCchromtab[12]=
  144. {
  145.   {0x0000,2}, {0x0001,2}, {0x0002,2}, {0x0006,3}, {0x000e,4}, {0x001e,5},
  146.   {0x003e,6}, {0x007e,7}, {0x00fe,8}, {0x01fe,9}, {0x03fe,10},{0x03ff,10}
  147. };
  148. /* Table B-14, DCT coefficients table zero
  149.  *
  150.  * indexed by [run][level-1]
  151.  * split into two tables (dct_code_tab1, dct_code_tab2) to reduce size
  152.  * 'first DCT coefficient' condition and 'End of Block' are treated elsewhere
  153.  * codes do not include s (sign bit)
  154.  */
  155. static VLCtable dct_code_tab1[2][40]=
  156. {
  157.  /* run = 0, level = 1...40 */
  158.  {
  159.   {0x03, 2}, {0x04, 4}, {0x05, 5}, {0x06, 7},
  160.   {0x26, 8}, {0x21, 8}, {0x0a,10}, {0x1d,12},
  161.   {0x18,12}, {0x13,12}, {0x10,12}, {0x1a,13},
  162.   {0x19,13}, {0x18,13}, {0x17,13}, {0x1f,14},
  163.   {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
  164.   {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
  165.   {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
  166.   {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
  167.   {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
  168.   {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
  169.  },
  170.  /* run = 1, level = 1...18 */
  171.  {
  172.   {0x03, 3}, {0x06, 6}, {0x25, 8}, {0x0c,10},
  173.   {0x1b,12}, {0x16,13}, {0x15,13}, {0x1f,15},
  174.   {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
  175.   {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
  176.   {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
  177.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  178.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  179.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  180.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  181.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
  182.  }
  183. };
  184. static VLCtable dct_code_tab2[30][5]=
  185. {
  186.   /* run = 2...31, level = 1...5 */
  187.   {{0x05, 4}, {0x04, 7}, {0x0b,10}, {0x14,12}, {0x14,13}},
  188.   {{0x07, 5}, {0x24, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
  189.   {{0x06, 5}, {0x0f,10}, {0x12,12}, {0x00, 0}, {0x00, 0}},
  190.   {{0x07, 6}, {0x09,10}, {0x12,13}, {0x00, 0}, {0x00, 0}},
  191.   {{0x05, 6}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
  192.   {{0x04, 6}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  193.   {{0x07, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  194.   {{0x05, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  195.   {{0x27, 8}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  196.   {{0x23, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  197.   {{0x22, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  198.   {{0x20, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  199.   {{0x0e,10}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  200.   {{0x0d,10}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  201.   {{0x08,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  202.   {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  203.   {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  204.   {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  205.   {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  206.   {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  207.   {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  208.   {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  209.   {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  210.   {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  211.   {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  212.   {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  213.   {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  214.   {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  215.   {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  216.   {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
  217. };
  218. /* Table B-15, DCT coefficients table one
  219.  *
  220.  * indexed by [run][level-1]
  221.  * split into two tables (dct_code_tab1a, dct_code_tab2a) to reduce size
  222.  * 'End of Block' is treated elsewhere
  223.  * codes do not include s (sign bit)
  224.  */
  225. static VLCtable dct_code_tab1a[2][40]=
  226. {
  227.  /* run = 0, level = 1...40 */
  228.  {
  229.   {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
  230.   {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
  231.   {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
  232.   {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
  233.   {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
  234.   {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
  235.   {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
  236.   {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
  237.   {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
  238.   {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
  239.  },
  240.  /* run = 1, level = 1...18 */
  241.  {
  242.   {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
  243.   {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
  244.   {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
  245.   {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
  246.   {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
  247.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  248.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  249.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  250.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
  251.   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
  252.  }
  253. };
  254. static VLCtable dct_code_tab2a[30][5]=
  255. {
  256.   /* run = 2...31, level = 1...5 */
  257.   {{0x05, 5}, {0x07, 7}, {0xfc, 8}, {0x0c,10}, {0x14,13}},
  258.   {{0x07, 5}, {0x26, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
  259.   {{0x06, 6}, {0xfd, 8}, {0x12,12}, {0x00, 0}, {0x00, 0}},
  260.   {{0x07, 6}, {0x04, 9}, {0x12,13}, {0x00, 0}, {0x00, 0}},
  261.   {{0x06, 7}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
  262.   {{0x04, 7}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  263.   {{0x05, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  264.   {{0x78, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  265.   {{0x7a, 7}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  266.   {{0x21, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  267.   {{0x25, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  268.   {{0x24, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  269.   {{0x05, 9}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  270.   {{0x07, 9}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  271.   {{0x0d,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  272.   {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  273.   {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  274.   {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  275.   {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  276.   {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  277.   {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  278.   {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  279.   {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  280.   {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  281.   {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  282.   {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  283.   {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  284.   {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  285.   {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
  286.   {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
  287. };