1. /*
  2.     Project  : H.264 encoder test    
  3.     Module   : Tables
  4.  
  5.     Author   : Marko 'Fador' Viitanen
  6.  
  7.     Date     : 25/6/2009
  8.     Modified : 25/6/2009
  9.  
  10. */
  11. #include "common.h"
  12. #include "cavlc.h"
  13. #include "tables.h"
  14.  
  15. //             [total_zeros][totalCoeffs]
  16.  
  17. const bitTable total_zeros_4x4[16][16]=
  18. {
  19.     {{1,1},{3,7},{4,5},{5,3},{4,5},{6,1},{6,1},{6,1},{6,1},{5,1},{4,0},{4,0},{3,0},{2,0},{1,0},{0,0}},
  20.     {{3,3},{3,6},{3,7},{3,7},{4,4},{5,1},{5,1},{4,1},{6,0},{5,0},{4,1},{4,1},{3,1},{2,1},{1,1},{0,0}},
  21.     {{3,2},{3,5},{3,6},{4,5},{4,3},{3,7},{3,5},{5,1},{4,1},{3,1},{3,1},{2,1},{1,1},{1,1},{0,0},{0,0}},
  22.     {{4,3},{3,4},{3,5},{4,4},{3,7},{3,6},{3,4},{3,3},{2,3},{2,3},{3,2},{1,1},{2,1},{0,0},{0,0},{0,0}},
  23.     {{4,2},{3,3},{4,4},{3,6},{3,6},{3,5},{3,3},{2,3},{2,2},{2,2},{1,1},{3,1},{0,0},{0,0},{0,0},{0,0}},
  24.     {{5,3},{4,5},{4,3},{3,5},{3,5},{3,4},{2,3},{2,2},{3,1},{2,1},{3,3},{0,0},{0,0},{0,0},{0,0},{0,0}},
  25.     {{5,2},{4,4},{3,4},{3,4},{3,4},{3,3},{3,2},{3,2},{2,1},{4,1},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  26.     {{6,3},{4,3},{3,3},{4,3},{3,3},{3,2},{4,1},{3,1},{5,1},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  27.     {{6,2},{4,2},{4,2},{3,3},{4,2},{4,1},{3,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  28.     {{7,3},{5,3},{5,3},{4,2},{5,1},{3,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  29.     {{7,2},{5,2},{5,2},{5,2},{4,1},{6,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  30.     {{8,3},{6,3},{6,1},{5,1},{5,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  31.     {{8,2},{6,2},{5,1},{5,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}},
  32.     {{9,3},{6,1},{6,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}},
  33.     {{9,2},{6,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}},
  34.     {{9,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}}
  35. };
  36.  
  37. //         [run_before][zeros_left]
  38. const bitTable run_before_table[15][7]=
  39. {
  40.     {{1,1},{1,1},{2,3},{2,3},{2,3},{2,3},{3,7}},
  41.     {{1,0},{2,1},{2,2},{2,2},{2,2},{3,0},{3,4}},  
  42.     {{0,0},{2,0},{2,1},{2,1},{3,3},{3,1},{3,5}},
  43.     {{0,0},{0,0},{2,0},{3,1},{3,2},{3,3},{3,4}},
  44.     {{0,0},{0,0},{0,0},{3,0},{3,1},{3,2},{3,3}},
  45.     {{0,0},{0,0},{0,0},{0,0},{3,0},{3,5},{3,2}},
  46.     {{0,0},{0,0},{0,0},{0,0},{0,0},{3,4},{3,1}},
  47.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{4,1}},
  48.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{5,1}},
  49.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{6,1}},
  50.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{7,1}},
  51.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{8,1}},
  52.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{9,1}},
  53.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{10,1}},
  54.     {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{11,1}}
  55. };
  56.  
  57.  
  58. //coeff tokens   [totalCoeffs][trailingOnes][tableid]
  59. const bitTable coeff_token_tables[17][4][6]=
  60. {
  61.     {
  62.         {{1,1},{2,3},{4,15},{6,3},{2,1},{1,1}},
  63.         {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  64.         {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  65.         {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
  66.     },
  67.     {
  68.         {{6,5},{6,11},{6,15},{6,0},{6,7},{7,15}},
  69.         {{2,1},{2,2},{8,224},{2,1},{1,1},{2,1}},
  70.         {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
  71.         {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
  72.     },
  73.     {
  74.         {{8,7},{6,7},{6,11},{6,4},{6,4},{7,14}},
  75.         {{6,4},{5,7},{5,15},{6,5},{6,6},{7,13}},
  76.         {{3,1},{3,3},{4,13},{6,6},{3,1},{3,1}},
  77.         {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}
  78.     },
  79.     {
  80.         {{9,7},{7,7},{6,8},{6,8},{6,3},{9,7}},
  81.         {{8,6},{6,10},{5,12},{6,9},{7,3},{7,12}},
  82.         {{7,5},{6,9},{5,14},{6,10},{7,2},{7,11}},
  83.         {{5,3},{4,5},{4,12},{6,11},{6,5},{5,1}}
  84.     },
  85.     {
  86.         {{10,7},{8,7},{7,15},{6,12},{6,2},{9,6}},
  87.         {{9,6},{6,6},{5,10},{6,13},{8,3},{9,5}},
  88.         {{8,5},{6,5},{5,11},{6,14},{8,2},{7,10}},
  89.         {{6,3},{4,4},{4,11},{6,15},{7,0},{6,1}}
  90.     },
  91.     {
  92.         {{11,7},{8,4},{7,11},{6,16},{1,0},{10,7}},
  93.         {{10,6},{7,6},{5,8},{6,17},{1,0},{10,6}},
  94.         {{9,5},{7,5},{5,9},{6,18},{1,0},{9,4}},
  95.         {{7,4},{5,6},{4,10},{6,19},{1,0},{7,9}}
  96.     },
  97.     {
  98.         {{13,15},{9,7},{7,9},{6,20},{1,0},{11,7}},
  99.         {{11,6},{8,6},{6,14},{6,21},{1,0},{11,6}},
  100.         {{10,5},{8,5},{6,13},{6,22},{1,0},{10,5}},
  101.         {{8,4},{6,8},{4,9},{6,23},{1,0},{7,8}}
  102.     },
  103.     {
  104.         {{13,11},{11,15},{7,8},{6,24},{1,0},{12,7}},
  105.         {{13,14},{9,6},{6,10},{6,25},{1,0},{12,6}},
  106.         {{11,5},{9,5},{6,9},{6,26},{1,0},{11,5}},
  107.         {{9,4},{6,4},{4,8},{6,27},{1,0},{10,4}}
  108.     },
  109.     {
  110.         {{13,8},{11,11},{8,15},{6,28},{1,0},{13,7}},
  111.         {{13,10},{11,14},{7,14},{6,29},{1,0},{12,5}},
  112.         {{13,13},{11,13},{7,13},{6,30},{1,0},{12,4}},
  113.         {{10,4},{7,4},{5,13},{6,31},{1,0},{11,4}}
  114.     },
  115.     {
  116.         {{14,15},{12,15},{8,11},{6,32},{1,0},{1,0}},
  117.         {{14,14},{11,10},{8,14},{6,33},{1,0},{1,0}},
  118.         {{13,9},{11,9},{7,10},{6,34},{1,0},{1,0}},
  119.         {{11,4},{9,4},{6,12},{6,35},{1,0},{1,0}}
  120.     },
  121.     {
  122.         {{14,11},{12,11},{9,15},{6,36},{1,0},{1,0}},
  123.         {{14,10},{12,14},{8,10},{6,37},{1,0},{1,0}},
  124.         {{14,13},{12,13},{8,13},{6,38},{1,0},{1,0}},
  125.         {{13,12},{11,12},{7,12},{6,39},{1,0},{1,0}}
  126.     },
  127.     {
  128.         {{15,15},{12,8},{9,11},{6,40},{1,0},{1,0}},
  129.         {{15,14},{12,10},{9,14},{6,41},{1,0},{1,0}},
  130.         {{14,9},{12,9},{8,9},{6,42},{1,0},{1,0}},
  131.         {{14,12},{11,8},{8,12},{6,43},{1,0},{1,0}}
  132.     },
  133.     {
  134.         {{15,11},{13,15},{8,4},{1,0},{6,44},{1,0}},
  135.         {{15,10},{13,14},{8,5},{1,0},{6,45},{1,0}},
  136.         {{15,13},{13,13},{8,6},{1,1},{6,46},{1,0}},
  137.         {{14,8},{12,12},{8,8},{6,47},{1,0},{1,0}}
  138.     },
  139.     {
  140.         {{16,15},{13,11},{10,13},{6,48},{1,0},{1,0}},
  141.         {{15,1},{13,10},{9,7},{6,49},{1,0},{1,0}},
  142.         {{15,9},{13,9},{9,9},{6,50},{1,0},{1,0}},
  143.         {{15,12},{13,12},{9,12},{6,51},{1,0},{1,0}}
  144.     },
  145.     {
  146.         {{16,11},{13,7},{10,9},{6,52},{1,0},{1,0}},
  147.         {{16,14},{14,11},{10,12},{6,53},{1,0},{1,0}},
  148.         {{16,13},{13,6},{10,11},{6,54},{1,0},{1,0}},
  149.         {{15,8},{13,8},{10,10},{6,55},{1,0},{1,0}}
  150.     },
  151.     {
  152.         {{16,7},{14,9},{10,5},{6,56},{1,0},{1,0}},
  153.         {{16,10},{14,8},{10,8},{6,57},{1,0},{1,0}},
  154.         {{16,9},{14,10},{10,7},{6,58},{1,0},{1,0}},
  155.         {{16,12},{13,1},{10,6},{6,59},{1,0},{1,0}}
  156.     },
  157.     {
  158.         {{16,4},{14,7},{10,1},{6,60},{1,0},{1,0}},
  159.         {{16,6},{14,6},{10,4},{6,61},{1,0},{1,0}},
  160.         {{16,5},{14,5},{10,3},{6,62},{1,0},{1,0}},
  161.         {{16,8},{14,4},{10,2},{6,63},{1,0},{1,0}}
  162.     }
  163. };
  164.  
  165. //Zig-zag scan order for 4x4 block
  166. const uint8 zigzag_4x4[] =
  167. {
  168.     0, 1, 4, 8,
  169.     5, 2, 3, 6,
  170.     9,12,13,10,
  171.     7,11,14,15
  172. };
  173.  
  174. const uint8 coded_block_pattern_inter[] =
  175. {
  176.  0, 16, 1,2, 4, 8, 32, 3,5, 10, 12, 15, 47, 7, 11, 13, 14, 6,9, 31, 35, 37, 42, 44, 33, 34,
  177.  36, 40, 39,43,45,46, 17, 18, 20, 24, 19,21,26, 28, 23, 27, 29, 30, 22, 25, 38, 41
  178. };
  179.  
  180. const uint8 coded_block_pattern_intra[] = {
  181.  47,31,15,0,23,27,29,30,7,11,13,14, 39, 43, 45, 46, 16, 3, 5, 10, 12, 19, 21, 26, 28, 35,
  182.  37, 42, 44, 1, 2, 4, 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41
  183. };