libavcodec/h264_cabac.c
Go to the documentation of this file.
00001 /*
00002  * H.26L/H.264/AVC/JVT/14496-10/... cabac decoding
00003  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #define CABAC 1
00029 
00030 #include "config.h"
00031 #include "cabac.h"
00032 #include "cabac_functions.h"
00033 #include "internal.h"
00034 #include "dsputil.h"
00035 #include "avcodec.h"
00036 #include "h264.h"
00037 #include "h264data.h"
00038 #include "h264_mvpred.h"
00039 #include "golomb.h"
00040 
00041 #if ARCH_X86
00042 #include "x86/h264_i386.h"
00043 #endif
00044 
00045 //#undef NDEBUG
00046 #include <assert.h>
00047 
00048 /* Cabac pre state table */
00049 
00050 static const int8_t cabac_context_init_I[1024][2] =
00051 {
00052     /* 0 - 10 */
00053     { 20, -15 }, {  2, 54 },  {  3,  74 }, { 20, -15 },
00054     {  2,  54 }, {  3, 74 },  { -28,127 }, { -23, 104 },
00055     { -6,  53 }, { -1, 54 },  {  7,  51 },
00056 
00057     /* 11 - 23 unsused for I */
00058     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00059     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00060     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00061     { 0, 0 },
00062 
00063     /* 24- 39 */
00064     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00065     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00066     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00067     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00068 
00069     /* 40 - 53 */
00070     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00071     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00072     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00073     { 0, 0 },    { 0, 0 },
00074 
00075     /* 54 - 59 */
00076     { 0, 0 },    { 0, 0 },    { 0, 0 },      { 0, 0 },
00077     { 0, 0 },    { 0, 0 },
00078 
00079     /* 60 - 69 */
00080     { 0, 41 },   { 0, 63 },   { 0, 63 },     { 0, 63 },
00081     { -9, 83 },  { 4, 86 },   { 0, 97 },     { -7, 72 },
00082     { 13, 41 },  { 3, 62 },
00083 
00084     /* 70 -> 87 */
00085     { 0, 11 },   { 1, 55 },   { 0, 69 },     { -17, 127 },
00086     { -13, 102 },{ 0, 82 },   { -7, 74 },    { -21, 107 },
00087     { -27, 127 },{ -31, 127 },{ -24, 127 },  { -18, 95 },
00088     { -27, 127 },{ -21, 114 },{ -30, 127 },  { -17, 123 },
00089     { -12, 115 },{ -16, 122 },
00090 
00091     /* 88 -> 104 */
00092     { -11, 115 },{ -12, 63 }, { -2, 68 },    { -15, 84 },
00093     { -13, 104 },{ -3, 70 },  { -8, 93 },    { -10, 90 },
00094     { -30, 127 },{ -1, 74 },  { -6, 97 },    { -7, 91 },
00095     { -20, 127 },{ -4, 56 },  { -5, 82 },    { -7, 76 },
00096     { -22, 125 },
00097 
00098     /* 105 -> 135 */
00099     { -7, 93 },  { -11, 87 }, { -3, 77 },    { -5, 71 },
00100     { -4, 63 },  { -4, 68 },  { -12, 84 },   { -7, 62 },
00101     { -7, 65 },  { 8, 61 },   { 5, 56 },     { -2, 66 },
00102     { 1, 64 },   { 0, 61 },   { -2, 78 },    { 1, 50 },
00103     { 7, 52 },   { 10, 35 },  { 0, 44 },     { 11, 38 },
00104     { 1, 45 },   { 0, 46 },   { 5, 44 },     { 31, 17 },
00105     { 1, 51 },   { 7, 50 },   { 28, 19 },    { 16, 33 },
00106     { 14, 62 },  { -13, 108 },{ -15, 100 },
00107 
00108     /* 136 -> 165 */
00109     { -13, 101 },{ -13, 91 }, { -12, 94 },   { -10, 88 },
00110     { -16, 84 }, { -10, 86 }, { -7, 83 },    { -13, 87 },
00111     { -19, 94 }, { 1, 70 },   { 0, 72 },     { -5, 74 },
00112     { 18, 59 },  { -8, 102 }, { -15, 100 },  { 0, 95 },
00113     { -4, 75 },  { 2, 72 },   { -11, 75 },   { -3, 71 },
00114     { 15, 46 },  { -13, 69 }, { 0, 62 },     { 0, 65 },
00115     { 21, 37 },  { -15, 72 }, { 9, 57 },     { 16, 54 },
00116     { 0, 62 },   { 12, 72 },
00117 
00118     /* 166 -> 196 */
00119     { 24, 0 },   { 15, 9 },   { 8, 25 },     { 13, 18 },
00120     { 15, 9 },   { 13, 19 },  { 10, 37 },    { 12, 18 },
00121     { 6, 29 },   { 20, 33 },  { 15, 30 },    { 4, 45 },
00122     { 1, 58 },   { 0, 62 },   { 7, 61 },     { 12, 38 },
00123     { 11, 45 },  { 15, 39 },  { 11, 42 },    { 13, 44 },
00124     { 16, 45 },  { 12, 41 },  { 10, 49 },    { 30, 34 },
00125     { 18, 42 },  { 10, 55 },  { 17, 51 },    { 17, 46 },
00126     { 0, 89 },   { 26, -19 }, { 22, -17 },
00127 
00128     /* 197 -> 226 */
00129     { 26, -17 }, { 30, -25 }, { 28, -20 },   { 33, -23 },
00130     { 37, -27 }, { 33, -23 }, { 40, -28 },   { 38, -17 },
00131     { 33, -11 }, { 40, -15 }, { 41, -6 },    { 38, 1 },
00132     { 41, 17 },  { 30, -6 },  { 27, 3 },     { 26, 22 },
00133     { 37, -16 }, { 35, -4 },  { 38, -8 },    { 38, -3 },
00134     { 37, 3 },   { 38, 5 },   { 42, 0 },     { 35, 16 },
00135     { 39, 22 },  { 14, 48 },  { 27, 37 },    { 21, 60 },
00136     { 12, 68 },  { 2, 97 },
00137 
00138     /* 227 -> 251 */
00139     { -3, 71 },  { -6, 42 },  { -5, 50 },    { -3, 54 },
00140     { -2, 62 },  { 0, 58 },   { 1, 63 },     { -2, 72 },
00141     { -1, 74 },  { -9, 91 },  { -5, 67 },    { -5, 27 },
00142     { -3, 39 },  { -2, 44 },  { 0, 46 },     { -16, 64 },
00143     { -8, 68 },  { -10, 78 }, { -6, 77 },    { -10, 86 },
00144     { -12, 92 }, { -15, 55 }, { -10, 60 },   { -6, 62 },
00145     { -4, 65 },
00146 
00147     /* 252 -> 275 */
00148     { -12, 73 }, { -8, 76 },  { -7, 80 },    { -9, 88 },
00149     { -17, 110 },{ -11, 97 }, { -20, 84 },   { -11, 79 },
00150     { -6, 73 },  { -4, 74 },  { -13, 86 },   { -13, 96 },
00151     { -11, 97 }, { -19, 117 },{ -8, 78 },    { -5, 33 },
00152     { -4, 48 },  { -2, 53 },  { -3, 62 },    { -13, 71 },
00153     { -10, 79 }, { -12, 86 }, { -13, 90 },   { -14, 97 },
00154 
00155     /* 276 a bit special (not used, bypass is used instead) */
00156     { 0, 0 },
00157 
00158     /* 277 -> 307 */
00159     { -6, 93 },  { -6, 84 },  { -8, 79 },    { 0, 66 },
00160     { -1, 71 },  { 0, 62 },   { -2, 60 },    { -2, 59 },
00161     { -5, 75 },  { -3, 62 },  { -4, 58 },    { -9, 66 },
00162     { -1, 79 },  { 0, 71 },   { 3, 68 },     { 10, 44 },
00163     { -7, 62 },  { 15, 36 },  { 14, 40 },    { 16, 27 },
00164     { 12, 29 },  { 1, 44 },   { 20, 36 },    { 18, 32 },
00165     { 5, 42 },   { 1, 48 },   { 10, 62 },    { 17, 46 },
00166     { 9, 64 },   { -12, 104 },{ -11, 97 },
00167 
00168     /* 308 -> 337 */
00169     { -16, 96 }, { -7, 88 },  { -8, 85 },    { -7, 85 },
00170     { -9, 85 },  { -13, 88 }, { 4, 66 },     { -3, 77 },
00171     { -3, 76 },  { -6, 76 },  { 10, 58 },    { -1, 76 },
00172     { -1, 83 },  { -7, 99 },  { -14, 95 },   { 2, 95 },
00173     { 0, 76 },   { -5, 74 },  { 0, 70 },     { -11, 75 },
00174     { 1, 68 },   { 0, 65 },   { -14, 73 },   { 3, 62 },
00175     { 4, 62 },   { -1, 68 },  { -13, 75 },   { 11, 55 },
00176     { 5, 64 },   { 12, 70 },
00177 
00178     /* 338 -> 368 */
00179     { 15, 6 },   { 6, 19 },   { 7, 16 },     { 12, 14 },
00180     { 18, 13 },  { 13, 11 },  { 13, 15 },    { 15, 16 },
00181     { 12, 23 },  { 13, 23 },  { 15, 20 },    { 14, 26 },
00182     { 14, 44 },  { 17, 40 },  { 17, 47 },    { 24, 17 },
00183     { 21, 21 },  { 25, 22 },  { 31, 27 },    { 22, 29 },
00184     { 19, 35 },  { 14, 50 },  { 10, 57 },    { 7, 63 },
00185     { -2, 77 },  { -4, 82 },  { -3, 94 },    { 9, 69 },
00186     { -12, 109 },{ 36, -35 }, { 36, -34 },
00187 
00188     /* 369 -> 398 */
00189     { 32, -26 }, { 37, -30 }, { 44, -32 },   { 34, -18 },
00190     { 34, -15 }, { 40, -15 }, { 33, -7 },    { 35, -5 },
00191     { 33, 0 },   { 38, 2 },   { 33, 13 },    { 23, 35 },
00192     { 13, 58 },  { 29, -3 },  { 26, 0 },     { 22, 30 },
00193     { 31, -7 },  { 35, -15 }, { 34, -3 },    { 34, 3 },
00194     { 36, -1 },  { 34, 5 },   { 32, 11 },    { 35, 5 },
00195     { 34, 12 },  { 39, 11 },  { 30, 29 },    { 34, 26 },
00196     { 29, 39 },  { 19, 66 },
00197 
00198     /* 399 -> 435 */
00199     {  31,  21 }, {  31,  31 }, {  25,  50 },
00200     { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11,  85 },
00201     { -15,  92 }, { -14,  89 }, { -26,  71 }, { -15,  81 },
00202     { -14,  80 }, {   0,  68 }, { -14,  70 }, { -24,  56 },
00203     { -23,  68 }, { -24,  50 }, { -11,  74 }, {  23, -13 },
00204     {  26, -13 }, {  40, -15 }, {  49, -14 }, {  44,   3 },
00205     {  45,   6 }, {  44,  34 }, {  33,  54 }, {  19,  82 },
00206     {  -3,  75 }, {  -1,  23 }, {   1,  34 }, {   1,  43 },
00207     {   0,  54 }, {  -2,  55 }, {   0,  61 }, {   1,  64 },
00208     {   0,  68 }, {  -9,  92 },
00209 
00210     /* 436 -> 459 */
00211     { -14, 106 }, { -13,  97 }, { -15,  90 }, { -12,  90 },
00212     { -18,  88 }, { -10,  73 }, {  -9,  79 }, { -14,  86 },
00213     { -10,  73 }, { -10,  70 }, { -10,  69 }, {  -5,  66 },
00214     {  -9,  64 }, {  -5,  58 }, {   2,  59 }, {  21, -10 },
00215     {  24, -11 }, {  28,  -8 }, {  28,  -1 }, {  29,   3 },
00216     {  29,   9 }, {  35,  20 }, {  29,  36 }, {  14,  67 },
00217 
00218     /* 460 -> 1024 */
00219     { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 },
00220     { -12,  63 }, {  -2,  68 }, { -15,  84 }, { -13, 104 },
00221     {  -3,  70 }, {  -8,  93 }, { -10,  90 }, { -30, 127 },
00222     { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 },
00223     { -12,  63 }, {  -2,  68 }, { -15,  84 }, { -13, 104 },
00224     {  -3,  70 }, {  -8,  93 }, { -10,  90 }, { -30, 127 },
00225     {  -7,  93 }, { -11,  87 }, {  -3,  77 }, {  -5,  71 },
00226     {  -4,  63 }, {  -4,  68 }, { -12,  84 }, {  -7,  62 },
00227     {  -7,  65 }, {   8,  61 }, {   5,  56 }, {  -2,  66 },
00228     {   1,  64 }, {   0,  61 }, {  -2,  78 }, {   1,  50 },
00229     {   7,  52 }, {  10,  35 }, {   0,  44 }, {  11,  38 },
00230     {   1,  45 }, {   0,  46 }, {   5,  44 }, {  31,  17 },
00231     {   1,  51 }, {   7,  50 }, {  28,  19 }, {  16,  33 },
00232     {  14,  62 }, { -13, 108 }, { -15, 100 }, { -13, 101 },
00233     { -13,  91 }, { -12,  94 }, { -10,  88 }, { -16,  84 },
00234     { -10,  86 }, {  -7,  83 }, { -13,  87 }, { -19,  94 },
00235     {   1,  70 }, {   0,  72 }, {  -5,  74 }, {  18,  59 },
00236     {  -7,  93 }, { -11,  87 }, {  -3,  77 }, {  -5,  71 },
00237     {  -4,  63 }, {  -4,  68 }, { -12,  84 }, {  -7,  62 },
00238     {  -7,  65 }, {   8,  61 }, {   5,  56 }, {  -2,  66 },
00239     {   1,  64 }, {   0,  61 }, {  -2,  78 }, {   1,  50 },
00240     {   7,  52 }, {  10,  35 }, {   0,  44 }, {  11,  38 },
00241     {   1,  45 }, {   0,  46 }, {   5,  44 }, {  31,  17 },
00242     {   1,  51 }, {   7,  50 }, {  28,  19 }, {  16,  33 },
00243     {  14,  62 }, { -13, 108 }, { -15, 100 }, { -13, 101 },
00244     { -13,  91 }, { -12,  94 }, { -10,  88 }, { -16,  84 },
00245     { -10,  86 }, {  -7,  83 }, { -13,  87 }, { -19,  94 },
00246     {   1,  70 }, {   0,  72 }, {  -5,  74 }, {  18,  59 },
00247     {  24,   0 }, {  15,   9 }, {   8,  25 }, {  13,  18 },
00248     {  15,   9 }, {  13,  19 }, {  10,  37 }, {  12,  18 },
00249     {   6,  29 }, {  20,  33 }, {  15,  30 }, {   4,  45 },
00250     {   1,  58 }, {   0,  62 }, {   7,  61 }, {  12,  38 },
00251     {  11,  45 }, {  15,  39 }, {  11,  42 }, {  13,  44 },
00252     {  16,  45 }, {  12,  41 }, {  10,  49 }, {  30,  34 },
00253     {  18,  42 }, {  10,  55 }, {  17,  51 }, {  17,  46 },
00254     {   0,  89 }, {  26, -19 }, {  22, -17 }, {  26, -17 },
00255     {  30, -25 }, {  28, -20 }, {  33, -23 }, {  37, -27 },
00256     {  33, -23 }, {  40, -28 }, {  38, -17 }, {  33, -11 },
00257     {  40, -15 }, {  41,  -6 }, {  38,   1 }, {  41,  17 },
00258     {  24,   0 }, {  15,   9 }, {   8,  25 }, {  13,  18 },
00259     {  15,   9 }, {  13,  19 }, {  10,  37 }, {  12,  18 },
00260     {   6,  29 }, {  20,  33 }, {  15,  30 }, {   4,  45 },
00261     {   1,  58 }, {   0,  62 }, {   7,  61 }, {  12,  38 },
00262     {  11,  45 }, {  15,  39 }, {  11,  42 }, {  13,  44 },
00263     {  16,  45 }, {  12,  41 }, {  10,  49 }, {  30,  34 },
00264     {  18,  42 }, {  10,  55 }, {  17,  51 }, {  17,  46 },
00265     {   0,  89 }, {  26, -19 }, {  22, -17 }, {  26, -17 },
00266     {  30, -25 }, {  28, -20 }, {  33, -23 }, {  37, -27 },
00267     {  33, -23 }, {  40, -28 }, {  38, -17 }, {  33, -11 },
00268     {  40, -15 }, {  41,  -6 }, {  38,   1 }, {  41,  17 },
00269     { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11,  85 },
00270     { -15,  92 }, { -14,  89 }, { -26,  71 }, { -15,  81 },
00271     { -14,  80 }, {   0,  68 }, { -14,  70 }, { -24,  56 },
00272     { -23,  68 }, { -24,  50 }, { -11,  74 }, { -14, 106 },
00273     { -13,  97 }, { -15,  90 }, { -12,  90 }, { -18,  88 },
00274     { -10,  73 }, {  -9,  79 }, { -14,  86 }, { -10,  73 },
00275     { -10,  70 }, { -10,  69 }, {  -5,  66 }, {  -9,  64 },
00276     {  -5,  58 }, {   2,  59 }, {  23, -13 }, {  26, -13 },
00277     {  40, -15 }, {  49, -14 }, {  44,   3 }, {  45,   6 },
00278     {  44,  34 }, {  33,  54 }, {  19,  82 }, {  21, -10 },
00279     {  24, -11 }, {  28,  -8 }, {  28,  -1 }, {  29,   3 },
00280     {  29,   9 }, {  35,  20 }, {  29,  36 }, {  14,  67 },
00281     {  -3,  75 }, {  -1,  23 }, {   1,  34 }, {   1,  43 },
00282     {   0,  54 }, {  -2,  55 }, {   0,  61 }, {   1,  64 },
00283     {   0,  68 }, {  -9,  92 }, { -17, 120 }, { -20, 112 },
00284     { -18, 114 }, { -11,  85 }, { -15,  92 }, { -14,  89 },
00285     { -26,  71 }, { -15,  81 }, { -14,  80 }, {   0,  68 },
00286     { -14,  70 }, { -24,  56 }, { -23,  68 }, { -24,  50 },
00287     { -11,  74 }, { -14, 106 }, { -13,  97 }, { -15,  90 },
00288     { -12,  90 }, { -18,  88 }, { -10,  73 }, {  -9,  79 },
00289     { -14,  86 }, { -10,  73 }, { -10,  70 }, { -10,  69 },
00290     {  -5,  66 }, {  -9,  64 }, {  -5,  58 }, {   2,  59 },
00291     {  23, -13 }, {  26, -13 }, {  40, -15 }, {  49, -14 },
00292     {  44,   3 }, {  45,   6 }, {  44,  34 }, {  33,  54 },
00293     {  19,  82 }, {  21, -10 }, {  24, -11 }, {  28,  -8 },
00294     {  28,  -1 }, {  29,   3 }, {  29,   9 }, {  35,  20 },
00295     {  29,  36 }, {  14,  67 }, {  -3,  75 }, {  -1,  23 },
00296     {   1,  34 }, {   1,  43 }, {   0,  54 }, {  -2,  55 },
00297     {   0,  61 }, {   1,  64 }, {   0,  68 }, {  -9,  92 },
00298     {  -6,  93 }, {  -6,  84 }, {  -8,  79 }, {   0,  66 },
00299     {  -1,  71 }, {   0,  62 }, {  -2,  60 }, {  -2,  59 },
00300     {  -5,  75 }, {  -3,  62 }, {  -4,  58 }, {  -9,  66 },
00301     {  -1,  79 }, {   0,  71 }, {   3,  68 }, {  10,  44 },
00302     {  -7,  62 }, {  15,  36 }, {  14,  40 }, {  16,  27 },
00303     {  12,  29 }, {   1,  44 }, {  20,  36 }, {  18,  32 },
00304     {   5,  42 }, {   1,  48 }, {  10,  62 }, {  17,  46 },
00305     {   9,  64 }, { -12, 104 }, { -11,  97 }, { -16,  96 },
00306     {  -7,  88 }, {  -8,  85 }, {  -7,  85 }, {  -9,  85 },
00307     { -13,  88 }, {   4,  66 }, {  -3,  77 }, {  -3,  76 },
00308     {  -6,  76 }, {  10,  58 }, {  -1,  76 }, {  -1,  83 },
00309     {  -6,  93 }, {  -6,  84 }, {  -8,  79 }, {   0,  66 },
00310     {  -1,  71 }, {   0,  62 }, {  -2,  60 }, {  -2,  59 },
00311     {  -5,  75 }, {  -3,  62 }, {  -4,  58 }, {  -9,  66 },
00312     {  -1,  79 }, {   0,  71 }, {   3,  68 }, {  10,  44 },
00313     {  -7,  62 }, {  15,  36 }, {  14,  40 }, {  16,  27 },
00314     {  12,  29 }, {   1,  44 }, {  20,  36 }, {  18,  32 },
00315     {   5,  42 }, {   1,  48 }, {  10,  62 }, {  17,  46 },
00316     {   9,  64 }, { -12, 104 }, { -11,  97 }, { -16,  96 },
00317     {  -7,  88 }, {  -8,  85 }, {  -7,  85 }, {  -9,  85 },
00318     { -13,  88 }, {   4,  66 }, {  -3,  77 }, {  -3,  76 },
00319     {  -6,  76 }, {  10,  58 }, {  -1,  76 }, {  -1,  83 },
00320     {  15,   6 }, {   6,  19 }, {   7,  16 }, {  12,  14 },
00321     {  18,  13 }, {  13,  11 }, {  13,  15 }, {  15,  16 },
00322     {  12,  23 }, {  13,  23 }, {  15,  20 }, {  14,  26 },
00323     {  14,  44 }, {  17,  40 }, {  17,  47 }, {  24,  17 },
00324     {  21,  21 }, {  25,  22 }, {  31,  27 }, {  22,  29 },
00325     {  19,  35 }, {  14,  50 }, {  10,  57 }, {   7,  63 },
00326     {  -2,  77 }, {  -4,  82 }, {  -3,  94 }, {   9,  69 },
00327     { -12, 109 }, {  36, -35 }, {  36, -34 }, {  32, -26 },
00328     {  37, -30 }, {  44, -32 }, {  34, -18 }, {  34, -15 },
00329     {  40, -15 }, {  33,  -7 }, {  35,  -5 }, {  33,   0 },
00330     {  38,   2 }, {  33,  13 }, {  23,  35 }, {  13,  58 },
00331     {  15,   6 }, {   6,  19 }, {   7,  16 }, {  12,  14 },
00332     {  18,  13 }, {  13,  11 }, {  13,  15 }, {  15,  16 },
00333     {  12,  23 }, {  13,  23 }, {  15,  20 }, {  14,  26 },
00334     {  14,  44 }, {  17,  40 }, {  17,  47 }, {  24,  17 },
00335     {  21,  21 }, {  25,  22 }, {  31,  27 }, {  22,  29 },
00336     {  19,  35 }, {  14,  50 }, {  10,  57 }, {   7,  63 },
00337     {  -2,  77 }, {  -4,  82 }, {  -3,  94 }, {   9,  69 },
00338     { -12, 109 }, {  36, -35 }, {  36, -34 }, {  32, -26 },
00339     {  37, -30 }, {  44, -32 }, {  34, -18 }, {  34, -15 },
00340     {  40, -15 }, {  33,  -7 }, {  35,  -5 }, {  33,   0 },
00341     {  38,   2 }, {  33,  13 }, {  23,  35 }, {  13,  58 },
00342     {  -3,  71 }, {  -6,  42 }, {  -5,  50 }, {  -3,  54 },
00343     {  -2,  62 }, {   0,  58 }, {   1,  63 }, {  -2,  72 },
00344     {  -1,  74 }, {  -9,  91 }, {  -5,  67 }, {  -5,  27 },
00345     {  -3,  39 }, {  -2,  44 }, {   0,  46 }, { -16,  64 },
00346     {  -8,  68 }, { -10,  78 }, {  -6,  77 }, { -10,  86 },
00347     { -12,  92 }, { -15,  55 }, { -10,  60 }, {  -6,  62 },
00348     {  -4,  65 }, { -12,  73 }, {  -8,  76 }, {  -7,  80 },
00349     {  -9,  88 }, { -17, 110 }, {  -3,  71 }, {  -6,  42 },
00350     {  -5,  50 }, {  -3,  54 }, {  -2,  62 }, {   0,  58 },
00351     {   1,  63 }, {  -2,  72 }, {  -1,  74 }, {  -9,  91 },
00352     {  -5,  67 }, {  -5,  27 }, {  -3,  39 }, {  -2,  44 },
00353     {   0,  46 }, { -16,  64 }, {  -8,  68 }, { -10,  78 },
00354     {  -6,  77 }, { -10,  86 }, { -12,  92 }, { -15,  55 },
00355     { -10,  60 }, {  -6,  62 }, {  -4,  65 }, { -12,  73 },
00356     {  -8,  76 }, {  -7,  80 }, {  -9,  88 }, { -17, 110 },
00357     {  -3,  70 }, {  -8,  93 }, { -10,  90 }, { -30, 127 },
00358     {  -3,  70 }, {  -8,  93 }, { -10,  90 }, { -30, 127 },
00359     {  -3,  70 }, {  -8,  93 }, { -10,  90 }, { -30, 127 }
00360 };
00361 
00362 static const int8_t cabac_context_init_PB[3][1024][2] =
00363 {
00364     /* i_cabac_init_idc == 0 */
00365     {
00366         /* 0 - 10 */
00367         {  20, -15 }, {   2,  54 }, {   3,  74 }, {  20, -15 },
00368         {   2,  54 }, {   3,  74 }, { -28, 127 }, { -23, 104 },
00369         {  -6,  53 }, {  -1,  54 }, {   7,  51 },
00370 
00371         /* 11 - 23 */
00372         {  23,  33 }, {  23,   2 }, {  21,   0 }, {   1,   9 },
00373         {   0,  49 }, { -37, 118 }, {   5,  57 }, { -13,  78 },
00374         { -11,  65 }, {   1,  62 }, {  12,  49 }, {  -4,  73 },
00375         {  17,  50 },
00376 
00377         /* 24 - 39 */
00378         {  18,  64 }, {   9,  43 }, {  29,   0 }, {  26,  67 },
00379         {  16,  90 }, {   9, 104 }, { -46, 127 }, { -20, 104 },
00380         {   1,  67 }, { -13,  78 }, { -11,  65 }, {   1,  62 },
00381         {  -6,  86 }, { -17,  95 }, {  -6,  61 }, {   9,  45 },
00382 
00383         /* 40 - 53 */
00384         {  -3,  69 }, {  -6,  81 }, { -11,  96 }, {   6,  55 },
00385         {   7,  67 }, {  -5,  86 }, {   2,  88 }, {   0,  58 },
00386         {  -3,  76 }, { -10,  94 }, {   5,  54 }, {   4,  69 },
00387         {  -3,  81 }, {   0,  88 },
00388 
00389         /* 54 - 59 */
00390         {  -7,  67 }, {  -5,  74 }, {  -4,  74 }, {  -5,  80 },
00391         {  -7,  72 }, {   1,  58 },
00392 
00393         /* 60 - 69 */
00394         {   0,  41 }, {   0,  63 }, {   0,  63 }, { 0, 63 },
00395         {  -9,  83 }, {   4,  86 }, {   0,  97 }, { -7, 72 },
00396         {  13,  41 }, {   3,  62 },
00397 
00398         /* 70 - 87 */
00399         {   0,  45 }, {  -4,  78 }, {  -3,  96 }, { -27,  126 },
00400         { -28,  98 }, { -25, 101 }, { -23,  67 }, { -28,  82 },
00401         { -20,  94 }, { -16,  83 }, { -22, 110 }, { -21,  91 },
00402         { -18, 102 }, { -13,  93 }, { -29, 127 }, {  -7,  92 },
00403         {  -5,  89 }, {  -7,  96 }, { -13, 108 }, {  -3,  46 },
00404         {  -1,  65 }, {  -1,  57 }, {  -9,  93 }, {  -3,  74 },
00405         {  -9,  92 }, {  -8,  87 }, { -23, 126 }, {   5,  54 },
00406         {   6,  60 }, {   6,  59 }, {   6,  69 }, {  -1,  48 },
00407         {   0,  68 }, {  -4,  69 }, {  -8,  88 },
00408 
00409         /* 105 -> 165 */
00410         {  -2,  85 }, {  -6,  78 }, {  -1,  75 }, {  -7,  77 },
00411         {   2,  54 }, {   5,  50 }, {  -3,  68 }, {   1,  50 },
00412         {   6,  42 }, {  -4,  81 }, {   1,  63 }, {  -4,  70 },
00413         {   0,  67 }, {   2,  57 }, {  -2,  76 }, {  11,  35 },
00414         {   4,  64 }, {   1,  61 }, {  11,  35 }, {  18,  25 },
00415         {  12,  24 }, {  13,  29 }, {  13,  36 }, { -10,  93 },
00416         {  -7,  73 }, {  -2,  73 }, {  13,  46 }, {   9,  49 },
00417         {  -7, 100 }, {   9,  53 }, {   2,  53 }, {   5,  53 },
00418         {  -2,  61 }, {   0,  56 }, {   0,  56 }, { -13,  63 },
00419         {  -5,  60 }, {  -1,  62 }, {   4,  57 }, {  -6,  69 },
00420         {   4,  57 }, {  14,  39 }, {   4,  51 }, {  13,  68 },
00421         {   3,  64 }, {   1,  61 }, {   9,  63 }, {   7,  50 },
00422         {  16,  39 }, {   5,  44 }, {   4,  52 }, {  11,  48 },
00423         {  -5,  60 }, {  -1,  59 }, {   0,  59 }, {  22,  33 },
00424         {   5,  44 }, {  14,  43 }, {  -1,  78 }, {   0,  60 },
00425         {   9,  69 },
00426 
00427         /* 166 - 226 */
00428         {  11,  28 }, {   2,  40 }, {   3,  44 }, {   0,  49 },
00429         {   0,  46 }, {   2,  44 }, {   2,  51 }, {   0,  47 },
00430         {   4,  39 }, {   2,  62 }, {   6,  46 }, {   0,  54 },
00431         {   3,  54 }, {   2,  58 }, {   4,  63 }, {   6,  51 },
00432         {   6,  57 }, {   7,  53 }, {   6,  52 }, {   6,  55 },
00433         {  11,  45 }, {  14,  36 }, {   8,  53 }, {  -1,  82 },
00434         {   7,  55 }, {  -3,  78 }, {  15,  46 }, {  22,  31 },
00435         {  -1,  84 }, {  25,   7 }, {  30,  -7 }, {  28,   3 },
00436         {  28,   4 }, {  32,   0 }, {  34,  -1 }, {  30,   6 },
00437         {  30,   6 }, {  32,   9 }, {  31,  19 }, {  26,  27 },
00438         {  26,  30 }, {  37,  20 }, {  28,  34 }, {  17,  70 },
00439         {   1,  67 }, {   5,  59 }, {   9,  67 }, {  16,  30 },
00440         {  18,  32 }, {  18,  35 }, {  22,  29 }, {  24,  31 },
00441         {  23,  38 }, {  18,  43 }, {  20,  41 }, {  11,  63 },
00442         {   9,  59 }, {   9,  64 }, {  -1,  94 }, {  -2,  89 },
00443         {  -9, 108 },
00444 
00445         /* 227 - 275 */
00446         {  -6,  76 }, {  -2,  44 }, {   0,  45 }, {   0,  52 },
00447         {  -3,  64 }, {  -2,  59 }, {  -4,  70 }, {  -4,  75 },
00448         {  -8,  82 }, { -17, 102 }, {  -9,  77 }, {   3,  24 },
00449         {   0,  42 }, {   0,  48 }, {   0,  55 }, {  -6,  59 },
00450         {  -7,  71 }, { -12,  83 }, { -11,  87 }, { -30, 119 },
00451         {   1,  58 }, {  -3,  29 }, {  -1,  36 }, {   1,  38 },
00452         {   2,  43 }, {  -6,  55 }, {   0,  58 }, {   0,  64 },
00453         {  -3,  74 }, { -10,  90 }, {   0,  70 }, {  -4,  29 },
00454         {   5,  31 }, {   7,  42 }, {   1,  59 }, {  -2,  58 },
00455         {  -3,  72 }, {  -3,  81 }, { -11,  97 }, {   0,  58 },
00456         {   8,   5 }, {  10,  14 }, {  14,  18 }, {  13,  27 },
00457         {   2,  40 }, {   0,  58 }, {  -3,  70 }, {  -6,  79 },
00458         {  -8,  85 },
00459 
00460         /* 276 a bit special (not used, bypass is used instead) */
00461         { 0, 0 },
00462 
00463         /* 277 - 337 */
00464         { -13, 106 }, { -16, 106 }, { -10,  87 }, { -21, 114 },
00465         { -18, 110 }, { -14,  98 }, { -22, 110 }, { -21, 106 },
00466         { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
00467         { -10,  96 }, { -12,  95 }, {  -5,  91 }, {  -9,  93 },
00468         { -22,  94 }, {  -5,  86 }, {   9,  67 }, {  -4,  80 },
00469         { -10,  85 }, {  -1,  70 }, {   7,  60 }, {   9,  58 },
00470         {   5,  61 }, {  12,  50 }, {  15,  50 }, {  18,  49 },
00471         {  17,  54 }, {  10,  41 }, {   7,  46 }, {  -1,  51 },
00472         {   7,  49 }, {   8,  52 }, {   9,  41 }, {   6,  47 },
00473         {   2,  55 }, {  13,  41 }, {  10,  44 }, {   6,  50 },
00474         {   5,  53 }, {  13,  49 }, {   4,  63 }, {   6,  64 },
00475         {  -2,  69 }, {  -2,  59 }, {   6,  70 }, {  10,  44 },
00476         {   9,  31 }, {  12,  43 }, {   3,  53 }, {  14,  34 },
00477         {  10,  38 }, {  -3,  52 }, {  13,  40 }, {  17,  32 },
00478         {   7,  44 }, {   7,  38 }, {  13,  50 }, {  10,  57 },
00479         {  26,  43 },
00480 
00481         /* 338 - 398 */
00482         {  14,  11 }, {  11,  14 }, {   9,  11 }, {  18,  11 },
00483         {  21,   9 }, {  23,  -2 }, {  32, -15 }, {  32, -15 },
00484         {  34, -21 }, {  39, -23 }, {  42, -33 }, {  41, -31 },
00485         {  46, -28 }, {  38, -12 }, {  21,  29 }, {  45, -24 },
00486         {  53, -45 }, {  48, -26 }, {  65, -43 }, {  43, -19 },
00487         {  39, -10 }, {  30,   9 }, {  18,  26 }, {  20,  27 },
00488         {   0,  57 }, { -14,  82 }, {  -5,  75 }, { -19,  97 },
00489         { -35, 125 }, {  27,   0 }, {  28,   0 }, {  31,  -4 },
00490         {  27,   6 }, {  34,   8 }, {  30,  10 }, {  24,  22 },
00491         {  33,  19 }, {  22,  32 }, {  26,  31 }, {  21,  41 },
00492         {  26,  44 }, {  23,  47 }, {  16,  65 }, {  14,  71 },
00493         {   8,  60 }, {   6,  63 }, {  17,  65 }, {  21,  24 },
00494         {  23,  20 }, {  26,  23 }, {  27,  32 }, {  28,  23 },
00495         {  28,  24 }, {  23,  40 }, {  24,  32 }, {  28,  29 },
00496         {  23,  42 }, {  19,  57 }, {  22,  53 }, {  22,  61 },
00497         {  11,  86 },
00498 
00499         /* 399 - 435 */
00500         {  12,  40 }, {  11,  51 }, {  14,  59 },
00501         {  -4,  79 }, {  -7,  71 }, {  -5,  69 }, {  -9,  70 },
00502         {  -8,  66 }, { -10,  68 }, { -19,  73 }, { -12,  69 },
00503         { -16,  70 }, { -15,  67 }, { -20,  62 }, { -19,  70 },
00504         { -16,  66 }, { -22,  65 }, { -20,  63 }, {   9,  -2 },
00505         {  26,  -9 }, {  33,  -9 }, {  39,  -7 }, {  41,  -2 },
00506         {  45,   3 }, {  49,   9 }, {  45,  27 }, {  36,  59 },
00507         {  -6,  66 }, {  -7,  35 }, {  -7,  42 }, {  -8,  45 },
00508         {  -5,  48 }, { -12,  56 }, {  -6,  60 }, {  -5,  62 },
00509         {  -8,  66 }, {  -8,  76 },
00510 
00511         /* 436 - 459 */
00512         {  -5,  85 }, {  -6,  81 }, { -10,  77 }, {  -7,  81 },
00513         { -17,  80 }, { -18,  73 }, {  -4,  74 }, { -10,  83 },
00514         {  -9,  71 }, {  -9,  67 }, {  -1,  61 }, {  -8,  66 },
00515         { -14,  66 }, {   0,  59 }, {   2,  59 }, {  21, -13 },
00516         {  33, -14 }, {  39,  -7 }, {  46,  -2 }, {  51,   2 },
00517         {  60,   6 }, {  61,  17 }, {  55,  34 }, {  42,  62 },
00518 
00519         /* 460 - 1024 */
00520         {  -7,  92 }, {  -5,  89 }, {  -7,  96 }, { -13, 108 },
00521         {  -3,  46 }, {  -1,  65 }, {  -1,  57 }, {  -9,  93 },
00522         {  -3,  74 }, {  -9,  92 }, {  -8,  87 }, { -23, 126 },
00523         {  -7,  92 }, {  -5,  89 }, {  -7,  96 }, { -13, 108 },
00524         {  -3,  46 }, {  -1,  65 }, {  -1,  57 }, {  -9,  93 },
00525         {  -3,  74 }, {  -9,  92 }, {  -8,  87 }, { -23, 126 },
00526         {  -2,  85 }, {  -6,  78 }, {  -1,  75 }, {  -7,  77 },
00527         {   2,  54 }, {   5,  50 }, {  -3,  68 }, {   1,  50 },
00528         {   6,  42 }, {  -4,  81 }, {   1,  63 }, {  -4,  70 },
00529         {   0,  67 }, {   2,  57 }, {  -2,  76 }, {  11,  35 },
00530         {   4,  64 }, {   1,  61 }, {  11,  35 }, {  18,  25 },
00531         {  12,  24 }, {  13,  29 }, {  13,  36 }, { -10,  93 },
00532         {  -7,  73 }, {  -2,  73 }, {  13,  46 }, {   9,  49 },
00533         {  -7, 100 }, {   9,  53 }, {   2,  53 }, {   5,  53 },
00534         {  -2,  61 }, {   0,  56 }, {   0,  56 }, { -13,  63 },
00535         {  -5,  60 }, {  -1,  62 }, {   4,  57 }, {  -6,  69 },
00536         {   4,  57 }, {  14,  39 }, {   4,  51 }, {  13,  68 },
00537         {  -2,  85 }, {  -6,  78 }, {  -1,  75 }, {  -7,  77 },
00538         {   2,  54 }, {   5,  50 }, {  -3,  68 }, {   1,  50 },
00539         {   6,  42 }, {  -4,  81 }, {   1,  63 }, {  -4,  70 },
00540         {   0,  67 }, {   2,  57 }, {  -2,  76 }, {  11,  35 },
00541         {   4,  64 }, {   1,  61 }, {  11,  35 }, {  18,  25 },
00542         {  12,  24 }, {  13,  29 }, {  13,  36 }, { -10,  93 },
00543         {  -7,  73 }, {  -2,  73 }, {  13,  46 }, {   9,  49 },
00544         {  -7, 100 }, {   9,  53 }, {   2,  53 }, {   5,  53 },
00545         {  -2,  61 }, {   0,  56 }, {   0,  56 }, { -13,  63 },
00546         {  -5,  60 }, {  -1,  62 }, {   4,  57 }, {  -6,  69 },
00547         {   4,  57 }, {  14,  39 }, {   4,  51 }, {  13,  68 },
00548         {  11,  28 }, {   2,  40 }, {   3,  44 }, {   0,  49 },
00549         {   0,  46 }, {   2,  44 }, {   2,  51 }, {   0,  47 },
00550         {   4,  39 }, {   2,  62 }, {   6,  46 }, {   0,  54 },
00551         {   3,  54 }, {   2,  58 }, {   4,  63 }, {   6,  51 },
00552         {   6,  57 }, {   7,  53 }, {   6,  52 }, {   6,  55 },
00553         {  11,  45 }, {  14,  36 }, {   8,  53 }, {  -1,  82 },
00554         {   7,  55 }, {  -3,  78 }, {  15,  46 }, {  22,  31 },
00555         {  -1,  84 }, {  25,   7 }, {  30,  -7 }, {  28,   3 },
00556         {  28,   4 }, {  32,   0 }, {  34,  -1 }, {  30,   6 },
00557         {  30,   6 }, {  32,   9 }, {  31,  19 }, {  26,  27 },
00558         {  26,  30 }, {  37,  20 }, {  28,  34 }, {  17,  70 },
00559         {  11,  28 }, {   2,  40 }, {   3,  44 }, {   0,  49 },
00560         {   0,  46 }, {   2,  44 }, {   2,  51 }, {   0,  47 },
00561         {   4,  39 }, {   2,  62 }, {   6,  46 }, {   0,  54 },
00562         {   3,  54 }, {   2,  58 }, {   4,  63 }, {   6,  51 },
00563         {   6,  57 }, {   7,  53 }, {   6,  52 }, {   6,  55 },
00564         {  11,  45 }, {  14,  36 }, {   8,  53 }, {  -1,  82 },
00565         {   7,  55 }, {  -3,  78 }, {  15,  46 }, {  22,  31 },
00566         {  -1,  84 }, {  25,   7 }, {  30,  -7 }, {  28,   3 },
00567         {  28,   4 }, {  32,   0 }, {  34,  -1 }, {  30,   6 },
00568         {  30,   6 }, {  32,   9 }, {  31,  19 }, {  26,  27 },
00569         {  26,  30 }, {  37,  20 }, {  28,  34 }, {  17,  70 },
00570         {  -4,  79 }, {  -7,  71 }, {  -5,  69 }, {  -9,  70 },
00571         {  -8,  66 }, { -10,  68 }, { -19,  73 }, { -12,  69 },
00572         { -16,  70 }, { -15,  67 }, { -20,  62 }, { -19,  70 },
00573         { -16,  66 }, { -22,  65 }, { -20,  63 }, {  -5,  85 },
00574         {  -6,  81 }, { -10,  77 }, {  -7,  81 }, { -17,  80 },
00575         { -18,  73 }, {  -4,  74 }, { -10,  83 }, {  -9,  71 },
00576         {  -9,  67 }, {  -1,  61 }, {  -8,  66 }, { -14,  66 },
00577         {   0,  59 }, {   2,  59 }, {   9,  -2 }, {  26,  -9 },
00578         {  33,  -9 }, {  39,  -7 }, {  41,  -2 }, {  45,   3 },
00579         {  49,   9 }, {  45,  27 }, {  36,  59 }, {  21, -13 },
00580         {  33, -14 }, {  39,  -7 }, {  46,  -2 }, {  51,   2 },
00581         {  60,   6 }, {  61,  17 }, {  55,  34 }, {  42,  62 },
00582         {  -6,  66 }, {  -7,  35 }, {  -7,  42 }, {  -8,  45 },
00583         {  -5,  48 }, { -12,  56 }, {  -6,  60 }, {  -5,  62 },
00584         {  -8,  66 }, {  -8,  76 }, {  -4,  79 }, {  -7,  71 },
00585         {  -5,  69 }, {  -9,  70 }, {  -8,  66 }, { -10,  68 },
00586         { -19,  73 }, { -12,  69 }, { -16,  70 }, { -15,  67 },
00587         { -20,  62 }, { -19,  70 }, { -16,  66 }, { -22,  65 },
00588         { -20,  63 }, {  -5,  85 }, {  -6,  81 }, { -10,  77 },
00589         {  -7,  81 }, { -17,  80 }, { -18,  73 }, {  -4,  74 },
00590         { -10,  83 }, {  -9,  71 }, {  -9,  67 }, {  -1,  61 },
00591         {  -8,  66 }, { -14,  66 }, {   0,  59 }, {   2,  59 },
00592         {   9,  -2 }, {  26,  -9 }, {  33,  -9 }, {  39,  -7 },
00593         {  41,  -2 }, {  45,   3 }, {  49,   9 }, {  45,  27 },
00594         {  36,  59 }, {  21, -13 }, {  33, -14 }, {  39,  -7 },
00595         {  46,  -2 }, {  51,   2 }, {  60,   6 }, {  61,  17 },
00596         {  55,  34 }, {  42,  62 }, {  -6,  66 }, {  -7,  35 },
00597         {  -7,  42 }, {  -8,  45 }, {  -5,  48 }, { -12,  56 },
00598         {  -6,  60 }, {  -5,  62 }, {  -8,  66 }, {  -8,  76 },
00599         { -13, 106 }, { -16, 106 }, { -10,  87 }, { -21, 114 },
00600         { -18, 110 }, { -14,  98 }, { -22, 110 }, { -21, 106 },
00601         { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
00602         { -10,  96 }, { -12,  95 }, {  -5,  91 }, {  -9,  93 },
00603         { -22,  94 }, {  -5,  86 }, {   9,  67 }, {  -4,  80 },
00604         { -10,  85 }, {  -1,  70 }, {   7,  60 }, {   9,  58 },
00605         {   5,  61 }, {  12,  50 }, {  15,  50 }, {  18,  49 },
00606         {  17,  54 }, {  10,  41 }, {   7,  46 }, {  -1,  51 },
00607         {   7,  49 }, {   8,  52 }, {   9,  41 }, {   6,  47 },
00608         {   2,  55 }, {  13,  41 }, {  10,  44 }, {   6,  50 },
00609         {   5,  53 }, {  13,  49 }, {   4,  63 }, {   6,  64 },
00610         { -13, 106 }, { -16, 106 }, { -10,  87 }, { -21, 114 },
00611         { -18, 110 }, { -14,  98 }, { -22, 110 }, { -21, 106 },
00612         { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
00613         { -10,  96 }, { -12,  95 }, {  -5,  91 }, {  -9,  93 },
00614         { -22,  94 }, {  -5,  86 }, {   9,  67 }, {  -4,  80 },
00615         { -10,  85 }, {  -1,  70 }, {   7,  60 }, {   9,  58 },
00616         {   5,  61 }, {  12,  50 }, {  15,  50 }, {  18,  49 },
00617         {  17,  54 }, {  10,  41 }, {   7,  46 }, {  -1,  51 },
00618         {   7,  49 }, {   8,  52 }, {   9,  41 }, {   6,  47 },
00619         {   2,  55 }, {  13,  41 }, {  10,  44 }, {   6,  50 },
00620         {   5,  53 }, {  13,  49 }, {   4,  63 }, {   6,  64 },
00621         {  14,  11 }, {  11,  14 }, {   9,  11 }, {  18,  11 },
00622         {  21,   9 }, {  23,  -2 }, {  32, -15 }, {  32, -15 },
00623         {  34, -21 }, {  39, -23 }, {  42, -33 }, {  41, -31 },
00624         {  46, -28 }, {  38, -12 }, {  21,  29 }, {  45, -24 },
00625         {  53, -45 }, {  48, -26 }, {  65, -43 }, {  43, -19 },
00626         {  39, -10 }, {  30,   9 }, {  18,  26 }, {  20,  27 },
00627         {   0,  57 }, { -14,  82 }, {  -5,  75 }, { -19,  97 },
00628         { -35, 125 }, {  27,   0 }, {  28,   0 }, {  31,  -4 },
00629         {  27,   6 }, {  34,   8 }, {  30,  10 }, {  24,  22 },
00630         {  33,  19 }, {  22,  32 }, {  26,  31 }, {  21,  41 },
00631         {  26,  44 }, {  23,  47 }, {  16,  65 }, {  14,  71 },
00632         {  14,  11 }, {  11,  14 }, {   9,  11 }, {  18,  11 },
00633         {  21,   9 }, {  23,  -2 }, {  32, -15 }, {  32, -15 },
00634         {  34, -21 }, {  39, -23 }, {  42, -33 }, {  41, -31 },
00635         {  46, -28 }, {  38, -12 }, {  21,  29 }, {  45, -24 },
00636         {  53, -45 }, {  48, -26 }, {  65, -43 }, {  43, -19 },
00637         {  39, -10 }, {  30,   9 }, {  18,  26 }, {  20,  27 },
00638         {   0,  57 }, { -14,  82 }, {  -5,  75 }, { -19,  97 },
00639         { -35, 125 }, {  27,   0 }, {  28,   0 }, {  31,  -4 },
00640         {  27,   6 }, {  34,   8 }, {  30,  10 }, {  24,  22 },
00641         {  33,  19 }, {  22,  32 }, {  26,  31 }, {  21,  41 },
00642         {  26,  44 }, {  23,  47 }, {  16,  65 }, {  14,  71 },
00643         {  -6,  76 }, {  -2,  44 }, {   0,  45 }, {   0,  52 },
00644         {  -3,  64 }, {  -2,  59 }, {  -4,  70 }, {  -4,  75 },
00645         {  -8,  82 }, { -17, 102 }, {  -9,  77 }, {   3,  24 },
00646         {   0,  42 }, {   0,  48 }, {   0,  55 }, {  -6,  59 },
00647         {  -7,  71 }, { -12,  83 }, { -11,  87 }, { -30, 119 },
00648         {   1,  58 }, {  -3,  29 }, {  -1,  36 }, {   1,  38 },
00649         {   2,  43 }, {  -6,  55 }, {   0,  58 }, {   0,  64 },
00650         {  -3,  74 }, { -10,  90 }, {  -6,  76 }, {  -2,  44 },
00651         {   0,  45 }, {   0,  52 }, {  -3,  64 }, {  -2,  59 },
00652         {  -4,  70 }, {  -4,  75 }, {  -8,  82 }, { -17, 102 },
00653         {  -9,  77 }, {   3,  24 }, {   0,  42 }, {   0,  48 },
00654         {   0,  55 }, {  -6,  59 }, {  -7,  71 }, { -12,  83 },
00655         { -11,  87 }, { -30, 119 }, {   1,  58 }, {  -3,  29 },
00656         {  -1,  36 }, {   1,  38 }, {   2,  43 }, {  -6,  55 },
00657         {   0,  58 }, {   0,  64 }, {  -3,  74 }, { -10,  90 },
00658         {  -3,  74 }, {  -9,  92 }, {  -8,  87 }, { -23, 126 },
00659         {  -3,  74 }, {  -9,  92 }, {  -8,  87 }, { -23, 126 },
00660         {  -3,  74 }, {  -9,  92 }, {  -8,  87 }, { -23, 126 }
00661     },
00662 
00663     /* i_cabac_init_idc == 1 */
00664     {
00665         /* 0 - 10 */
00666         {  20, -15 }, {   2,  54 }, {   3,  74 }, {  20, -15 },
00667         {   2,  54 }, {   3,  74 }, { -28, 127 }, { -23, 104 },
00668         {  -6,  53 }, {  -1,  54 }, {   7,  51 },
00669 
00670         /* 11 - 23 */
00671         {  22,  25 }, {  34,   0 }, {  16,   0 }, {  -2,   9 },
00672         {   4,  41 }, { -29, 118 }, {   2,  65 }, {  -6,  71 },
00673         { -13,  79 }, {   5,  52 }, {   9,  50 }, {  -3,  70 },
00674         {  10,  54 },
00675 
00676         /* 24 - 39 */
00677         {  26,  34 }, {  19,  22 }, {  40,   0 }, {  57,   2 },
00678         {  41,  36 }, {  26,  69 }, { -45, 127 }, { -15, 101 },
00679         {  -4,  76 }, {  -6,  71 }, { -13,  79 }, {   5,  52 },
00680         {   6,  69 }, { -13,  90 }, {   0,  52 }, {   8,  43 },
00681 
00682         /* 40 - 53 */
00683         {  -2,  69 },{  -5,  82 },{ -10,  96 },{   2,  59 },
00684         {   2,  75 },{  -3,  87 },{  -3,  100 },{   1,  56 },
00685         {  -3,  74 },{  -6,  85 },{   0,  59 },{  -3,  81 },
00686         {  -7,  86 },{  -5,  95 },
00687 
00688         /* 54 - 59 */
00689         {  -1,  66 },{  -1,  77 },{   1,  70 },{  -2,  86 },
00690         {  -5,  72 },{   0,  61 },
00691 
00692         /* 60 - 69 */
00693         { 0, 41 },   { 0, 63 },   { 0, 63 },     { 0, 63 },
00694         { -9, 83 },  { 4, 86 },   { 0, 97 },     { -7, 72 },
00695         { 13, 41 },  { 3, 62 },
00696 
00697         /* 70 - 104 */
00698         {  13,  15 }, {   7,  51 }, {   2,  80 }, { -39, 127 },
00699         { -18,  91 }, { -17,  96 }, { -26,  81 }, { -35,  98 },
00700         { -24, 102 }, { -23,  97 }, { -27, 119 }, { -24,  99 },
00701         { -21, 110 }, { -18, 102 }, { -36, 127 }, {   0,  80 },
00702         {  -5,  89 }, {  -7,  94 }, {  -4,  92 }, {   0,  39 },
00703         {   0,  65 }, { -15,  84 }, { -35, 127 }, {  -2,  73 },
00704         { -12, 104 }, {  -9,  91 }, { -31, 127 }, {   3,  55 },
00705         {   7,  56 }, {   7,  55 }, {   8,  61 }, {  -3,  53 },
00706         {   0,  68 }, {  -7,  74 }, {  -9,  88 },
00707 
00708         /* 105 -> 165 */
00709         { -13, 103 }, { -13,  91 }, {  -9,  89 }, { -14,  92 },
00710         {  -8,  76 }, { -12,  87 }, { -23, 110 }, { -24, 105 },
00711         { -10,  78 }, { -20, 112 }, { -17,  99 }, { -78, 127 },
00712         { -70, 127 }, { -50, 127 }, { -46, 127 }, {  -4,  66 },
00713         {  -5,  78 }, {  -4,  71 }, {  -8,  72 }, {   2,  59 },
00714         {  -1,  55 }, {  -7,  70 }, {  -6,  75 }, {  -8,  89 },
00715         { -34, 119 }, {  -3,  75 }, {  32,  20 }, {  30,  22 },
00716         { -44, 127 }, {   0,  54 }, {  -5,  61 }, {   0,  58 },
00717         {  -1,  60 }, {  -3,  61 }, {  -8,  67 }, { -25,  84 },
00718         { -14,  74 }, {  -5,  65 }, {   5,  52 }, {   2,  57 },
00719         {   0,  61 }, {  -9,  69 }, { -11,  70 }, {  18,  55 },
00720         {  -4,  71 }, {   0,  58 }, {   7,  61 }, {   9,  41 },
00721         {  18,  25 }, {   9,  32 }, {   5,  43 }, {   9,  47 },
00722         {   0,  44 }, {   0,  51 }, {   2,  46 }, {  19,  38 },
00723         {  -4,  66 }, {  15,  38 }, {  12,  42 }, {   9,  34 },
00724         {   0,  89 },
00725 
00726         /* 166 - 226 */
00727         {   4,  45 }, {  10,  28 }, {  10,  31 }, {  33, -11 },
00728         {  52, -43 }, {  18,  15 }, {  28,   0 }, {  35, -22 },
00729         {  38, -25 }, {  34,   0 }, {  39, -18 }, {  32, -12 },
00730         { 102, -94 }, {   0,   0 }, {  56, -15 }, {  33,  -4 },
00731         {  29,  10 }, {  37,  -5 }, {  51, -29 }, {  39,  -9 },
00732         {  52, -34 }, {  69, -58 }, {  67, -63 }, {  44,  -5 },
00733         {  32,   7 }, {  55, -29 }, {  32,   1 }, {   0,   0 },
00734         {  27,  36 }, {  33, -25 }, {  34, -30 }, {  36, -28 },
00735         {  38, -28 }, {  38, -27 }, {  34, -18 }, {  35, -16 },
00736         {  34, -14 }, {  32,  -8 }, {  37,  -6 }, {  35,   0 },
00737         {  30,  10 }, {  28,  18 }, {  26,  25 }, {  29,  41 },
00738         {   0,  75 }, {   2,  72 }, {   8,  77 }, {  14,  35 },
00739         {  18,  31 }, {  17,  35 }, {  21,  30 }, {  17,  45 },
00740         {  20,  42 }, {  18,  45 }, {  27,  26 }, {  16,  54 },
00741         {   7,  66 }, {  16,  56 }, {  11,  73 }, {  10,  67 },
00742         { -10, 116 },
00743 
00744         /* 227 - 275 */
00745         { -23, 112 }, { -15,  71 }, {  -7,  61 }, {   0,  53 },
00746         {  -5,  66 }, { -11,  77 }, {  -9,  80 }, {  -9,  84 },
00747         { -10,  87 }, { -34, 127 }, { -21, 101 }, {  -3,  39 },
00748         {  -5,  53 }, {  -7,  61 }, { -11,  75 }, { -15,  77 },
00749         { -17,  91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
00750         { -11,  76 }, { -10,  44 }, { -10,  52 }, { -10,  57 },
00751         {  -9,  58 }, { -16,  72 }, {  -7,  69 }, {  -4,  69 },
00752         {  -5,  74 }, {  -9,  86 }, {   2,  66 }, {  -9,  34 },
00753         {   1,  32 }, {  11,  31 }, {   5,  52 }, {  -2,  55 },
00754         {  -2,  67 }, {   0,  73 }, {  -8,  89 }, {   3,  52 },
00755         {   7,   4 }, {  10,   8 }, {  17,   8 }, {  16,  19 },
00756         {   3,  37 }, {  -1,  61 }, {  -5,  73 }, {  -1,  70 },
00757         {  -4,  78 },
00758 
00759         /* 276 a bit special (not used, bypass is used instead) */
00760         { 0, 0 },
00761 
00762         /* 277 - 337 */
00763         { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
00764         { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
00765         { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
00766         { -10,  95 }, { -14, 100 }, {  -8,  95 }, { -17, 111 },
00767         { -28, 114 }, {  -6,  89 }, {  -2,  80 }, {  -4,  82 },
00768         {  -9,  85 }, {  -8,  81 }, {  -1,  72 }, {   5,  64 },
00769         {   1,  67 }, {   9,  56 }, {   0,  69 }, {   1,  69 },
00770         {   7,  69 }, {  -7,  69 }, {  -6,  67 }, { -16,  77 },
00771         {  -2,  64 }, {   2,  61 }, {  -6,  67 }, {  -3,  64 },
00772         {   2,  57 }, {  -3,  65 }, {  -3,  66 }, {   0,  62 },
00773         {   9,  51 }, {  -1,  66 }, {  -2,  71 }, {  -2,  75 },
00774         {  -1,  70 }, {  -9,  72 }, {  14,  60 }, {  16,  37 },
00775         {   0,  47 }, {  18,  35 }, {  11,  37 }, {  12,  41 },
00776         {  10,  41 }, {   2,  48 }, {  12,  41 }, {  13,  41 },
00777         {   0,  59 }, {   3,  50 }, {  19,  40 }, {   3,  66 },
00778         {  18,  50 },
00779 
00780         /* 338 - 398 */
00781         {  19,  -6 }, {  18,  -6 }, {  14,   0 }, {  26, -12 },
00782         {  31, -16 }, {  33, -25 }, {  33, -22 }, {  37, -28 },
00783         {  39, -30 }, {  42, -30 }, {  47, -42 }, {  45, -36 },
00784         {  49, -34 }, {  41, -17 }, {  32,   9 }, {  69, -71 },
00785         {  63, -63 }, {  66, -64 }, {  77, -74 }, {  54, -39 },
00786         {  52, -35 }, {  41, -10 }, {  36,   0 }, {  40,  -1 },
00787         {  30,  14 }, {  28,  26 }, {  23,  37 }, {  12,  55 },
00788         {  11,  65 }, {  37, -33 }, {  39, -36 }, {  40, -37 },
00789         {  38, -30 }, {  46, -33 }, {  42, -30 }, {  40, -24 },
00790         {  49, -29 }, {  38, -12 }, {  40, -10 }, {  38,  -3 },
00791         {  46,  -5 }, {  31,  20 }, {  29,  30 }, {  25,  44 },
00792         {  12,  48 }, {  11,  49 }, {  26,  45 }, {  22,  22 },
00793         {  23,  22 }, {  27,  21 }, {  33,  20 }, {  26,  28 },
00794         {  30,  24 }, {  27,  34 }, {  18,  42 }, {  25,  39 },
00795         {  18,  50 }, {  12,  70 }, {  21,  54 }, {  14,  71 },
00796         {  11,  83 },
00797 
00798         /* 399 - 435 */
00799         {  25,  32 }, {  21,  49 }, {  21,  54 },
00800         {  -5,  85 }, {  -6,  81 }, { -10,  77 }, {  -7,  81 },
00801         { -17,  80 }, { -18,  73 }, {  -4,  74 }, { -10,  83 },
00802         {  -9,  71 }, {  -9,  67 }, {  -1,  61 }, {  -8,  66 },
00803         { -14,  66 }, {   0,  59 }, {   2,  59 }, {  17, -10 },
00804         {  32, -13 }, {  42,  -9 }, {  49,  -5 }, {  53,   0 },
00805         {  64,   3 }, {  68,  10 }, {  66,  27 }, {  47,  57 },
00806         {  -5,  71 }, {   0,  24 }, {  -1,  36 }, {  -2,  42 },
00807         {  -2,  52 }, {  -9,  57 }, {  -6,  63 }, {  -4,  65 },
00808         {  -4,  67 }, {  -7,  82 },
00809 
00810         /* 436 - 459 */
00811         {  -3,  81 }, {  -3,  76 }, {  -7,  72 }, {  -6,  78 },
00812         { -12,  72 }, { -14,  68 }, {  -3,  70 }, {  -6,  76 },
00813         {  -5,  66 }, {  -5,  62 }, {   0,  57 }, {  -4,  61 },
00814         {  -9,  60 }, {   1,  54 }, {   2,  58 }, {  17, -10 },
00815         {  32, -13 }, {  42,  -9 }, {  49,  -5 }, {  53,   0 },
00816         {  64,   3 }, {  68,  10 }, {  66,  27 }, {  47,  57 },
00817 
00818         /* 460 - 1024 */
00819         {   0,  80 }, {  -5,  89 }, {  -7,  94 }, {  -4,  92 },
00820         {   0,  39 }, {   0,  65 }, { -15,  84 }, { -35, 127 },
00821         {  -2,  73 }, { -12, 104 }, {  -9,  91 }, { -31, 127 },
00822         {   0,  80 }, {  -5,  89 }, {  -7,  94 }, {  -4,  92 },
00823         {   0,  39 }, {   0,  65 }, { -15,  84 }, { -35, 127 },
00824         {  -2,  73 }, { -12, 104 }, {  -9,  91 }, { -31, 127 },
00825         { -13, 103 }, { -13,  91 }, {  -9,  89 }, { -14,  92 },
00826         {  -8,  76 }, { -12,  87 }, { -23, 110 }, { -24, 105 },
00827         { -10,  78 }, { -20, 112 }, { -17,  99 }, { -78, 127 },
00828         { -70, 127 }, { -50, 127 }, { -46, 127 }, {  -4,  66 },
00829         {  -5,  78 }, {  -4,  71 }, {  -8,  72 }, {   2,  59 },
00830         {  -1,  55 }, {  -7,  70 }, {  -6,  75 }, {  -8,  89 },
00831         { -34, 119 }, {  -3,  75 }, {  32,  20 }, {  30,  22 },
00832         { -44, 127 }, {   0,  54 }, {  -5,  61 }, {   0,  58 },
00833         {  -1,  60 }, {  -3,  61 }, {  -8,  67 }, { -25,  84 },
00834         { -14,  74 }, {  -5,  65 }, {   5,  52 }, {   2,  57 },
00835         {   0,  61 }, {  -9,  69 }, { -11,  70 }, {  18,  55 },
00836         { -13, 103 }, { -13,  91 }, {  -9,  89 }, { -14,  92 },
00837         {  -8,  76 }, { -12,  87 }, { -23, 110 }, { -24, 105 },
00838         { -10,  78 }, { -20, 112 }, { -17,  99 }, { -78, 127 },
00839         { -70, 127 }, { -50, 127 }, { -46, 127 }, {  -4,  66 },
00840         {  -5,  78 }, {  -4,  71 }, {  -8,  72 }, {   2,  59 },
00841         {  -1,  55 }, {  -7,  70 }, {  -6,  75 }, {  -8,  89 },
00842         { -34, 119 }, {  -3,  75 }, {  32,  20 }, {  30,  22 },
00843         { -44, 127 }, {   0,  54 }, {  -5,  61 }, {   0,  58 },
00844         {  -1,  60 }, {  -3,  61 }, {  -8,  67 }, { -25,  84 },
00845         { -14,  74 }, {  -5,  65 }, {   5,  52 }, {   2,  57 },
00846         {   0,  61 }, {  -9,  69 }, { -11,  70 }, {  18,  55 },
00847         {   4,  45 }, {  10,  28 }, {  10,  31 }, {  33, -11 },
00848         {  52, -43 }, {  18,  15 }, {  28,   0 }, {  35, -22 },
00849         {  38, -25 }, {  34,   0 }, {  39, -18 }, {  32, -12 },
00850         { 102, -94 }, {   0,   0 }, {  56, -15 }, {  33,  -4 },
00851         {  29,  10 }, {  37,  -5 }, {  51, -29 }, {  39,  -9 },
00852         {  52, -34 }, {  69, -58 }, {  67, -63 }, {  44,  -5 },
00853         {  32,   7 }, {  55, -29 }, {  32,   1 }, {   0,   0 },
00854         {  27,  36 }, {  33, -25 }, {  34, -30 }, {  36, -28 },
00855         {  38, -28 }, {  38, -27 }, {  34, -18 }, {  35, -16 },
00856         {  34, -14 }, {  32,  -8 }, {  37,  -6 }, {  35,   0 },
00857         {  30,  10 }, {  28,  18 }, {  26,  25 }, {  29,  41 },
00858         {   4,  45 }, {  10,  28 }, {  10,  31 }, {  33, -11 },
00859         {  52, -43 }, {  18,  15 }, {  28,   0 }, {  35, -22 },
00860         {  38, -25 }, {  34,   0 }, {  39, -18 }, {  32, -12 },
00861         { 102, -94 }, {   0,   0 }, {  56, -15 }, {  33,  -4 },
00862         {  29,  10 }, {  37,  -5 }, {  51, -29 }, {  39,  -9 },
00863         {  52, -34 }, {  69, -58 }, {  67, -63 }, {  44,  -5 },
00864         {  32,   7 }, {  55, -29 }, {  32,   1 }, {   0,   0 },
00865         {  27,  36 }, {  33, -25 }, {  34, -30 }, {  36, -28 },
00866         {  38, -28 }, {  38, -27 }, {  34, -18 }, {  35, -16 },
00867         {  34, -14 }, {  32,  -8 }, {  37,  -6 }, {  35,   0 },
00868         {  30,  10 }, {  28,  18 }, {  26,  25 }, {  29,  41 },
00869         {  -5,  85 }, {  -6,  81 }, { -10,  77 }, {  -7,  81 },
00870         { -17,  80 }, { -18,  73 }, {  -4,  74 }, { -10,  83 },
00871         {  -9,  71 }, {  -9,  67 }, {  -1,  61 }, {  -8,  66 },
00872         { -14,  66 }, {   0,  59 }, {   2,  59 }, {  -3,  81 },
00873         {  -3,  76 }, {  -7,  72 }, {  -6,  78 }, { -12,  72 },
00874         { -14,  68 }, {  -3,  70 }, {  -6,  76 }, {  -5,  66 },
00875         {  -5,  62 }, {   0,  57 }, {  -4,  61 }, {  -9,  60 },
00876         {   1,  54 }, {   2,  58 }, {  17, -10 }, {  32, -13 },
00877         {  42,  -9 }, {  49,  -5 }, {  53,   0 }, {  64,   3 },
00878         {  68,  10 }, {  66,  27 }, {  47,  57 }, {  17, -10 },
00879         {  32, -13 }, {  42,  -9 }, {  49,  -5 }, {  53,   0 },
00880         {  64,   3 }, {  68,  10 }, {  66,  27 }, {  47,  57 },
00881         {  -5,  71 }, {   0,  24 }, {  -1,  36 }, {  -2,  42 },
00882         {  -2,  52 }, {  -9,  57 }, {  -6,  63 }, {  -4,  65 },
00883         {  -4,  67 }, {  -7,  82 }, {  -5,  85 }, {  -6,  81 },
00884         { -10,  77 }, {  -7,  81 }, { -17,  80 }, { -18,  73 },
00885         {  -4,  74 }, { -10,  83 }, {  -9,  71 }, {  -9,  67 },
00886         {  -1,  61 }, {  -8,  66 }, { -14,  66 }, {   0,  59 },
00887         {   2,  59 }, {  -3,  81 }, {  -3,  76 }, {  -7,  72 },
00888         {  -6,  78 }, { -12,  72 }, { -14,  68 }, {  -3,  70 },
00889         {  -6,  76 }, {  -5,  66 }, {  -5,  62 }, {   0,  57 },
00890         {  -4,  61 }, {  -9,  60 }, {   1,  54 }, {   2,  58 },
00891         {  17, -10 }, {  32, -13 }, {  42,  -9 }, {  49,  -5 },
00892         {  53,   0 }, {  64,   3 }, {  68,  10 }, {  66,  27 },
00893         {  47,  57 }, {  17, -10 }, {  32, -13 }, {  42,  -9 },
00894         {  49,  -5 }, {  53,   0 }, {  64,   3 }, {  68,  10 },
00895         {  66,  27 }, {  47,  57 }, {  -5,  71 }, {   0,  24 },
00896         {  -1,  36 }, {  -2,  42 }, {  -2,  52 }, {  -9,  57 },
00897         {  -6,  63 }, {  -4,  65 }, {  -4,  67 }, {  -7,  82 },
00898         { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
00899         { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
00900         { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
00901         { -10,  95 }, { -14, 100 }, {  -8,  95 }, { -17, 111 },
00902         { -28, 114 }, {  -6,  89 }, {  -2,  80 }, {  -4,  82 },
00903         {  -9,  85 }, {  -8,  81 }, {  -1,  72 }, {   5,  64 },
00904         {   1,  67 }, {   9,  56 }, {   0,  69 }, {   1,  69 },
00905         {   7,  69 }, {  -7,  69 }, {  -6,  67 }, { -16,  77 },
00906         {  -2,  64 }, {   2,  61 }, {  -6,  67 }, {  -3,  64 },
00907         {   2,  57 }, {  -3,  65 }, {  -3,  66 }, {   0,  62 },
00908         {   9,  51 }, {  -1,  66 }, {  -2,  71 }, {  -2,  75 },
00909         { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
00910         { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
00911         { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
00912         { -10,  95 }, { -14, 100 }, {  -8,  95 }, { -17, 111 },
00913         { -28, 114 }, {  -6,  89 }, {  -2,  80 }, {  -4,  82 },
00914         {  -9,  85 }, {  -8,  81 }, {  -1,  72 }, {   5,  64 },
00915         {   1,  67 }, {   9,  56 }, {   0,  69 }, {   1,  69 },
00916         {   7,  69 }, {  -7,  69 }, {  -6,  67 }, { -16,  77 },
00917         {  -2,  64 }, {   2,  61 }, {  -6,  67 }, {  -3,  64 },
00918         {   2,  57 }, {  -3,  65 }, {  -3,  66 }, {   0,  62 },
00919         {   9,  51 }, {  -1,  66 }, {  -2,  71 }, {  -2,  75 },
00920         {  19,  -6 }, {  18,  -6 }, {  14,   0 }, {  26, -12 },
00921         {  31, -16 }, {  33, -25 }, {  33, -22 }, {  37, -28 },
00922         {  39, -30 }, {  42, -30 }, {  47, -42 }, {  45, -36 },
00923         {  49, -34 }, {  41, -17 }, {  32,   9 }, {  69, -71 },
00924         {  63, -63 }, {  66, -64 }, {  77, -74 }, {  54, -39 },
00925         {  52, -35 }, {  41, -10 }, {  36,   0 }, {  40,  -1 },
00926         {  30,  14 }, {  28,  26 }, {  23,  37 }, {  12,  55 },
00927         {  11,  65 }, {  37, -33 }, {  39, -36 }, {  40, -37 },
00928         {  38, -30 }, {  46, -33 }, {  42, -30 }, {  40, -24 },
00929         {  49, -29 }, {  38, -12 }, {  40, -10 }, {  38,  -3 },
00930         {  46,  -5 }, {  31,  20 }, {  29,  30 }, {  25,  44 },
00931         {  19,  -6 }, {  18,  -6 }, {  14,   0 }, {  26, -12 },
00932         {  31, -16 }, {  33, -25 }, {  33, -22 }, {  37, -28 },
00933         {  39, -30 }, {  42, -30 }, {  47, -42 }, {  45, -36 },
00934         {  49, -34 }, {  41, -17 }, {  32,   9 }, {  69, -71 },
00935         {  63, -63 }, {  66, -64 }, {  77, -74 }, {  54, -39 },
00936         {  52, -35 }, {  41, -10 }, {  36,   0 }, {  40,  -1 },
00937         {  30,  14 }, {  28,  26 }, {  23,  37 }, {  12,  55 },
00938         {  11,  65 }, {  37, -33 }, {  39, -36 }, {  40, -37 },
00939         {  38, -30 }, {  46, -33 }, {  42, -30 }, {  40, -24 },
00940         {  49, -29 }, {  38, -12 }, {  40, -10 }, {  38,  -3 },
00941         {  46,  -5 }, {  31,  20 }, {  29,  30 }, {  25,  44 },
00942         { -23, 112 }, { -15,  71 }, {  -7,  61 }, {   0,  53 },
00943         {  -5,  66 }, { -11,  77 }, {  -9,  80 }, {  -9,  84 },
00944         { -10,  87 }, { -34, 127 }, { -21, 101 }, {  -3,  39 },
00945         {  -5,  53 }, {  -7,  61 }, { -11,  75 }, { -15,  77 },
00946         { -17,  91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
00947         { -11,  76 }, { -10,  44 }, { -10,  52 }, { -10,  57 },
00948         {  -9,  58 }, { -16,  72 }, {  -7,  69 }, {  -4,  69 },
00949         {  -5,  74 }, {  -9,  86 }, { -23, 112 }, { -15,  71 },
00950         {  -7,  61 }, {   0,  53 }, {  -5,  66 }, { -11,  77 },
00951         {  -9,  80 }, {  -9,  84 }, { -10,  87 }, { -34, 127 },
00952         { -21, 101 }, {  -3,  39 }, {  -5,  53 }, {  -7,  61 },
00953         { -11,  75 }, { -15,  77 }, { -17,  91 }, { -25, 107 },
00954         { -25, 111 }, { -28, 122 }, { -11,  76 }, { -10,  44 },
00955         { -10,  52 }, { -10,  57 }, {  -9,  58 }, { -16,  72 },
00956         {  -7,  69 }, {  -4,  69 }, {  -5,  74 }, {  -9,  86 },
00957         {  -2,  73 }, { -12, 104 }, {  -9,  91 }, { -31, 127 },
00958         {  -2,  73 }, { -12, 104 }, {  -9,  91 }, { -31, 127 },
00959         {  -2,  73 }, { -12, 104 }, {  -9,  91 }, { -31, 127 }
00960     },
00961 
00962     /* i_cabac_init_idc == 2 */
00963     {
00964         /* 0 - 10 */
00965         {  20, -15 }, {   2,  54 }, {   3,  74 }, {  20, -15 },
00966         {   2,  54 }, {   3,  74 }, { -28, 127 }, { -23, 104 },
00967         {  -6,  53 }, {  -1,  54 }, {   7,  51 },
00968 
00969         /* 11 - 23 */
00970         {  29,  16 }, {  25,   0 }, {  14,   0 }, { -10,  51 },
00971         {  -3,  62 }, { -27,  99 }, {  26,  16 }, {  -4,  85 },
00972         { -24, 102 }, {   5,  57 }, {   6,  57 }, { -17,  73 },
00973         {  14,  57 },
00974 
00975         /* 24 - 39 */
00976         {  20,  40 }, {  20,  10 }, {  29,   0 }, {  54,   0 },
00977         {  37,  42 }, {  12,  97 }, { -32, 127 }, { -22, 117 },
00978         {  -2,  74 }, {  -4,  85 }, { -24, 102 }, {   5,  57 },
00979         {  -6,  93 }, { -14,  88 }, {  -6,  44 }, {   4,  55 },
00980 
00981         /* 40 - 53 */
00982         { -11,  89 },{ -15,  103 },{ -21,  116 },{  19,  57 },
00983         {  20,  58 },{   4,  84 },{   6,  96 },{   1,  63 },
00984         {  -5,  85 },{ -13,  106 },{   5,  63 },{   6,  75 },
00985         {  -3,  90 },{  -1,  101 },
00986 
00987         /* 54 - 59 */
00988         {   3,  55 },{  -4,  79 },{  -2,  75 },{ -12,  97 },
00989         {  -7,  50 },{   1,  60 },
00990 
00991         /* 60 - 69 */
00992         { 0, 41 },   { 0, 63 },   { 0, 63 },     { 0, 63 },
00993         { -9, 83 },  { 4, 86 },   { 0, 97 },     { -7, 72 },
00994         { 13, 41 },  { 3, 62 },
00995 
00996         /* 70 - 104 */
00997         {   7,  34 }, {  -9,  88 }, { -20, 127 }, { -36, 127 },
00998         { -17,  91 }, { -14,  95 }, { -25,  84 }, { -25,  86 },
00999         { -12,  89 }, { -17,  91 }, { -31, 127 }, { -14,  76 },
01000         { -18, 103 }, { -13,  90 }, { -37, 127 }, {  11,  80 },
01001         {   5,  76 }, {   2,  84 }, {   5,  78 }, {  -6,  55 },
01002         {   4,  61 }, { -14,  83 }, { -37, 127 }, {  -5,  79 },
01003         { -11, 104 }, { -11,  91 }, { -30, 127 }, {   0,  65 },
01004         {  -2,  79 }, {   0,  72 }, {  -4,  92 }, {  -6,  56 },
01005         {   3,  68 }, {  -8,  71 }, { -13,  98 },
01006 
01007         /* 105 -> 165 */
01008         {  -4,  86 }, { -12,  88 }, {  -5,  82 }, {  -3,  72 },
01009         {  -4,  67 }, {  -8,  72 }, { -16,  89 }, {  -9,  69 },
01010         {  -1,  59 }, {   5,  66 }, {   4,  57 }, {  -4,  71 },
01011         {  -2,  71 }, {   2,  58 }, {  -1,  74 }, {  -4,  44 },
01012         {  -1,  69 }, {   0,  62 }, {  -7,  51 }, {  -4,  47 },
01013         {  -6,  42 }, {  -3,  41 }, {  -6,  53 }, {   8,  76 },
01014         {  -9,  78 }, { -11,  83 }, {   9,  52 }, {   0,  67 },
01015         {  -5,  90 }, {   1,  67 }, { -15,  72 }, {  -5,  75 },
01016         {  -8,  80 }, { -21,  83 }, { -21,  64 }, { -13,  31 },
01017         { -25,  64 }, { -29,  94 }, {   9,  75 }, {  17,  63 },
01018         {  -8,  74 }, {  -5,  35 }, {  -2,  27 }, {  13,  91 },
01019         {   3,  65 }, {  -7,  69 }, {   8,  77 }, { -10,  66 },
01020         {   3,  62 }, {  -3,  68 }, { -20,  81 }, {   0,  30 },
01021         {   1,   7 }, {  -3,  23 }, { -21,  74 }, {  16,  66 },
01022         { -23, 124 }, {  17,  37 }, {  44, -18 }, {  50, -34 },
01023         { -22, 127 },
01024 
01025         /* 166 - 226 */
01026         {   4,  39 }, {   0,  42 }, {   7,  34 }, {  11,  29 },
01027         {   8,  31 }, {   6,  37 }, {   7,  42 }, {   3,  40 },
01028         {   8,  33 }, {  13,  43 }, {  13,  36 }, {   4,  47 },
01029         {   3,  55 }, {   2,  58 }, {   6,  60 }, {   8,  44 },
01030         {  11,  44 }, {  14,  42 }, {   7,  48 }, {   4,  56 },
01031         {   4,  52 }, {  13,  37 }, {   9,  49 }, {  19,  58 },
01032         {  10,  48 }, {  12,  45 }, {   0,  69 }, {  20,  33 },
01033         {   8,  63 }, {  35, -18 }, {  33, -25 }, {  28,  -3 },
01034         {  24,  10 }, {  27,   0 }, {  34, -14 }, {  52, -44 },
01035         {  39, -24 }, {  19,  17 }, {  31,  25 }, {  36,  29 },
01036         {  24,  33 }, {  34,  15 }, {  30,  20 }, {  22,  73 },
01037         {  20,  34 }, {  19,  31 }, {  27,  44 }, {  19,  16 },
01038         {  15,  36 }, {  15,  36 }, {  21,  28 }, {  25,  21 },
01039         {  30,  20 }, {  31,  12 }, {  27,  16 }, {  24,  42 },
01040         {   0,  93 }, {  14,  56 }, {  15,  57 }, {  26,  38 },
01041         { -24, 127 },
01042 
01043         /* 227 - 275 */
01044         { -24, 115 }, { -22,  82 }, {  -9,  62 }, {   0,  53 },
01045         {   0,  59 }, { -14,  85 }, { -13,  89 }, { -13,  94 },
01046         { -11,  92 }, { -29, 127 }, { -21, 100 }, { -14,  57 },
01047         { -12,  67 }, { -11,  71 }, { -10,  77 }, { -21,  85 },
01048         { -16,  88 }, { -23, 104 }, { -15,  98 }, { -37, 127 },
01049         { -10,  82 }, {  -8,  48 }, {  -8,  61 }, {  -8,  66 },
01050         {  -7,  70 }, { -14,  75 }, { -10,  79 }, {  -9,  83 },
01051         { -12,  92 }, { -18, 108 }, {  -4,  79 }, { -22,  69 },
01052         { -16,  75 }, {  -2,  58 }, {   1,  58 }, { -13,  78 },
01053         {  -9,  83 }, {  -4,  81 }, { -13,  99 }, { -13,  81 },
01054         {  -6,  38 }, { -13,  62 }, {  -6,  58 }, {  -2,  59 },
01055         { -16,  73 }, { -10,  76 }, { -13,  86 }, {  -9,  83 },
01056         { -10,  87 },
01057 
01058         /* 276 a bit special (not used, bypass is used instead) */
01059         { 0, 0 },
01060 
01061         /* 277 - 337 */
01062         { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
01063         { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
01064         { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
01065         { -10,  94 }, { -15, 102 }, { -10,  99 }, { -13, 106 },
01066         { -50, 127 }, {  -5,  92 }, {  17,  57 }, {  -5,  86 },
01067         { -13,  94 }, { -12,  91 }, {  -2,  77 }, {   0,  71 },
01068         {  -1,  73 }, {   4,  64 }, {  -7,  81 }, {   5,  64 },
01069         {  15,  57 }, {   1,  67 }, {   0,  68 }, { -10,  67 },
01070         {   1,  68 }, {   0,  77 }, {   2,  64 }, {   0,  68 },
01071         {  -5,  78 }, {   7,  55 }, {   5,  59 }, {   2,  65 },
01072         {  14,  54 }, {  15,  44 }, {   5,  60 }, {   2,  70 },
01073         {  -2,  76 }, { -18,  86 }, {  12,  70 }, {   5,  64 },
01074         { -12,  70 }, {  11,  55 }, {   5,  56 }, {   0,  69 },
01075         {   2,  65 }, {  -6,  74 }, {   5,  54 }, {   7,  54 },
01076         {  -6,  76 }, { -11,  82 }, {  -2,  77 }, {  -2,  77 },
01077         {  25,  42 },
01078 
01079         /* 338 - 398 */
01080         {  17, -13 }, {  16,  -9 }, {  17, -12 }, {  27, -21 },
01081         {  37, -30 }, {  41, -40 }, {  42, -41 }, {  48, -47 },
01082         {  39, -32 }, {  46, -40 }, {  52, -51 }, {  46, -41 },
01083         {  52, -39 }, {  43, -19 }, {  32,  11 }, {  61, -55 },
01084         {  56, -46 }, {  62, -50 }, {  81, -67 }, {  45, -20 },
01085         {  35,  -2 }, {  28,  15 }, {  34,   1 }, {  39,   1 },
01086         {  30,  17 }, {  20,  38 }, {  18,  45 }, {  15,  54 },
01087         {   0,  79 }, {  36, -16 }, {  37, -14 }, {  37, -17 },
01088         {  32,   1 }, {  34,  15 }, {  29,  15 }, {  24,  25 },
01089         {  34,  22 }, {  31,  16 }, {  35,  18 }, {  31,  28 },
01090         {  33,  41 }, {  36,  28 }, {  27,  47 }, {  21,  62 },
01091         {  18,  31 }, {  19,  26 }, {  36,  24 }, {  24,  23 },
01092         {  27,  16 }, {  24,  30 }, {  31,  29 }, {  22,  41 },
01093         {  22,  42 }, {  16,  60 }, {  15,  52 }, {  14,  60 },
01094         {   3,  78 }, { -16, 123 }, {  21,  53 }, {  22,  56 },
01095         {  25,  61 },
01096 
01097         /* 399 - 435 */
01098         {  21,  33 }, {  19,  50 }, {  17,  61 },
01099         {  -3,  78 }, {  -8,  74 }, {  -9,  72 }, { -10,  72 },
01100         { -18,  75 }, { -12,  71 }, { -11,  63 }, {  -5,  70 },
01101         { -17,  75 }, { -14,  72 }, { -16,  67 }, {  -8,  53 },
01102         { -14,  59 }, {  -9,  52 }, { -11,  68 }, {   9,  -2 },
01103         {  30, -10 }, {  31,  -4 }, {  33,  -1 }, {  33,   7 },
01104         {  31,  12 }, {  37,  23 }, {  31,  38 }, {  20,  64 },
01105         {  -9,  71 }, {  -7,  37 }, {  -8,  44 }, { -11,  49 },
01106         { -10,  56 }, { -12,  59 }, {  -8,  63 }, {  -9,  67 },
01107         {  -6,  68 }, { -10,  79 },
01108 
01109         /* 436 - 459 */
01110         {  -3,  78 }, {  -8,  74 }, {  -9,  72 }, { -10,  72 },
01111         { -18,  75 }, { -12,  71 }, { -11,  63 }, {  -5,  70 },
01112         { -17,  75 }, { -14,  72 }, { -16,  67 }, {  -8,  53 },
01113         { -14,  59 }, {  -9,  52 }, { -11,  68 }, {   9,  -2 },
01114         {  30, -10 }, {  31,  -4 }, {  33,  -1 }, {  33,   7 },
01115         {  31,  12 }, {  37,  23 }, {  31,  38 }, {  20,  64 },
01116 
01117         /* 460 - 1024 */
01118         {  11,  80 }, {   5,  76 }, {   2,  84 }, {   5,  78 },
01119         {  -6,  55 }, {   4,  61 }, { -14,  83 }, { -37, 127 },
01120         {  -5,  79 }, { -11, 104 }, { -11,  91 }, { -30, 127 },
01121         {  11,  80 }, {   5,  76 }, {   2,  84 }, {   5,  78 },
01122         {  -6,  55 }, {   4,  61 }, { -14,  83 }, { -37, 127 },
01123         {  -5,  79 }, { -11, 104 }, { -11,  91 }, { -30, 127 },
01124         {  -4,  86 }, { -12,  88 }, {  -5,  82 }, {  -3,  72 },
01125         {  -4,  67 }, {  -8,  72 }, { -16,  89 }, {  -9,  69 },
01126         {  -1,  59 }, {   5,  66 }, {   4,  57 }, {  -4,  71 },
01127         {  -2,  71 }, {   2,  58 }, {  -1,  74 }, {  -4,  44 },
01128         {  -1,  69 }, {   0,  62 }, {  -7,  51 }, {  -4,  47 },
01129         {  -6,  42 }, {  -3,  41 }, {  -6,  53 }, {   8,  76 },
01130         {  -9,  78 }, { -11,  83 }, {   9,  52 }, {   0,  67 },
01131         {  -5,  90 }, {   1,  67 }, { -15,  72 }, {  -5,  75 },
01132         {  -8,  80 }, { -21,  83 }, { -21,  64 }, { -13,  31 },
01133         { -25,  64 }, { -29,  94 }, {   9,  75 }, {  17,  63 },
01134         {  -8,  74 }, {  -5,  35 }, {  -2,  27 }, {  13,  91 },
01135         {  -4,  86 }, { -12,  88 }, {  -5,  82 }, {  -3,  72 },
01136         {  -4,  67 }, {  -8,  72 }, { -16,  89 }, {  -9,  69 },
01137         {  -1,  59 }, {   5,  66 }, {   4,  57 }, {  -4,  71 },
01138         {  -2,  71 }, {   2,  58 }, {  -1,  74 }, {  -4,  44 },
01139         {  -1,  69 }, {   0,  62 }, {  -7,  51 }, {  -4,  47 },
01140         {  -6,  42 }, {  -3,  41 }, {  -6,  53 }, {   8,  76 },
01141         {  -9,  78 }, { -11,  83 }, {   9,  52 }, {   0,  67 },
01142         {  -5,  90 }, {   1,  67 }, { -15,  72 }, {  -5,  75 },
01143         {  -8,  80 }, { -21,  83 }, { -21,  64 }, { -13,  31 },
01144         { -25,  64 }, { -29,  94 }, {   9,  75 }, {  17,  63 },
01145         {  -8,  74 }, {  -5,  35 }, {  -2,  27 }, {  13,  91 },
01146         {   4,  39 }, {   0,  42 }, {   7,  34 }, {  11,  29 },
01147         {   8,  31 }, {   6,  37 }, {   7,  42 }, {   3,  40 },
01148         {   8,  33 }, {  13,  43 }, {  13,  36 }, {   4,  47 },
01149         {   3,  55 }, {   2,  58 }, {   6,  60 }, {   8,  44 },
01150         {  11,  44 }, {  14,  42 }, {   7,  48 }, {   4,  56 },
01151         {   4,  52 }, {  13,  37 }, {   9,  49 }, {  19,  58 },
01152         {  10,  48 }, {  12,  45 }, {   0,  69 }, {  20,  33 },
01153         {   8,  63 }, {  35, -18 }, {  33, -25 }, {  28,  -3 },
01154         {  24,  10 }, {  27,   0 }, {  34, -14 }, {  52, -44 },
01155         {  39, -24 }, {  19,  17 }, {  31,  25 }, {  36,  29 },
01156         {  24,  33 }, {  34,  15 }, {  30,  20 }, {  22,  73 },
01157         {   4,  39 }, {   0,  42 }, {   7,  34 }, {  11,  29 },
01158         {   8,  31 }, {   6,  37 }, {   7,  42 }, {   3,  40 },
01159         {   8,  33 }, {  13,  43 }, {  13,  36 }, {   4,  47 },
01160         {   3,  55 }, {   2,  58 }, {   6,  60 }, {   8,  44 },
01161         {  11,  44 }, {  14,  42 }, {   7,  48 }, {   4,  56 },
01162         {   4,  52 }, {  13,  37 }, {   9,  49 }, {  19,  58 },
01163         {  10,  48 }, {  12,  45 }, {   0,  69 }, {  20,  33 },
01164         {   8,  63 }, {  35, -18 }, {  33, -25 }, {  28,  -3 },
01165         {  24,  10 }, {  27,   0 }, {  34, -14 }, {  52, -44 },
01166         {  39, -24 }, {  19,  17 }, {  31,  25 }, {  36,  29 },
01167         {  24,  33 }, {  34,  15 }, {  30,  20 }, {  22,  73 },
01168         {  -3,  78 }, {  -8,  74 }, {  -9,  72 }, { -10,  72 },
01169         { -18,  75 }, { -12,  71 }, { -11,  63 }, {  -5,  70 },
01170         { -17,  75 }, { -14,  72 }, { -16,  67 }, {  -8,  53 },
01171         { -14,  59 }, {  -9,  52 }, { -11,  68 }, {  -3,  78 },
01172         {  -8,  74 }, {  -9,  72 }, { -10,  72 }, { -18,  75 },
01173         { -12,  71 }, { -11,  63 }, {  -5,  70 }, { -17,  75 },
01174         { -14,  72 }, { -16,  67 }, {  -8,  53 }, { -14,  59 },
01175         {  -9,  52 }, { -11,  68 }, {   9,  -2 }, {  30, -10 },
01176         {  31,  -4 }, {  33,  -1 }, {  33,   7 }, {  31,  12 },
01177         {  37,  23 }, {  31,  38 }, {  20,  64 }, {   9,  -2 },
01178         {  30, -10 }, {  31,  -4 }, {  33,  -1 }, {  33,   7 },
01179         {  31,  12 }, {  37,  23 }, {  31,  38 }, {  20,  64 },
01180         {  -9,  71 }, {  -7,  37 }, {  -8,  44 }, { -11,  49 },
01181         { -10,  56 }, { -12,  59 }, {  -8,  63 }, {  -9,  67 },
01182         {  -6,  68 }, { -10,  79 }, {  -3,  78 }, {  -8,  74 },
01183         {  -9,  72 }, { -10,  72 }, { -18,  75 }, { -12,  71 },
01184         { -11,  63 }, {  -5,  70 }, { -17,  75 }, { -14,  72 },
01185         { -16,  67 }, {  -8,  53 }, { -14,  59 }, {  -9,  52 },
01186         { -11,  68 }, {  -3,  78 }, {  -8,  74 }, {  -9,  72 },
01187         { -10,  72 }, { -18,  75 }, { -12,  71 }, { -11,  63 },
01188         {  -5,  70 }, { -17,  75 }, { -14,  72 }, { -16,  67 },
01189         {  -8,  53 }, { -14,  59 }, {  -9,  52 }, { -11,  68 },
01190         {   9,  -2 }, {  30, -10 }, {  31,  -4 }, {  33,  -1 },
01191         {  33,   7 }, {  31,  12 }, {  37,  23 }, {  31,  38 },
01192         {  20,  64 }, {   9,  -2 }, {  30, -10 }, {  31,  -4 },
01193         {  33,  -1 }, {  33,   7 }, {  31,  12 }, {  37,  23 },
01194         {  31,  38 }, {  20,  64 }, {  -9,  71 }, {  -7,  37 },
01195         {  -8,  44 }, { -11,  49 }, { -10,  56 }, { -12,  59 },
01196         {  -8,  63 }, {  -9,  67 }, {  -6,  68 }, { -10,  79 },
01197         { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
01198         { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
01199         { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
01200         { -10,  94 }, { -15, 102 }, { -10,  99 }, { -13, 106 },
01201         { -50, 127 }, {  -5,  92 }, {  17,  57 }, {  -5,  86 },
01202         { -13,  94 }, { -12,  91 }, {  -2,  77 }, {   0,  71 },
01203         {  -1,  73 }, {   4,  64 }, {  -7,  81 }, {   5,  64 },
01204         {  15,  57 }, {   1,  67 }, {   0,  68 }, { -10,  67 },
01205         {   1,  68 }, {   0,  77 }, {   2,  64 }, {   0,  68 },
01206         {  -5,  78 }, {   7,  55 }, {   5,  59 }, {   2,  65 },
01207         {  14,  54 }, {  15,  44 }, {   5,  60 }, {   2,  70 },
01208         { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
01209         { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
01210         { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
01211         { -10,  94 }, { -15, 102 }, { -10,  99 }, { -13, 106 },
01212         { -50, 127 }, {  -5,  92 }, {  17,  57 }, {  -5,  86 },
01213         { -13,  94 }, { -12,  91 }, {  -2,  77 }, {   0,  71 },
01214         {  -1,  73 }, {   4,  64 }, {  -7,  81 }, {   5,  64 },
01215         {  15,  57 }, {   1,  67 }, {   0,  68 }, { -10,  67 },
01216         {   1,  68 }, {   0,  77 }, {   2,  64 }, {   0,  68 },
01217         {  -5,  78 }, {   7,  55 }, {   5,  59 }, {   2,  65 },
01218         {  14,  54 }, {  15,  44 }, {   5,  60 }, {   2,  70 },
01219         {  17, -13 }, {  16,  -9 }, {  17, -12 }, {  27, -21 },
01220         {  37, -30 }, {  41, -40 }, {  42, -41 }, {  48, -47 },
01221         {  39, -32 }, {  46, -40 }, {  52, -51 }, {  46, -41 },
01222         {  52, -39 }, {  43, -19 }, {  32,  11 }, {  61, -55 },
01223         {  56, -46 }, {  62, -50 }, {  81, -67 }, {  45, -20 },
01224         {  35,  -2 }, {  28,  15 }, {  34,   1 }, {  39,   1 },
01225         {  30,  17 }, {  20,  38 }, {  18,  45 }, {  15,  54 },
01226         {   0,  79 }, {  36, -16 }, {  37, -14 }, {  37, -17 },
01227         {  32,   1 }, {  34,  15 }, {  29,  15 }, {  24,  25 },
01228         {  34,  22 }, {  31,  16 }, {  35,  18 }, {  31,  28 },
01229         {  33,  41 }, {  36,  28 }, {  27,  47 }, {  21,  62 },
01230         {  17, -13 }, {  16,  -9 }, {  17, -12 }, {  27, -21 },
01231         {  37, -30 }, {  41, -40 }, {  42, -41 }, {  48, -47 },
01232         {  39, -32 }, {  46, -40 }, {  52, -51 }, {  46, -41 },
01233         {  52, -39 }, {  43, -19 }, {  32,  11 }, {  61, -55 },
01234         {  56, -46 }, {  62, -50 }, {  81, -67 }, {  45, -20 },
01235         {  35,  -2 }, {  28,  15 }, {  34,   1 }, {  39,   1 },
01236         {  30,  17 }, {  20,  38 }, {  18,  45 }, {  15,  54 },
01237         {   0,  79 }, {  36, -16 }, {  37, -14 }, {  37, -17 },
01238         {  32,   1 }, {  34,  15 }, {  29,  15 }, {  24,  25 },
01239         {  34,  22 }, {  31,  16 }, {  35,  18 }, {  31,  28 },
01240         {  33,  41 }, {  36,  28 }, {  27,  47 }, {  21,  62 },
01241         { -24, 115 }, { -22,  82 }, {  -9,  62 }, {   0,  53 },
01242         {   0,  59 }, { -14,  85 }, { -13,  89 }, { -13,  94 },
01243         { -11,  92 }, { -29, 127 }, { -21, 100 }, { -14,  57 },
01244         { -12,  67 }, { -11,  71 }, { -10,  77 }, { -21,  85 },
01245         { -16,  88 }, { -23, 104 }, { -15,  98 }, { -37, 127 },
01246         { -10,  82 }, {  -8,  48 }, {  -8,  61 }, {  -8,  66 },
01247         {  -7,  70 }, { -14,  75 }, { -10,  79 }, {  -9,  83 },
01248         { -12,  92 }, { -18, 108 }, { -24, 115 }, { -22,  82 },
01249         {  -9,  62 }, {   0,  53 }, {   0,  59 }, { -14,  85 },
01250         { -13,  89 }, { -13,  94 }, { -11,  92 }, { -29, 127 },
01251         { -21, 100 }, { -14,  57 }, { -12,  67 }, { -11,  71 },
01252         { -10,  77 }, { -21,  85 }, { -16,  88 }, { -23, 104 },
01253         { -15,  98 }, { -37, 127 }, { -10,  82 }, {  -8,  48 },
01254         {  -8,  61 }, {  -8,  66 }, {  -7,  70 }, { -14,  75 },
01255         { -10,  79 }, {  -9,  83 }, { -12,  92 }, { -18, 108 },
01256         {  -5,  79 }, { -11, 104 }, { -11,  91 }, { -30, 127 },
01257         {  -5,  79 }, { -11, 104 }, { -11,  91 }, { -30, 127 },
01258         {  -5,  79 }, { -11, 104 }, { -11,  91 }, { -30, 127 }
01259     }
01260 };
01261 
01262 void ff_h264_init_cabac_states(H264Context *h) {
01263     MpegEncContext * const s = &h->s;
01264     int i;
01265     const int8_t (*tab)[2];
01266     const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51);
01267 
01268     if( h->slice_type_nos == AV_PICTURE_TYPE_I ) tab = cabac_context_init_I;
01269     else                                 tab = cabac_context_init_PB[h->cabac_init_idc];
01270 
01271     /* calculate pre-state */
01272     for( i= 0; i < 1024; i++ ) {
01273         int pre = 2*(((tab[i][0] * slice_qp) >>4 ) + tab[i][1]) - 127;
01274 
01275         pre^= pre>>31;
01276         if(pre > 124)
01277             pre= 124 + (pre&1);
01278 
01279         h->cabac_state[i] =  pre;
01280     }
01281 }
01282 
01283 static int decode_cabac_field_decoding_flag(H264Context *h) {
01284     MpegEncContext * const s = &h->s;
01285     const long mbb_xy = h->mb_xy - 2L*s->mb_stride;
01286 
01287     unsigned long ctx = 0;
01288 
01289     ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num);
01290     ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
01291 
01292     return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] );
01293 }
01294 
01295 static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) {
01296     uint8_t *state= &h->cabac_state[ctx_base];
01297     int mb_type;
01298 
01299     if(intra_slice){
01300         int ctx=0;
01301         if( h->left_type[LTOP] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM))
01302             ctx++;
01303         if( h->top_type        & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM))
01304             ctx++;
01305         if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 )
01306             return 0;   /* I4x4 */
01307         state += 2;
01308     }else{
01309         if( get_cabac_noinline( &h->cabac, state ) == 0 )
01310             return 0;   /* I4x4 */
01311     }
01312 
01313     if( get_cabac_terminate( &h->cabac ) )
01314         return 25;  /* PCM */
01315 
01316     mb_type = 1; /* I16x16 */
01317     mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */
01318     if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */
01319         mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] );
01320     mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] );
01321     mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] );
01322     return mb_type;
01323 }
01324 
01325 static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
01326     MpegEncContext * const s = &h->s;
01327     int mba_xy, mbb_xy;
01328     int ctx = 0;
01329 
01330     if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches?
01331         int mb_xy = mb_x + (mb_y&~1)*s->mb_stride;
01332         mba_xy = mb_xy - 1;
01333         if( (mb_y&1)
01334             && h->slice_table[mba_xy] == h->slice_num
01335             && MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) )
01336             mba_xy += s->mb_stride;
01337         if( MB_FIELD ){
01338             mbb_xy = mb_xy - s->mb_stride;
01339             if( !(mb_y&1)
01340                 && h->slice_table[mbb_xy] == h->slice_num
01341                 && IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) )
01342                 mbb_xy -= s->mb_stride;
01343         }else
01344             mbb_xy = mb_x + (mb_y-1)*s->mb_stride;
01345     }else{
01346         int mb_xy = h->mb_xy;
01347         mba_xy = mb_xy - 1;
01348         mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE);
01349     }
01350 
01351     if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] ))
01352         ctx++;
01353     if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] ))
01354         ctx++;
01355 
01356     if( h->slice_type_nos == AV_PICTURE_TYPE_B )
01357         ctx += 13;
01358     return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] );
01359 }
01360 
01361 static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) {
01362     int mode = 0;
01363 
01364     if( get_cabac( &h->cabac, &h->cabac_state[68] ) )
01365         return pred_mode;
01366 
01367     mode += 1 * get_cabac( &h->cabac, &h->cabac_state[69] );
01368     mode += 2 * get_cabac( &h->cabac, &h->cabac_state[69] );
01369     mode += 4 * get_cabac( &h->cabac, &h->cabac_state[69] );
01370 
01371     return mode + ( mode >= pred_mode );
01372 }
01373 
01374 static int decode_cabac_mb_chroma_pre_mode( H264Context *h) {
01375     const int mba_xy = h->left_mb_xy[0];
01376     const int mbb_xy = h->top_mb_xy;
01377 
01378     int ctx = 0;
01379 
01380     /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */
01381     if( h->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0 )
01382         ctx++;
01383 
01384     if( h->top_type        && h->chroma_pred_mode_table[mbb_xy] != 0 )
01385         ctx++;
01386 
01387     if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 )
01388         return 0;
01389 
01390     if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 )
01391         return 1;
01392     if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 )
01393         return 2;
01394     else
01395         return 3;
01396 }
01397 
01398 static int decode_cabac_mb_cbp_luma( H264Context *h) {
01399     int cbp_b, cbp_a, ctx, cbp = 0;
01400 
01401     cbp_a = h->left_cbp;
01402     cbp_b = h->top_cbp;
01403 
01404     ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04);
01405     cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]);
01406     ctx = !(cbp   & 0x01) + 2 * !(cbp_b & 0x08);
01407     cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 1;
01408     ctx = !(cbp_a & 0x08) + 2 * !(cbp   & 0x01);
01409     cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 2;
01410     ctx = !(cbp   & 0x04) + 2 * !(cbp   & 0x02);
01411     cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 3;
01412     return cbp;
01413 }
01414 static int decode_cabac_mb_cbp_chroma( H264Context *h) {
01415     int ctx;
01416     int cbp_a, cbp_b;
01417 
01418     cbp_a = (h->left_cbp>>4)&0x03;
01419     cbp_b = (h-> top_cbp>>4)&0x03;
01420 
01421     ctx = 0;
01422     if( cbp_a > 0 ) ctx++;
01423     if( cbp_b > 0 ) ctx += 2;
01424     if( get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 )
01425         return 0;
01426 
01427     ctx = 4;
01428     if( cbp_a == 2 ) ctx++;
01429     if( cbp_b == 2 ) ctx += 2;
01430     return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] );
01431 }
01432 
01433 static int decode_cabac_p_mb_sub_type( H264Context *h ) {
01434     if( get_cabac( &h->cabac, &h->cabac_state[21] ) )
01435         return 0;   /* 8x8 */
01436     if( !get_cabac( &h->cabac, &h->cabac_state[22] ) )
01437         return 1;   /* 8x4 */
01438     if( get_cabac( &h->cabac, &h->cabac_state[23] ) )
01439         return 2;   /* 4x8 */
01440     return 3;       /* 4x4 */
01441 }
01442 static int decode_cabac_b_mb_sub_type( H264Context *h ) {
01443     int type;
01444     if( !get_cabac( &h->cabac, &h->cabac_state[36] ) )
01445         return 0;   /* B_Direct_8x8 */
01446     if( !get_cabac( &h->cabac, &h->cabac_state[37] ) )
01447         return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */
01448     type = 3;
01449     if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) {
01450         if( get_cabac( &h->cabac, &h->cabac_state[39] ) )
01451             return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */
01452         type += 4;
01453     }
01454     type += 2*get_cabac( &h->cabac, &h->cabac_state[39] );
01455     type +=   get_cabac( &h->cabac, &h->cabac_state[39] );
01456     return type;
01457 }
01458 
01459 static int decode_cabac_mb_ref( H264Context *h, int list, int n ) {
01460     int refa = h->ref_cache[list][scan8[n] - 1];
01461     int refb = h->ref_cache[list][scan8[n] - 8];
01462     int ref  = 0;
01463     int ctx  = 0;
01464 
01465     if( h->slice_type_nos == AV_PICTURE_TYPE_B) {
01466         if( refa > 0 && !(h->direct_cache[scan8[n] - 1]&(MB_TYPE_DIRECT2>>1)) )
01467             ctx++;
01468         if( refb > 0 && !(h->direct_cache[scan8[n] - 8]&(MB_TYPE_DIRECT2>>1)) )
01469             ctx += 2;
01470     } else {
01471         if( refa > 0 )
01472             ctx++;
01473         if( refb > 0 )
01474             ctx += 2;
01475     }
01476 
01477     while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) {
01478         ref++;
01479         ctx = (ctx>>2)+4;
01480         if(ref >= 32 /*h->ref_list[list]*/){
01481             return -1;
01482         }
01483     }
01484     return ref;
01485 }
01486 
01487 static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda) {
01488     int mvd;
01489 
01490     if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+((amvd-3)>>(INT_BIT-1))+((amvd-33)>>(INT_BIT-1))+2])){
01491 //    if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+(amvd>2)+(amvd>32)])){
01492         *mvda= 0;
01493         return 0;
01494     }
01495 
01496     mvd= 1;
01497     ctxbase+= 3;
01498     while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase] ) ) {
01499         if( mvd < 4 )
01500             ctxbase++;
01501         mvd++;
01502     }
01503 
01504     if( mvd >= 9 ) {
01505         int k = 3;
01506         while( get_cabac_bypass( &h->cabac ) ) {
01507             mvd += 1 << k;
01508             k++;
01509             if(k>24){
01510                 av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n");
01511                 return INT_MIN;
01512             }
01513         }
01514         while( k-- ) {
01515             mvd += get_cabac_bypass( &h->cabac )<<k;
01516         }
01517         *mvda=mvd < 70 ? mvd : 70;
01518     }else
01519         *mvda=mvd;
01520     return get_cabac_bypass_sign( &h->cabac, -mvd );
01521 }
01522 
01523 #define DECODE_CABAC_MB_MVD( h,  list,  n )\
01524 {\
01525     int amvd0 = h->mvd_cache[list][scan8[n] - 1][0] +\
01526                 h->mvd_cache[list][scan8[n] - 8][0];\
01527     int amvd1 = h->mvd_cache[list][scan8[n] - 1][1] +\
01528                 h->mvd_cache[list][scan8[n] - 8][1];\
01529 \
01530     mx += decode_cabac_mb_mvd( h, 40, amvd0, &mpx );\
01531     my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\
01532 }
01533 
01534 static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int max_coeff, int is_dc ) {
01535     int nza, nzb;
01536     int ctx = 0;
01537     static const uint16_t base_ctx[14] = {85,89,93,97,101,1012,460,464,468,1016,472,476,480,1020};
01538 
01539     if( is_dc ) {
01540         if( cat == 3 ) {
01541             idx -= CHROMA_DC_BLOCK_INDEX;
01542             nza = (h->left_cbp>>(6+idx))&0x01;
01543             nzb = (h-> top_cbp>>(6+idx))&0x01;
01544         } else {
01545             idx -= LUMA_DC_BLOCK_INDEX;
01546             nza = h->left_cbp&(0x100<<idx);
01547             nzb = h-> top_cbp&(0x100<<idx);
01548         }
01549     } else {
01550         nza = h->non_zero_count_cache[scan8[idx] - 1];
01551         nzb = h->non_zero_count_cache[scan8[idx] - 8];
01552     }
01553 
01554     if( nza > 0 )
01555         ctx++;
01556 
01557     if( nzb > 0 )
01558         ctx += 2;
01559 
01560     return base_ctx[cat] + ctx;
01561 }
01562 
01563 DECLARE_ASM_CONST(1, uint8_t, last_coeff_flag_offset_8x8)[63] = {
01564     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
01565     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
01566     3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
01567     5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
01568 };
01569 
01570 static av_always_inline void
01571 decode_cabac_residual_internal(H264Context *h, DCTELEM *block,
01572                                int cat, int n, const uint8_t *scantable,
01573                                const uint32_t *qmul, int max_coeff,
01574                                int is_dc, int chroma422)
01575 {
01576     static const int significant_coeff_flag_offset[2][14] = {
01577       { 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718 },
01578       { 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733 }
01579     };
01580     static const int last_coeff_flag_offset[2][14] = {
01581       { 166+0, 166+15, 166+29, 166+44, 166+47, 417, 572+0, 572+15, 572+29, 690, 616+0, 616+15, 616+29, 748 },
01582       { 338+0, 338+15, 338+29, 338+44, 338+47, 451, 864+0, 864+15, 864+29, 699, 908+0, 908+15, 908+29, 757 }
01583     };
01584     static const int coeff_abs_level_m1_offset[14] = {
01585         227+0, 227+10, 227+20, 227+30, 227+39, 426, 952+0, 952+10, 952+20, 708, 982+0, 982+10, 982+20, 766
01586     };
01587     static const uint8_t significant_coeff_flag_offset_8x8[2][63] = {
01588       { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
01589         4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
01590         7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
01591        12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12 },
01592       { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
01593         6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
01594         9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
01595         9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 }
01596     };
01597     static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 };
01598     /* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
01599      * 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
01600      * map node ctx => cabac ctx for level=1 */
01601     static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 };
01602     /* map node ctx => cabac ctx for level>1 */
01603     static const uint8_t coeff_abs_levelgt1_ctx[2][8] = {
01604         { 5, 5, 5, 5, 6, 7, 8, 9 },
01605         { 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case
01606     };
01607     static const uint8_t coeff_abs_level_transition[2][8] = {
01608     /* update node ctx after decoding a level=1 */
01609         { 1, 2, 3, 3, 4, 5, 6, 7 },
01610     /* update node ctx after decoding a level>1 */
01611         { 4, 4, 4, 4, 5, 6, 7, 7 }
01612     };
01613 
01614     int index[64];
01615 
01616     int av_unused last;
01617     int coeff_count = 0;
01618     int node_ctx = 0;
01619 
01620     uint8_t *significant_coeff_ctx_base;
01621     uint8_t *last_coeff_ctx_base;
01622     uint8_t *abs_level_m1_ctx_base;
01623 
01624 #if !ARCH_X86
01625 #define CABAC_ON_STACK
01626 #endif
01627 #ifdef CABAC_ON_STACK
01628 #define CC &cc
01629     CABACContext cc;
01630     cc.range     = h->cabac.range;
01631     cc.low       = h->cabac.low;
01632     cc.bytestream= h->cabac.bytestream;
01633 #else
01634 #define CC &h->cabac
01635 #endif
01636 
01637     significant_coeff_ctx_base = h->cabac_state
01638         + significant_coeff_flag_offset[MB_FIELD][cat];
01639     last_coeff_ctx_base = h->cabac_state
01640         + last_coeff_flag_offset[MB_FIELD][cat];
01641     abs_level_m1_ctx_base = h->cabac_state
01642         + coeff_abs_level_m1_offset[cat];
01643 
01644     if( !is_dc && max_coeff == 64 ) {
01645 #define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \
01646         for(last= 0; last < coefs; last++) { \
01647             uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \
01648             if( get_cabac( CC, sig_ctx )) { \
01649                 uint8_t *last_ctx = last_coeff_ctx_base + last_off; \
01650                 index[coeff_count++] = last; \
01651                 if( get_cabac( CC, last_ctx ) ) { \
01652                     last= max_coeff; \
01653                     break; \
01654                 } \
01655             } \
01656         }\
01657         if( last == max_coeff -1 ) {\
01658             index[coeff_count++] = last;\
01659         }
01660         const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
01661 #if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
01662         coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index,
01663                                                  last_coeff_ctx_base, sig_off);
01664     } else {
01665         if (is_dc && chroma422) { // dc 422
01666             DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
01667         } else {
01668             coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index,
01669                                                  last_coeff_ctx_base-significant_coeff_ctx_base);
01670         }
01671 #else
01672         DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] );
01673     } else {
01674         if (is_dc && chroma422) { // dc 422
01675             DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
01676         } else {
01677             DECODE_SIGNIFICANCE(max_coeff - 1, last, last);
01678         }
01679 #endif
01680     }
01681     assert(coeff_count > 0);
01682 
01683     if( is_dc ) {
01684         if( cat == 3 )
01685             h->cbp_table[h->mb_xy] |= 0x40 << (n - CHROMA_DC_BLOCK_INDEX);
01686         else
01687             h->cbp_table[h->mb_xy] |= 0x100 << (n - LUMA_DC_BLOCK_INDEX);
01688         h->non_zero_count_cache[scan8[n]] = coeff_count;
01689     } else {
01690         if( max_coeff == 64 )
01691             fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1);
01692         else {
01693             assert( cat == 1 || cat ==  2 || cat ==  4 || cat == 7 || cat == 8 || cat == 11 || cat == 12 );
01694             h->non_zero_count_cache[scan8[n]] = coeff_count;
01695         }
01696     }
01697 
01698 #define STORE_BLOCK(type) \
01699     do { \
01700         uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; \
01701  \
01702         int j= scantable[index[--coeff_count]]; \
01703  \
01704         if( get_cabac( CC, ctx ) == 0 ) { \
01705             node_ctx = coeff_abs_level_transition[0][node_ctx]; \
01706             if( is_dc ) { \
01707                 ((type*)block)[j] = get_cabac_bypass_sign( CC, -1); \
01708             }else{ \
01709                 ((type*)block)[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; \
01710             } \
01711         } else { \
01712             int coeff_abs = 2; \
01713             ctx = coeff_abs_levelgt1_ctx[is_dc && chroma422][node_ctx] + abs_level_m1_ctx_base; \
01714             node_ctx = coeff_abs_level_transition[1][node_ctx]; \
01715 \
01716             while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \
01717                 coeff_abs++; \
01718             } \
01719 \
01720             if( coeff_abs >= 15 ) { \
01721                 int j = 0; \
01722                 while (get_cabac_bypass(CC) && j < 30) { \
01723                     j++; \
01724                 } \
01725 \
01726                 coeff_abs=1; \
01727                 while( j-- ) { \
01728                     coeff_abs += coeff_abs + get_cabac_bypass( CC ); \
01729                 } \
01730                 coeff_abs+= 14; \
01731             } \
01732 \
01733             if( is_dc ) { \
01734                 ((type*)block)[j] = get_cabac_bypass_sign( CC, -coeff_abs ); \
01735             }else{ \
01736                 ((type*)block)[j] = ((int)(get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32)) >> 6; \
01737             } \
01738         } \
01739     } while ( coeff_count );
01740 
01741     if (h->pixel_shift) {
01742         STORE_BLOCK(int32_t)
01743     } else {
01744         STORE_BLOCK(int16_t)
01745     }
01746 #ifdef CABAC_ON_STACK
01747             h->cabac.range     = cc.range     ;
01748             h->cabac.low       = cc.low       ;
01749             h->cabac.bytestream= cc.bytestream;
01750 #endif
01751 
01752 }
01753 
01754 static void decode_cabac_residual_dc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) {
01755     decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0);
01756 }
01757 
01758 static void decode_cabac_residual_dc_internal_422(H264Context *h, DCTELEM *block,
01759                                                   int cat, int n, const uint8_t *scantable,
01760                                                   int max_coeff)
01761 {
01762     decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1);
01763 }
01764 
01765 static void decode_cabac_residual_nondc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
01766     decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0);
01767 }
01768 
01769 /* cat: 0-> DC 16x16  n = 0
01770  *      1-> AC 16x16  n = luma4x4idx
01771  *      2-> Luma4x4   n = luma4x4idx
01772  *      3-> DC Chroma n = iCbCr
01773  *      4-> AC Chroma n = 16 + 4 * iCbCr + chroma4x4idx
01774  *      5-> Luma8x8   n = 4 * luma8x8idx */
01775 
01776 /* Partially inline the CABAC residual decode: inline the coded block flag.
01777  * This has very little impact on binary size and improves performance
01778  * because it allows improved constant propagation into get_cabac_cbf_ctx,
01779  * as well as because most blocks have zero CBFs. */
01780 
01781 static av_always_inline void decode_cabac_residual_dc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) {
01782     /* read coded block flag */
01783     if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 1 ) ] ) == 0 ) {
01784         h->non_zero_count_cache[scan8[n]] = 0;
01785         return;
01786     }
01787     decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff );
01788 }
01789 
01790 static av_always_inline void
01791 decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block,
01792                              int cat, int n, const uint8_t *scantable,
01793                              int max_coeff)
01794 {
01795     /* read coded block flag */
01796     if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) {
01797         h->non_zero_count_cache[scan8[n]] = 0;
01798         return;
01799     }
01800     decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff);
01801 }
01802 
01803 static av_always_inline void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
01804     /* read coded block flag */
01805     if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
01806         if( max_coeff == 64 ) {
01807             fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1);
01808         } else {
01809             h->non_zero_count_cache[scan8[n]] = 0;
01810         }
01811         return;
01812     }
01813     decode_cabac_residual_nondc_internal( h, block, cat, n, scantable, qmul, max_coeff );
01814 }
01815 
01816 static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p )
01817 {
01818     static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};
01819     const uint32_t *qmul;
01820     int i8x8, i4x4;
01821     MpegEncContext * const s = &h->s;
01822     int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1];
01823     if( IS_INTRA16x16( mb_type ) ) {
01824         //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" );
01825         AV_ZERO128(h->mb_luma_dc[p]+0);
01826         AV_ZERO128(h->mb_luma_dc[p]+8);
01827         AV_ZERO128(h->mb_luma_dc[p]+16);
01828         AV_ZERO128(h->mb_luma_dc[p]+24);
01829         decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16);
01830 
01831         if( cbp&15 ) {
01832             qmul = h->dequant4_coeff[p][qscale];
01833             for( i4x4 = 0; i4x4 < 16; i4x4++ ) {
01834                 const int index = 16*p + i4x4;
01835                 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", index );
01836                 decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15);
01837             }
01838         } else {
01839             fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1);
01840         }
01841     } else {
01842         int cqm = (IS_INTRA( mb_type ) ? 0:3) + p;
01843         for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
01844             if( cbp & (1<<i8x8) ) {
01845                 if( IS_8x8DCT(mb_type) ) {
01846                     const int index = 16*p + 4*i8x8;
01847                     decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index,
01848                                                 scan8x8, h->dequant8_coeff[cqm][qscale], 64);
01849                 } else {
01850                     qmul = h->dequant4_coeff[cqm][qscale];
01851                     for( i4x4 = 0; i4x4 < 4; i4x4++ ) {
01852                         const int index = 16*p + 4*i8x8 + i4x4;
01853                         //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index );
01854 //START_TIMER
01855                         decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16);
01856 //STOP_TIMER("decode_residual")
01857                     }
01858                 }
01859             } else {
01860                 fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);
01861             }
01862         }
01863     }
01864 }
01865 
01870 int ff_h264_decode_mb_cabac(H264Context *h) {
01871     MpegEncContext * const s = &h->s;
01872     int mb_xy;
01873     int mb_type, partition_count, cbp = 0;
01874     int dct8x8_allowed= h->pps.transform_8x8_mode;
01875     int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;
01876     const int pixel_shift = h->pixel_shift;
01877 
01878     mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
01879 
01880     tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
01881     if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {
01882         int skip;
01883         /* a skipped mb needs the aff flag from the following mb */
01884         if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )
01885             skip = h->next_mb_skipped;
01886         else
01887             skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );
01888         /* read skip flags */
01889         if( skip ) {
01890             if( FRAME_MBAFF && (s->mb_y&1)==0 ){
01891                 s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP;
01892                 h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );
01893                 if(!h->next_mb_skipped)
01894                     h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
01895             }
01896 
01897             decode_mb_skip(h);
01898 
01899             h->cbp_table[mb_xy] = 0;
01900             h->chroma_pred_mode_table[mb_xy] = 0;
01901             h->last_qscale_diff = 0;
01902 
01903             return 0;
01904 
01905         }
01906     }
01907     if(FRAME_MBAFF){
01908         if( (s->mb_y&1) == 0 )
01909             h->mb_mbaff =
01910             h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
01911     }
01912 
01913     h->prev_mb_skipped = 0;
01914 
01915     fill_decode_neighbors(h, -(MB_FIELD));
01916 
01917     if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
01918         int ctx = 0;
01919         assert(h->slice_type_nos == AV_PICTURE_TYPE_B);
01920 
01921         if( !IS_DIRECT( h->left_type[LTOP]-1 ) )
01922             ctx++;
01923         if( !IS_DIRECT( h->top_type-1 ) )
01924             ctx++;
01925 
01926         if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){
01927             mb_type= 0; /* B_Direct_16x16 */
01928         }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {
01929             mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */
01930         }else{
01931             int bits;
01932             bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;
01933             bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;
01934             bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;
01935             bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );
01936             if( bits < 8 ){
01937                 mb_type= bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */
01938             }else if( bits == 13 ){
01939                 mb_type= decode_cabac_intra_mb_type(h, 32, 0);
01940                 goto decode_intra_mb;
01941             }else if( bits == 14 ){
01942                 mb_type= 11; /* B_L1_L0_8x16 */
01943             }else if( bits == 15 ){
01944                 mb_type= 22; /* B_8x8 */
01945             }else{
01946                 bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );
01947                 mb_type= bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */
01948             }
01949         }
01950             partition_count= b_mb_type_info[mb_type].partition_count;
01951             mb_type=         b_mb_type_info[mb_type].type;
01952     } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {
01953         if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {
01954             /* P-type */
01955             if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {
01956                 /* P_L0_D16x16, P_8x8 */
01957                 mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );
01958             } else {
01959                 /* P_L0_D8x16, P_L0_D16x8 */
01960                 mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );
01961             }
01962             partition_count= p_mb_type_info[mb_type].partition_count;
01963             mb_type=         p_mb_type_info[mb_type].type;
01964         } else {
01965             mb_type= decode_cabac_intra_mb_type(h, 17, 0);
01966             goto decode_intra_mb;
01967         }
01968     } else {
01969         mb_type= decode_cabac_intra_mb_type(h, 3, 1);
01970         if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)
01971             mb_type--;
01972         assert(h->slice_type_nos == AV_PICTURE_TYPE_I);
01973 decode_intra_mb:
01974         partition_count = 0;
01975         cbp= i_mb_type_info[mb_type].cbp;
01976         h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
01977         mb_type= i_mb_type_info[mb_type].type;
01978     }
01979     if(MB_FIELD)
01980         mb_type |= MB_TYPE_INTERLACED;
01981 
01982     h->slice_table[ mb_xy ]= h->slice_num;
01983 
01984     if(IS_INTRA_PCM(mb_type)) {
01985         static const uint16_t mb_sizes[4] = {256,384,512,768};
01986         const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;
01987         const uint8_t *ptr;
01988 
01989         // We assume these blocks are very rare so we do not optimize it.
01990         // FIXME The two following lines get the bitstream position in the cabac
01991         // decode, I think it should be done by a function in cabac.h (or cabac.c).
01992         ptr= h->cabac.bytestream;
01993         if(h->cabac.low&0x1) ptr--;
01994         if(CABAC_BITS==16){
01995             if(h->cabac.low&0x1FF) ptr--;
01996         }
01997 
01998         // The pixels are stored in the same order as levels in h->mb array.
01999         if ((int) (h->cabac.bytestream_end - ptr) < mb_size)
02000             return -1;
02001         memcpy(h->mb, ptr, mb_size); ptr+=mb_size;
02002 
02003         ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
02004 
02005         // All blocks are present
02006         h->cbp_table[mb_xy] = 0xf7ef;
02007         h->chroma_pred_mode_table[mb_xy] = 0;
02008         // In deblocking, the quantizer is 0
02009         s->current_picture.f.qscale_table[mb_xy] = 0;
02010         // All coeffs are present
02011         memset(h->non_zero_count[mb_xy], 16, 48);
02012         s->current_picture.f.mb_type[mb_xy] = mb_type;
02013         h->last_qscale_diff = 0;
02014         return 0;
02015     }
02016 
02017     if(MB_MBAFF){
02018         h->ref_count[0] <<= 1;
02019         h->ref_count[1] <<= 1;
02020     }
02021 
02022     fill_decode_caches(h, mb_type);
02023 
02024     if( IS_INTRA( mb_type ) ) {
02025         int i, pred_mode;
02026         if( IS_INTRA4x4( mb_type ) ) {
02027             if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {
02028                 mb_type |= MB_TYPE_8x8DCT;
02029                 for( i = 0; i < 16; i+=4 ) {
02030                     int pred = pred_intra_mode( h, i );
02031                     int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );
02032                     fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );
02033                 }
02034             } else {
02035                 for( i = 0; i < 16; i++ ) {
02036                     int pred = pred_intra_mode( h, i );
02037                     h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );
02038 
02039                 //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] );
02040                 }
02041             }
02042             write_back_intra_pred_mode(h);
02043             if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;
02044         } else {
02045             h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode, 0 );
02046             if( h->intra16x16_pred_mode < 0 ) return -1;
02047         }
02048         if(decode_chroma){
02049             h->chroma_pred_mode_table[mb_xy] =
02050             pred_mode                        = decode_cabac_mb_chroma_pre_mode( h );
02051 
02052             pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode, 1 );
02053             if( pred_mode < 0 ) return -1;
02054             h->chroma_pred_mode= pred_mode;
02055         } else {
02056             h->chroma_pred_mode= DC_128_PRED8x8;
02057         }
02058     } else if( partition_count == 4 ) {
02059         int i, j, sub_partition_count[4], list, ref[2][4];
02060 
02061         if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
02062             for( i = 0; i < 4; i++ ) {
02063                 h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );
02064                 sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
02065                 h->sub_mb_type[i]=      b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
02066             }
02067             if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |
02068                           h->sub_mb_type[2] | h->sub_mb_type[3]) ) {
02069                 ff_h264_pred_direct_motion(h, &mb_type);
02070                 h->ref_cache[0][scan8[4]] =
02071                 h->ref_cache[1][scan8[4]] =
02072                 h->ref_cache[0][scan8[12]] =
02073                 h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
02074                     for( i = 0; i < 4; i++ )
02075                         fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );
02076             }
02077         } else {
02078             for( i = 0; i < 4; i++ ) {
02079                 h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );
02080                 sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
02081                 h->sub_mb_type[i]=      p_sub_mb_type_info[ h->sub_mb_type[i] ].type;
02082             }
02083         }
02084 
02085         for( list = 0; list < h->list_count; list++ ) {
02086                 for( i = 0; i < 4; i++ ) {
02087                     if(IS_DIRECT(h->sub_mb_type[i])) continue;
02088                     if(IS_DIR(h->sub_mb_type[i], 0, list)){
02089                         if( h->ref_count[list] > 1 ){
02090                             ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );
02091                             if(ref[list][i] >= (unsigned)h->ref_count[list]){
02092                                 av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], h->ref_count[list]);
02093                                 return -1;
02094                             }
02095                         }else
02096                             ref[list][i] = 0;
02097                     } else {
02098                         ref[list][i] = -1;
02099                     }
02100                                                        h->ref_cache[list][ scan8[4*i]+1 ]=
02101                     h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
02102                 }
02103         }
02104 
02105         if(dct8x8_allowed)
02106             dct8x8_allowed = get_dct8x8_allowed(h);
02107 
02108         for(list=0; list<h->list_count; list++){
02109             for(i=0; i<4; i++){
02110                 h->ref_cache[list][ scan8[4*i]   ]=h->ref_cache[list][ scan8[4*i]+1 ];
02111                 if(IS_DIRECT(h->sub_mb_type[i])){
02112                     fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);
02113                     continue;
02114                 }
02115 
02116                 if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){
02117                     const int sub_mb_type= h->sub_mb_type[i];
02118                     const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
02119                     for(j=0; j<sub_partition_count[i]; j++){
02120                         int mpx, mpy;
02121                         int mx, my;
02122                         const int index= 4*i + block_width*j;
02123                         int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
02124                         uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];
02125                         pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
02126                         DECODE_CABAC_MB_MVD( h, list, index)
02127                         tprintf(s->avctx, "final mv:%d %d\n", mx, my);
02128 
02129                         if(IS_SUB_8X8(sub_mb_type)){
02130                             mv_cache[ 1 ][0]=
02131                             mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
02132                             mv_cache[ 1 ][1]=
02133                             mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
02134 
02135                             mvd_cache[ 1 ][0]=
02136                             mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;
02137                             mvd_cache[ 1 ][1]=
02138                             mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;
02139                         }else if(IS_SUB_8X4(sub_mb_type)){
02140                             mv_cache[ 1 ][0]= mx;
02141                             mv_cache[ 1 ][1]= my;
02142 
02143                             mvd_cache[ 1 ][0]=  mpx;
02144                             mvd_cache[ 1 ][1]= mpy;
02145                         }else if(IS_SUB_4X8(sub_mb_type)){
02146                             mv_cache[ 8 ][0]= mx;
02147                             mv_cache[ 8 ][1]= my;
02148 
02149                             mvd_cache[ 8 ][0]= mpx;
02150                             mvd_cache[ 8 ][1]= mpy;
02151                         }
02152                         mv_cache[ 0 ][0]= mx;
02153                         mv_cache[ 0 ][1]= my;
02154 
02155                         mvd_cache[ 0 ][0]= mpx;
02156                         mvd_cache[ 0 ][1]= mpy;
02157                     }
02158                 }else{
02159                     fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);
02160                     fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);
02161                 }
02162             }
02163         }
02164     } else if( IS_DIRECT(mb_type) ) {
02165         ff_h264_pred_direct_motion(h, &mb_type);
02166         fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);
02167         fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);
02168         dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
02169     } else {
02170         int list, i;
02171         if(IS_16X16(mb_type)){
02172             for(list=0; list<h->list_count; list++){
02173                 if(IS_DIR(mb_type, 0, list)){
02174                     int ref;
02175                     if(h->ref_count[list] > 1){
02176                         ref= decode_cabac_mb_ref(h, list, 0);
02177                         if(ref >= (unsigned)h->ref_count[list]){
02178                             av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]);
02179                             return -1;
02180                         }
02181                     }else
02182                         ref=0;
02183                         fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);
02184                 }
02185             }
02186             for(list=0; list<h->list_count; list++){
02187                 if(IS_DIR(mb_type, 0, list)){
02188                     int mx,my,mpx,mpy;
02189                     pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
02190                     DECODE_CABAC_MB_MVD( h, list, 0)
02191                     tprintf(s->avctx, "final mv:%d %d\n", mx, my);
02192 
02193                     fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);
02194                     fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
02195                 }
02196             }
02197         }
02198         else if(IS_16X8(mb_type)){
02199             for(list=0; list<h->list_count; list++){
02200                     for(i=0; i<2; i++){
02201                         if(IS_DIR(mb_type, i, list)){
02202                             int ref;
02203                             if(h->ref_count[list] > 1){
02204                                 ref= decode_cabac_mb_ref( h, list, 8*i );
02205                                 if(ref >= (unsigned)h->ref_count[list]){
02206                                     av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]);
02207                                     return -1;
02208                                 }
02209                             }else
02210                                 ref=0;
02211                             fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);
02212                         }else
02213                             fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);
02214                     }
02215             }
02216             for(list=0; list<h->list_count; list++){
02217                 for(i=0; i<2; i++){
02218                     if(IS_DIR(mb_type, i, list)){
02219                         int mx,my,mpx,mpy;
02220                         pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
02221                         DECODE_CABAC_MB_MVD( h, list, 8*i)
02222                         tprintf(s->avctx, "final mv:%d %d\n", mx, my);
02223 
02224                         fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);
02225                         fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
02226                     }else{
02227                         fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);
02228                         fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
02229                     }
02230                 }
02231             }
02232         }else{
02233             assert(IS_8X16(mb_type));
02234             for(list=0; list<h->list_count; list++){
02235                     for(i=0; i<2; i++){
02236                         if(IS_DIR(mb_type, i, list)){ //FIXME optimize
02237                             int ref;
02238                             if(h->ref_count[list] > 1){
02239                                 ref= decode_cabac_mb_ref( h, list, 4*i );
02240                                 if(ref >= (unsigned)h->ref_count[list]){
02241                                     av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]);
02242                                     return -1;
02243                                 }
02244                             }else
02245                                 ref=0;
02246                             fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);
02247                         }else
02248                             fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);
02249                     }
02250             }
02251             for(list=0; list<h->list_count; list++){
02252                 for(i=0; i<2; i++){
02253                     if(IS_DIR(mb_type, i, list)){
02254                         int mx,my,mpx,mpy;
02255                         pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
02256                         DECODE_CABAC_MB_MVD( h, list, 4*i)
02257 
02258                         tprintf(s->avctx, "final mv:%d %d\n", mx, my);
02259                         fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);
02260                         fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
02261                     }else{
02262                         fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);
02263                         fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
02264                     }
02265                 }
02266             }
02267         }
02268     }
02269 
02270    if( IS_INTER( mb_type ) ) {
02271         h->chroma_pred_mode_table[mb_xy] = 0;
02272         write_back_motion( h, mb_type );
02273    }
02274 
02275     if( !IS_INTRA16x16( mb_type ) ) {
02276         cbp  = decode_cabac_mb_cbp_luma( h );
02277         if(decode_chroma)
02278             cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;
02279     }
02280 
02281     h->cbp_table[mb_xy] = h->cbp = cbp;
02282 
02283     if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {
02284         mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );
02285     }
02286 
02287     /* It would be better to do this in fill_decode_caches, but we don't know
02288      * the transform mode of the current macroblock there. */
02289     if (CHROMA444 && IS_8x8DCT(mb_type)){
02290         int i;
02291         uint8_t *nnz_cache = h->non_zero_count_cache;
02292         for (i = 0; i < 2; i++){
02293             if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){
02294                 nnz_cache[3+8* 1 + 2*8*i]=
02295                 nnz_cache[3+8* 2 + 2*8*i]=
02296                 nnz_cache[3+8* 6 + 2*8*i]=
02297                 nnz_cache[3+8* 7 + 2*8*i]=
02298                 nnz_cache[3+8*11 + 2*8*i]=
02299                 nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;
02300             }
02301         }
02302         if (h->top_type && !IS_8x8DCT(h->top_type)){
02303             uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
02304             AV_WN32A(&nnz_cache[4+8* 0], top_empty);
02305             AV_WN32A(&nnz_cache[4+8* 5], top_empty);
02306             AV_WN32A(&nnz_cache[4+8*10], top_empty);
02307         }
02308     }
02309     s->current_picture.f.mb_type[mb_xy] = mb_type;
02310 
02311     if( cbp || IS_INTRA16x16( mb_type ) ) {
02312         const uint8_t *scan, *scan8x8;
02313         const uint32_t *qmul;
02314 
02315         if(IS_INTERLACED(mb_type)){
02316             scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;
02317             scan= s->qscale ? h->field_scan : h->field_scan_q0;
02318         }else{
02319             scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;
02320             scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
02321         }
02322 
02323         // decode_cabac_mb_dqp
02324         if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){
02325             int val = 1;
02326             int ctx= 2;
02327             const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
02328 
02329             while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
02330                 ctx= 3;
02331                 val++;
02332                 if(val > 2*max_qp){ //prevent infinite loop
02333                     av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y);
02334                     return -1;
02335                 }
02336             }
02337 
02338             if( val&0x01 )
02339                 val=   (val + 1)>>1 ;
02340             else
02341                 val= -((val + 1)>>1);
02342             h->last_qscale_diff = val;
02343             s->qscale += val;
02344             if(((unsigned)s->qscale) > max_qp){
02345                 if(s->qscale<0) s->qscale+= max_qp+1;
02346                 else            s->qscale-= max_qp+1;
02347             }
02348             h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
02349             h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
02350         }else
02351             h->last_qscale_diff=0;
02352 
02353         decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);
02354         if(CHROMA444){
02355             decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);
02356             decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);
02357         } else if (CHROMA422) {
02358             if( cbp&0x30 ){
02359                 int c;
02360                 for( c = 0; c < 2; c++ ) {
02361                     //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
02362                     decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3,
02363                                                  CHROMA_DC_BLOCK_INDEX + c,
02364                                                  chroma422_dc_scan, 8);
02365                 }
02366             }
02367 
02368             if( cbp&0x20 ) {
02369                 int c, i, i8x8;
02370                 for( c = 0; c < 2; c++ ) {
02371                     DCTELEM *mb = h->mb + (16*(16 + 16*c) << pixel_shift);
02372                     qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
02373                     for (i8x8 = 0; i8x8 < 2; i8x8++) {
02374                         for (i = 0; i < 4; i++) {
02375                             const int index = 16 + 16 * c + 8*i8x8 + i;
02376                             //av_log(s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16);
02377                             decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15);
02378                             mb += 16<<pixel_shift;
02379                         }
02380                     }
02381                 }
02382             } else {
02383                 fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
02384                 fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
02385             }
02386         } else /* yuv420 */ {
02387             if( cbp&0x30 ){
02388                 int c;
02389                 for( c = 0; c < 2; c++ ) {
02390                     //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
02391                     decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);
02392                 }
02393             }
02394 
02395             if( cbp&0x20 ) {
02396                 int c, i;
02397                 for( c = 0; c < 2; c++ ) {
02398                     qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
02399                     for( i = 0; i < 4; i++ ) {
02400                         const int index = 16 + 16 * c + i;
02401                         //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 );
02402                         decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);
02403                     }
02404                 }
02405             } else {
02406                 fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
02407                 fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
02408             }
02409         }
02410     } else {
02411         fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);
02412         fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
02413         fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
02414         h->last_qscale_diff = 0;
02415     }
02416 
02417     s->current_picture.f.qscale_table[mb_xy] = s->qscale;
02418     write_back_non_zero_count(h);
02419 
02420     if(MB_MBAFF){
02421         h->ref_count[0] >>= 1;
02422         h->ref_count[1] >>= 1;
02423     }
02424 
02425     return 0;
02426 }