You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2424 lines
112KB

  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... cabac decoding
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * H.264 / AVC / MPEG4 part10 cabac decoding.
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #define CABAC 1
  27. #include "internal.h"
  28. #include "dsputil.h"
  29. #include "avcodec.h"
  30. #include "h264.h"
  31. #include "h264data.h"
  32. #include "h264_mvpred.h"
  33. #include "golomb.h"
  34. #include "cabac.h"
  35. #if ARCH_X86
  36. #include "x86/h264_i386.h"
  37. #endif
  38. //#undef NDEBUG
  39. #include <assert.h>
  40. /* Cabac pre state table */
  41. static const int8_t cabac_context_init_I[1024][2] =
  42. {
  43. /* 0 - 10 */
  44. { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
  45. { 2, 54 }, { 3, 74 }, { -28,127 }, { -23, 104 },
  46. { -6, 53 }, { -1, 54 }, { 7, 51 },
  47. /* 11 - 23 unsused for I */
  48. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  49. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  50. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  51. { 0, 0 },
  52. /* 24- 39 */
  53. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  54. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  55. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  56. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  57. /* 40 - 53 */
  58. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  59. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  60. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  61. { 0, 0 }, { 0, 0 },
  62. /* 54 - 59 */
  63. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
  64. { 0, 0 }, { 0, 0 },
  65. /* 60 - 69 */
  66. { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
  67. { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
  68. { 13, 41 }, { 3, 62 },
  69. /* 70 -> 87 */
  70. { 0, 11 }, { 1, 55 }, { 0, 69 }, { -17, 127 },
  71. { -13, 102 },{ 0, 82 }, { -7, 74 }, { -21, 107 },
  72. { -27, 127 },{ -31, 127 },{ -24, 127 }, { -18, 95 },
  73. { -27, 127 },{ -21, 114 },{ -30, 127 }, { -17, 123 },
  74. { -12, 115 },{ -16, 122 },
  75. /* 88 -> 104 */
  76. { -11, 115 },{ -12, 63 }, { -2, 68 }, { -15, 84 },
  77. { -13, 104 },{ -3, 70 }, { -8, 93 }, { -10, 90 },
  78. { -30, 127 },{ -1, 74 }, { -6, 97 }, { -7, 91 },
  79. { -20, 127 },{ -4, 56 }, { -5, 82 }, { -7, 76 },
  80. { -22, 125 },
  81. /* 105 -> 135 */
  82. { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
  83. { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
  84. { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
  85. { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
  86. { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
  87. { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
  88. { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
  89. { 14, 62 }, { -13, 108 },{ -15, 100 },
  90. /* 136 -> 165 */
  91. { -13, 101 },{ -13, 91 }, { -12, 94 }, { -10, 88 },
  92. { -16, 84 }, { -10, 86 }, { -7, 83 }, { -13, 87 },
  93. { -19, 94 }, { 1, 70 }, { 0, 72 }, { -5, 74 },
  94. { 18, 59 }, { -8, 102 }, { -15, 100 }, { 0, 95 },
  95. { -4, 75 }, { 2, 72 }, { -11, 75 }, { -3, 71 },
  96. { 15, 46 }, { -13, 69 }, { 0, 62 }, { 0, 65 },
  97. { 21, 37 }, { -15, 72 }, { 9, 57 }, { 16, 54 },
  98. { 0, 62 }, { 12, 72 },
  99. /* 166 -> 196 */
  100. { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
  101. { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
  102. { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
  103. { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
  104. { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
  105. { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
  106. { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
  107. { 0, 89 }, { 26, -19 }, { 22, -17 },
  108. /* 197 -> 226 */
  109. { 26, -17 }, { 30, -25 }, { 28, -20 }, { 33, -23 },
  110. { 37, -27 }, { 33, -23 }, { 40, -28 }, { 38, -17 },
  111. { 33, -11 }, { 40, -15 }, { 41, -6 }, { 38, 1 },
  112. { 41, 17 }, { 30, -6 }, { 27, 3 }, { 26, 22 },
  113. { 37, -16 }, { 35, -4 }, { 38, -8 }, { 38, -3 },
  114. { 37, 3 }, { 38, 5 }, { 42, 0 }, { 35, 16 },
  115. { 39, 22 }, { 14, 48 }, { 27, 37 }, { 21, 60 },
  116. { 12, 68 }, { 2, 97 },
  117. /* 227 -> 251 */
  118. { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 },
  119. { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 },
  120. { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 },
  121. { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 },
  122. { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 },
  123. { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 },
  124. { -4, 65 },
  125. /* 252 -> 275 */
  126. { -12, 73 }, { -8, 76 }, { -7, 80 }, { -9, 88 },
  127. { -17, 110 },{ -11, 97 }, { -20, 84 }, { -11, 79 },
  128. { -6, 73 }, { -4, 74 }, { -13, 86 }, { -13, 96 },
  129. { -11, 97 }, { -19, 117 },{ -8, 78 }, { -5, 33 },
  130. { -4, 48 }, { -2, 53 }, { -3, 62 }, { -13, 71 },
  131. { -10, 79 }, { -12, 86 }, { -13, 90 }, { -14, 97 },
  132. /* 276 a bit special (not used, bypass is used instead) */
  133. { 0, 0 },
  134. /* 277 -> 307 */
  135. { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
  136. { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
  137. { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
  138. { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
  139. { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
  140. { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
  141. { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
  142. { 9, 64 }, { -12, 104 },{ -11, 97 },
  143. /* 308 -> 337 */
  144. { -16, 96 }, { -7, 88 }, { -8, 85 }, { -7, 85 },
  145. { -9, 85 }, { -13, 88 }, { 4, 66 }, { -3, 77 },
  146. { -3, 76 }, { -6, 76 }, { 10, 58 }, { -1, 76 },
  147. { -1, 83 }, { -7, 99 }, { -14, 95 }, { 2, 95 },
  148. { 0, 76 }, { -5, 74 }, { 0, 70 }, { -11, 75 },
  149. { 1, 68 }, { 0, 65 }, { -14, 73 }, { 3, 62 },
  150. { 4, 62 }, { -1, 68 }, { -13, 75 }, { 11, 55 },
  151. { 5, 64 }, { 12, 70 },
  152. /* 338 -> 368 */
  153. { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
  154. { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
  155. { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
  156. { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
  157. { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
  158. { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
  159. { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
  160. { -12, 109 },{ 36, -35 }, { 36, -34 },
  161. /* 369 -> 398 */
  162. { 32, -26 }, { 37, -30 }, { 44, -32 }, { 34, -18 },
  163. { 34, -15 }, { 40, -15 }, { 33, -7 }, { 35, -5 },
  164. { 33, 0 }, { 38, 2 }, { 33, 13 }, { 23, 35 },
  165. { 13, 58 }, { 29, -3 }, { 26, 0 }, { 22, 30 },
  166. { 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 },
  167. { 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 },
  168. { 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 },
  169. { 29, 39 }, { 19, 66 },
  170. /* 399 -> 435 */
  171. { 31, 21 }, { 31, 31 }, { 25, 50 },
  172. { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 },
  173. { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 },
  174. { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 },
  175. { -23, 68 }, { -24, 50 }, { -11, 74 }, { 23, -13 },
  176. { 26, -13 }, { 40, -15 }, { 49, -14 }, { 44, 3 },
  177. { 45, 6 }, { 44, 34 }, { 33, 54 }, { 19, 82 },
  178. { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 },
  179. { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 },
  180. { 0, 68 }, { -9, 92 },
  181. /* 436 -> 459 */
  182. { -14, 106 }, { -13, 97 }, { -15, 90 }, { -12, 90 },
  183. { -18, 88 }, { -10, 73 }, { -9, 79 }, { -14, 86 },
  184. { -10, 73 }, { -10, 70 }, { -10, 69 }, { -5, 66 },
  185. { -9, 64 }, { -5, 58 }, { 2, 59 }, { 21, -10 },
  186. { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 },
  187. { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 },
  188. /* 460 -> 1024 */
  189. { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 },
  190. { -12, 63 }, { -2, 68 }, { -15, 84 }, { -13, 104 },
  191. { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
  192. { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 },
  193. { -12, 63 }, { -2, 68 }, { -15, 84 }, { -13, 104 },
  194. { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
  195. { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
  196. { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
  197. { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
  198. { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
  199. { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
  200. { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
  201. { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
  202. { 14, 62 }, { -13, 108 }, { -15, 100 }, { -13, 101 },
  203. { -13, 91 }, { -12, 94 }, { -10, 88 }, { -16, 84 },
  204. { -10, 86 }, { -7, 83 }, { -13, 87 }, { -19, 94 },
  205. { 1, 70 }, { 0, 72 }, { -5, 74 }, { 18, 59 },
  206. { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 },
  207. { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 },
  208. { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 },
  209. { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 },
  210. { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 },
  211. { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 },
  212. { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 },
  213. { 14, 62 }, { -13, 108 }, { -15, 100 }, { -13, 101 },
  214. { -13, 91 }, { -12, 94 }, { -10, 88 }, { -16, 84 },
  215. { -10, 86 }, { -7, 83 }, { -13, 87 }, { -19, 94 },
  216. { 1, 70 }, { 0, 72 }, { -5, 74 }, { 18, 59 },
  217. { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
  218. { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
  219. { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
  220. { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
  221. { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
  222. { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
  223. { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
  224. { 0, 89 }, { 26, -19 }, { 22, -17 }, { 26, -17 },
  225. { 30, -25 }, { 28, -20 }, { 33, -23 }, { 37, -27 },
  226. { 33, -23 }, { 40, -28 }, { 38, -17 }, { 33, -11 },
  227. { 40, -15 }, { 41, -6 }, { 38, 1 }, { 41, 17 },
  228. { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 },
  229. { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 },
  230. { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 },
  231. { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 },
  232. { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 },
  233. { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 },
  234. { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 },
  235. { 0, 89 }, { 26, -19 }, { 22, -17 }, { 26, -17 },
  236. { 30, -25 }, { 28, -20 }, { 33, -23 }, { 37, -27 },
  237. { 33, -23 }, { 40, -28 }, { 38, -17 }, { 33, -11 },
  238. { 40, -15 }, { 41, -6 }, { 38, 1 }, { 41, 17 },
  239. { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 },
  240. { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 },
  241. { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 },
  242. { -23, 68 }, { -24, 50 }, { -11, 74 }, { -14, 106 },
  243. { -13, 97 }, { -15, 90 }, { -12, 90 }, { -18, 88 },
  244. { -10, 73 }, { -9, 79 }, { -14, 86 }, { -10, 73 },
  245. { -10, 70 }, { -10, 69 }, { -5, 66 }, { -9, 64 },
  246. { -5, 58 }, { 2, 59 }, { 23, -13 }, { 26, -13 },
  247. { 40, -15 }, { 49, -14 }, { 44, 3 }, { 45, 6 },
  248. { 44, 34 }, { 33, 54 }, { 19, 82 }, { 21, -10 },
  249. { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 },
  250. { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 },
  251. { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 },
  252. { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 },
  253. { 0, 68 }, { -9, 92 }, { -17, 120 }, { -20, 112 },
  254. { -18, 114 }, { -11, 85 }, { -15, 92 }, { -14, 89 },
  255. { -26, 71 }, { -15, 81 }, { -14, 80 }, { 0, 68 },
  256. { -14, 70 }, { -24, 56 }, { -23, 68 }, { -24, 50 },
  257. { -11, 74 }, { -14, 106 }, { -13, 97 }, { -15, 90 },
  258. { -12, 90 }, { -18, 88 }, { -10, 73 }, { -9, 79 },
  259. { -14, 86 }, { -10, 73 }, { -10, 70 }, { -10, 69 },
  260. { -5, 66 }, { -9, 64 }, { -5, 58 }, { 2, 59 },
  261. { 23, -13 }, { 26, -13 }, { 40, -15 }, { 49, -14 },
  262. { 44, 3 }, { 45, 6 }, { 44, 34 }, { 33, 54 },
  263. { 19, 82 }, { 21, -10 }, { 24, -11 }, { 28, -8 },
  264. { 28, -1 }, { 29, 3 }, { 29, 9 }, { 35, 20 },
  265. { 29, 36 }, { 14, 67 }, { -3, 75 }, { -1, 23 },
  266. { 1, 34 }, { 1, 43 }, { 0, 54 }, { -2, 55 },
  267. { 0, 61 }, { 1, 64 }, { 0, 68 }, { -9, 92 },
  268. { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
  269. { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
  270. { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
  271. { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
  272. { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
  273. { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
  274. { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
  275. { 9, 64 }, { -12, 104 }, { -11, 97 }, { -16, 96 },
  276. { -7, 88 }, { -8, 85 }, { -7, 85 }, { -9, 85 },
  277. { -13, 88 }, { 4, 66 }, { -3, 77 }, { -3, 76 },
  278. { -6, 76 }, { 10, 58 }, { -1, 76 }, { -1, 83 },
  279. { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 },
  280. { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 },
  281. { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 },
  282. { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 },
  283. { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 },
  284. { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 },
  285. { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 },
  286. { 9, 64 }, { -12, 104 }, { -11, 97 }, { -16, 96 },
  287. { -7, 88 }, { -8, 85 }, { -7, 85 }, { -9, 85 },
  288. { -13, 88 }, { 4, 66 }, { -3, 77 }, { -3, 76 },
  289. { -6, 76 }, { 10, 58 }, { -1, 76 }, { -1, 83 },
  290. { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
  291. { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
  292. { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
  293. { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
  294. { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
  295. { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
  296. { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
  297. { -12, 109 }, { 36, -35 }, { 36, -34 }, { 32, -26 },
  298. { 37, -30 }, { 44, -32 }, { 34, -18 }, { 34, -15 },
  299. { 40, -15 }, { 33, -7 }, { 35, -5 }, { 33, 0 },
  300. { 38, 2 }, { 33, 13 }, { 23, 35 }, { 13, 58 },
  301. { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 },
  302. { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 },
  303. { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 },
  304. { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 },
  305. { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 },
  306. { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 },
  307. { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 },
  308. { -12, 109 }, { 36, -35 }, { 36, -34 }, { 32, -26 },
  309. { 37, -30 }, { 44, -32 }, { 34, -18 }, { 34, -15 },
  310. { 40, -15 }, { 33, -7 }, { 35, -5 }, { 33, 0 },
  311. { 38, 2 }, { 33, 13 }, { 23, 35 }, { 13, 58 },
  312. { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 },
  313. { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 },
  314. { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 },
  315. { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 },
  316. { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 },
  317. { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 },
  318. { -4, 65 }, { -12, 73 }, { -8, 76 }, { -7, 80 },
  319. { -9, 88 }, { -17, 110 }, { -3, 71 }, { -6, 42 },
  320. { -5, 50 }, { -3, 54 }, { -2, 62 }, { 0, 58 },
  321. { 1, 63 }, { -2, 72 }, { -1, 74 }, { -9, 91 },
  322. { -5, 67 }, { -5, 27 }, { -3, 39 }, { -2, 44 },
  323. { 0, 46 }, { -16, 64 }, { -8, 68 }, { -10, 78 },
  324. { -6, 77 }, { -10, 86 }, { -12, 92 }, { -15, 55 },
  325. { -10, 60 }, { -6, 62 }, { -4, 65 }, { -12, 73 },
  326. { -8, 76 }, { -7, 80 }, { -9, 88 }, { -17, 110 },
  327. { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
  328. { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 },
  329. { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 }
  330. };
  331. static const int8_t cabac_context_init_PB[3][1024][2] =
  332. {
  333. /* i_cabac_init_idc == 0 */
  334. {
  335. /* 0 - 10 */
  336. { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
  337. { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
  338. { -6, 53 }, { -1, 54 }, { 7, 51 },
  339. /* 11 - 23 */
  340. { 23, 33 }, { 23, 2 }, { 21, 0 }, { 1, 9 },
  341. { 0, 49 }, { -37, 118 }, { 5, 57 }, { -13, 78 },
  342. { -11, 65 }, { 1, 62 }, { 12, 49 }, { -4, 73 },
  343. { 17, 50 },
  344. /* 24 - 39 */
  345. { 18, 64 }, { 9, 43 }, { 29, 0 }, { 26, 67 },
  346. { 16, 90 }, { 9, 104 }, { -46, 127 }, { -20, 104 },
  347. { 1, 67 }, { -13, 78 }, { -11, 65 }, { 1, 62 },
  348. { -6, 86 }, { -17, 95 }, { -6, 61 }, { 9, 45 },
  349. /* 40 - 53 */
  350. { -3, 69 }, { -6, 81 }, { -11, 96 }, { 6, 55 },
  351. { 7, 67 }, { -5, 86 }, { 2, 88 }, { 0, 58 },
  352. { -3, 76 }, { -10, 94 }, { 5, 54 }, { 4, 69 },
  353. { -3, 81 }, { 0, 88 },
  354. /* 54 - 59 */
  355. { -7, 67 }, { -5, 74 }, { -4, 74 }, { -5, 80 },
  356. { -7, 72 }, { 1, 58 },
  357. /* 60 - 69 */
  358. { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
  359. { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
  360. { 13, 41 }, { 3, 62 },
  361. /* 70 - 87 */
  362. { 0, 45 }, { -4, 78 }, { -3, 96 }, { -27, 126 },
  363. { -28, 98 }, { -25, 101 }, { -23, 67 }, { -28, 82 },
  364. { -20, 94 }, { -16, 83 }, { -22, 110 }, { -21, 91 },
  365. { -18, 102 }, { -13, 93 }, { -29, 127 }, { -7, 92 },
  366. { -5, 89 }, { -7, 96 }, { -13, 108 }, { -3, 46 },
  367. { -1, 65 }, { -1, 57 }, { -9, 93 }, { -3, 74 },
  368. { -9, 92 }, { -8, 87 }, { -23, 126 }, { 5, 54 },
  369. { 6, 60 }, { 6, 59 }, { 6, 69 }, { -1, 48 },
  370. { 0, 68 }, { -4, 69 }, { -8, 88 },
  371. /* 105 -> 165 */
  372. { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
  373. { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
  374. { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
  375. { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
  376. { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
  377. { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
  378. { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
  379. { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
  380. { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
  381. { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
  382. { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
  383. { 3, 64 }, { 1, 61 }, { 9, 63 }, { 7, 50 },
  384. { 16, 39 }, { 5, 44 }, { 4, 52 }, { 11, 48 },
  385. { -5, 60 }, { -1, 59 }, { 0, 59 }, { 22, 33 },
  386. { 5, 44 }, { 14, 43 }, { -1, 78 }, { 0, 60 },
  387. { 9, 69 },
  388. /* 166 - 226 */
  389. { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
  390. { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
  391. { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
  392. { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
  393. { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
  394. { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
  395. { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
  396. { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
  397. { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
  398. { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
  399. { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
  400. { 1, 67 }, { 5, 59 }, { 9, 67 }, { 16, 30 },
  401. { 18, 32 }, { 18, 35 }, { 22, 29 }, { 24, 31 },
  402. { 23, 38 }, { 18, 43 }, { 20, 41 }, { 11, 63 },
  403. { 9, 59 }, { 9, 64 }, { -1, 94 }, { -2, 89 },
  404. { -9, 108 },
  405. /* 227 - 275 */
  406. { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 },
  407. { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 },
  408. { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 },
  409. { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 },
  410. { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 },
  411. { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 },
  412. { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 },
  413. { -3, 74 }, { -10, 90 }, { 0, 70 }, { -4, 29 },
  414. { 5, 31 }, { 7, 42 }, { 1, 59 }, { -2, 58 },
  415. { -3, 72 }, { -3, 81 }, { -11, 97 }, { 0, 58 },
  416. { 8, 5 }, { 10, 14 }, { 14, 18 }, { 13, 27 },
  417. { 2, 40 }, { 0, 58 }, { -3, 70 }, { -6, 79 },
  418. { -8, 85 },
  419. /* 276 a bit special (not used, bypass is used instead) */
  420. { 0, 0 },
  421. /* 277 - 337 */
  422. { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
  423. { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
  424. { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
  425. { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
  426. { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
  427. { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
  428. { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
  429. { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
  430. { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
  431. { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
  432. { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
  433. { -2, 69 }, { -2, 59 }, { 6, 70 }, { 10, 44 },
  434. { 9, 31 }, { 12, 43 }, { 3, 53 }, { 14, 34 },
  435. { 10, 38 }, { -3, 52 }, { 13, 40 }, { 17, 32 },
  436. { 7, 44 }, { 7, 38 }, { 13, 50 }, { 10, 57 },
  437. { 26, 43 },
  438. /* 338 - 398 */
  439. { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
  440. { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
  441. { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
  442. { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
  443. { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
  444. { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
  445. { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
  446. { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
  447. { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
  448. { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
  449. { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
  450. { 8, 60 }, { 6, 63 }, { 17, 65 }, { 21, 24 },
  451. { 23, 20 }, { 26, 23 }, { 27, 32 }, { 28, 23 },
  452. { 28, 24 }, { 23, 40 }, { 24, 32 }, { 28, 29 },
  453. { 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 },
  454. { 11, 86 },
  455. /* 399 - 435 */
  456. { 12, 40 }, { 11, 51 }, { 14, 59 },
  457. { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 },
  458. { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 },
  459. { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 },
  460. { -16, 66 }, { -22, 65 }, { -20, 63 }, { 9, -2 },
  461. { 26, -9 }, { 33, -9 }, { 39, -7 }, { 41, -2 },
  462. { 45, 3 }, { 49, 9 }, { 45, 27 }, { 36, 59 },
  463. { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 },
  464. { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 },
  465. { -8, 66 }, { -8, 76 },
  466. /* 436 - 459 */
  467. { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
  468. { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
  469. { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
  470. { -14, 66 }, { 0, 59 }, { 2, 59 }, { 21, -13 },
  471. { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 },
  472. { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 },
  473. /* 460 - 1024 */
  474. { -7, 92 }, { -5, 89 }, { -7, 96 }, { -13, 108 },
  475. { -3, 46 }, { -1, 65 }, { -1, 57 }, { -9, 93 },
  476. { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
  477. { -7, 92 }, { -5, 89 }, { -7, 96 }, { -13, 108 },
  478. { -3, 46 }, { -1, 65 }, { -1, 57 }, { -9, 93 },
  479. { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
  480. { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
  481. { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
  482. { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
  483. { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
  484. { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
  485. { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
  486. { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
  487. { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
  488. { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
  489. { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
  490. { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
  491. { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 },
  492. { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 },
  493. { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 },
  494. { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 },
  495. { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 },
  496. { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 },
  497. { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 },
  498. { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 },
  499. { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 },
  500. { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 },
  501. { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 },
  502. { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
  503. { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
  504. { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
  505. { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
  506. { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
  507. { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
  508. { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
  509. { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
  510. { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
  511. { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
  512. { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
  513. { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 },
  514. { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 },
  515. { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 },
  516. { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 },
  517. { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 },
  518. { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 },
  519. { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 },
  520. { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 },
  521. { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 },
  522. { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 },
  523. { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 },
  524. { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 },
  525. { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 },
  526. { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 },
  527. { -16, 66 }, { -22, 65 }, { -20, 63 }, { -5, 85 },
  528. { -6, 81 }, { -10, 77 }, { -7, 81 }, { -17, 80 },
  529. { -18, 73 }, { -4, 74 }, { -10, 83 }, { -9, 71 },
  530. { -9, 67 }, { -1, 61 }, { -8, 66 }, { -14, 66 },
  531. { 0, 59 }, { 2, 59 }, { 9, -2 }, { 26, -9 },
  532. { 33, -9 }, { 39, -7 }, { 41, -2 }, { 45, 3 },
  533. { 49, 9 }, { 45, 27 }, { 36, 59 }, { 21, -13 },
  534. { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 },
  535. { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 },
  536. { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 },
  537. { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 },
  538. { -8, 66 }, { -8, 76 }, { -4, 79 }, { -7, 71 },
  539. { -5, 69 }, { -9, 70 }, { -8, 66 }, { -10, 68 },
  540. { -19, 73 }, { -12, 69 }, { -16, 70 }, { -15, 67 },
  541. { -20, 62 }, { -19, 70 }, { -16, 66 }, { -22, 65 },
  542. { -20, 63 }, { -5, 85 }, { -6, 81 }, { -10, 77 },
  543. { -7, 81 }, { -17, 80 }, { -18, 73 }, { -4, 74 },
  544. { -10, 83 }, { -9, 71 }, { -9, 67 }, { -1, 61 },
  545. { -8, 66 }, { -14, 66 }, { 0, 59 }, { 2, 59 },
  546. { 9, -2 }, { 26, -9 }, { 33, -9 }, { 39, -7 },
  547. { 41, -2 }, { 45, 3 }, { 49, 9 }, { 45, 27 },
  548. { 36, 59 }, { 21, -13 }, { 33, -14 }, { 39, -7 },
  549. { 46, -2 }, { 51, 2 }, { 60, 6 }, { 61, 17 },
  550. { 55, 34 }, { 42, 62 }, { -6, 66 }, { -7, 35 },
  551. { -7, 42 }, { -8, 45 }, { -5, 48 }, { -12, 56 },
  552. { -6, 60 }, { -5, 62 }, { -8, 66 }, { -8, 76 },
  553. { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
  554. { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
  555. { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
  556. { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
  557. { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
  558. { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
  559. { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
  560. { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
  561. { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
  562. { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
  563. { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
  564. { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 },
  565. { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 },
  566. { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 },
  567. { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 },
  568. { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 },
  569. { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 },
  570. { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 },
  571. { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 },
  572. { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 },
  573. { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 },
  574. { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 },
  575. { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
  576. { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
  577. { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
  578. { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
  579. { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
  580. { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
  581. { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
  582. { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
  583. { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
  584. { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
  585. { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
  586. { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 },
  587. { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 },
  588. { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 },
  589. { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 },
  590. { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 },
  591. { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 },
  592. { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 },
  593. { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 },
  594. { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 },
  595. { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 },
  596. { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 },
  597. { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 },
  598. { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 },
  599. { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 },
  600. { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 },
  601. { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 },
  602. { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 },
  603. { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 },
  604. { -3, 74 }, { -10, 90 }, { -6, 76 }, { -2, 44 },
  605. { 0, 45 }, { 0, 52 }, { -3, 64 }, { -2, 59 },
  606. { -4, 70 }, { -4, 75 }, { -8, 82 }, { -17, 102 },
  607. { -9, 77 }, { 3, 24 }, { 0, 42 }, { 0, 48 },
  608. { 0, 55 }, { -6, 59 }, { -7, 71 }, { -12, 83 },
  609. { -11, 87 }, { -30, 119 }, { 1, 58 }, { -3, 29 },
  610. { -1, 36 }, { 1, 38 }, { 2, 43 }, { -6, 55 },
  611. { 0, 58 }, { 0, 64 }, { -3, 74 }, { -10, 90 },
  612. { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
  613. { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 },
  614. { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 }
  615. },
  616. /* i_cabac_init_idc == 1 */
  617. {
  618. /* 0 - 10 */
  619. { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
  620. { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
  621. { -6, 53 }, { -1, 54 }, { 7, 51 },
  622. /* 11 - 23 */
  623. { 22, 25 }, { 34, 0 }, { 16, 0 }, { -2, 9 },
  624. { 4, 41 }, { -29, 118 }, { 2, 65 }, { -6, 71 },
  625. { -13, 79 }, { 5, 52 }, { 9, 50 }, { -3, 70 },
  626. { 10, 54 },
  627. /* 24 - 39 */
  628. { 26, 34 }, { 19, 22 }, { 40, 0 }, { 57, 2 },
  629. { 41, 36 }, { 26, 69 }, { -45, 127 }, { -15, 101 },
  630. { -4, 76 }, { -6, 71 }, { -13, 79 }, { 5, 52 },
  631. { 6, 69 }, { -13, 90 }, { 0, 52 }, { 8, 43 },
  632. /* 40 - 53 */
  633. { -2, 69 },{ -5, 82 },{ -10, 96 },{ 2, 59 },
  634. { 2, 75 },{ -3, 87 },{ -3, 100 },{ 1, 56 },
  635. { -3, 74 },{ -6, 85 },{ 0, 59 },{ -3, 81 },
  636. { -7, 86 },{ -5, 95 },
  637. /* 54 - 59 */
  638. { -1, 66 },{ -1, 77 },{ 1, 70 },{ -2, 86 },
  639. { -5, 72 },{ 0, 61 },
  640. /* 60 - 69 */
  641. { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
  642. { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
  643. { 13, 41 }, { 3, 62 },
  644. /* 70 - 104 */
  645. { 13, 15 }, { 7, 51 }, { 2, 80 }, { -39, 127 },
  646. { -18, 91 }, { -17, 96 }, { -26, 81 }, { -35, 98 },
  647. { -24, 102 }, { -23, 97 }, { -27, 119 }, { -24, 99 },
  648. { -21, 110 }, { -18, 102 }, { -36, 127 }, { 0, 80 },
  649. { -5, 89 }, { -7, 94 }, { -4, 92 }, { 0, 39 },
  650. { 0, 65 }, { -15, 84 }, { -35, 127 }, { -2, 73 },
  651. { -12, 104 }, { -9, 91 }, { -31, 127 }, { 3, 55 },
  652. { 7, 56 }, { 7, 55 }, { 8, 61 }, { -3, 53 },
  653. { 0, 68 }, { -7, 74 }, { -9, 88 },
  654. /* 105 -> 165 */
  655. { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
  656. { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
  657. { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
  658. { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
  659. { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
  660. { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
  661. { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
  662. { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
  663. { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
  664. { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
  665. { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
  666. { -4, 71 }, { 0, 58 }, { 7, 61 }, { 9, 41 },
  667. { 18, 25 }, { 9, 32 }, { 5, 43 }, { 9, 47 },
  668. { 0, 44 }, { 0, 51 }, { 2, 46 }, { 19, 38 },
  669. { -4, 66 }, { 15, 38 }, { 12, 42 }, { 9, 34 },
  670. { 0, 89 },
  671. /* 166 - 226 */
  672. { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
  673. { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
  674. { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
  675. { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
  676. { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
  677. { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
  678. { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
  679. { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
  680. { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
  681. { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
  682. { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
  683. { 0, 75 }, { 2, 72 }, { 8, 77 }, { 14, 35 },
  684. { 18, 31 }, { 17, 35 }, { 21, 30 }, { 17, 45 },
  685. { 20, 42 }, { 18, 45 }, { 27, 26 }, { 16, 54 },
  686. { 7, 66 }, { 16, 56 }, { 11, 73 }, { 10, 67 },
  687. { -10, 116 },
  688. /* 227 - 275 */
  689. { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 },
  690. { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 },
  691. { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 },
  692. { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 },
  693. { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
  694. { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 },
  695. { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 },
  696. { -5, 74 }, { -9, 86 }, { 2, 66 }, { -9, 34 },
  697. { 1, 32 }, { 11, 31 }, { 5, 52 }, { -2, 55 },
  698. { -2, 67 }, { 0, 73 }, { -8, 89 }, { 3, 52 },
  699. { 7, 4 }, { 10, 8 }, { 17, 8 }, { 16, 19 },
  700. { 3, 37 }, { -1, 61 }, { -5, 73 }, { -1, 70 },
  701. { -4, 78 },
  702. /* 276 a bit special (not used, bypass is used instead) */
  703. { 0, 0 },
  704. /* 277 - 337 */
  705. { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
  706. { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
  707. { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
  708. { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
  709. { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
  710. { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
  711. { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
  712. { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
  713. { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
  714. { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
  715. { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
  716. { -1, 70 }, { -9, 72 }, { 14, 60 }, { 16, 37 },
  717. { 0, 47 }, { 18, 35 }, { 11, 37 }, { 12, 41 },
  718. { 10, 41 }, { 2, 48 }, { 12, 41 }, { 13, 41 },
  719. { 0, 59 }, { 3, 50 }, { 19, 40 }, { 3, 66 },
  720. { 18, 50 },
  721. /* 338 - 398 */
  722. { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
  723. { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
  724. { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
  725. { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
  726. { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
  727. { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
  728. { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
  729. { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
  730. { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
  731. { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
  732. { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
  733. { 12, 48 }, { 11, 49 }, { 26, 45 }, { 22, 22 },
  734. { 23, 22 }, { 27, 21 }, { 33, 20 }, { 26, 28 },
  735. { 30, 24 }, { 27, 34 }, { 18, 42 }, { 25, 39 },
  736. { 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 },
  737. { 11, 83 },
  738. /* 399 - 435 */
  739. { 25, 32 }, { 21, 49 }, { 21, 54 },
  740. { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
  741. { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
  742. { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
  743. { -14, 66 }, { 0, 59 }, { 2, 59 }, { 17, -10 },
  744. { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
  745. { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
  746. { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 },
  747. { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 },
  748. { -4, 67 }, { -7, 82 },
  749. /* 436 - 459 */
  750. { -3, 81 }, { -3, 76 }, { -7, 72 }, { -6, 78 },
  751. { -12, 72 }, { -14, 68 }, { -3, 70 }, { -6, 76 },
  752. { -5, 66 }, { -5, 62 }, { 0, 57 }, { -4, 61 },
  753. { -9, 60 }, { 1, 54 }, { 2, 58 }, { 17, -10 },
  754. { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
  755. { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
  756. /* 460 - 1024 */
  757. { 0, 80 }, { -5, 89 }, { -7, 94 }, { -4, 92 },
  758. { 0, 39 }, { 0, 65 }, { -15, 84 }, { -35, 127 },
  759. { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
  760. { 0, 80 }, { -5, 89 }, { -7, 94 }, { -4, 92 },
  761. { 0, 39 }, { 0, 65 }, { -15, 84 }, { -35, 127 },
  762. { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
  763. { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
  764. { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
  765. { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
  766. { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
  767. { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
  768. { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
  769. { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
  770. { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
  771. { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
  772. { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
  773. { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
  774. { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 },
  775. { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 },
  776. { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 },
  777. { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 },
  778. { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 },
  779. { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 },
  780. { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 },
  781. { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 },
  782. { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 },
  783. { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 },
  784. { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 },
  785. { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
  786. { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
  787. { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
  788. { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
  789. { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
  790. { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
  791. { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
  792. { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
  793. { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
  794. { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
  795. { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
  796. { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 },
  797. { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 },
  798. { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 },
  799. { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 },
  800. { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 },
  801. { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 },
  802. { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 },
  803. { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 },
  804. { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 },
  805. { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 },
  806. { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 },
  807. { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
  808. { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
  809. { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
  810. { -14, 66 }, { 0, 59 }, { 2, 59 }, { -3, 81 },
  811. { -3, 76 }, { -7, 72 }, { -6, 78 }, { -12, 72 },
  812. { -14, 68 }, { -3, 70 }, { -6, 76 }, { -5, 66 },
  813. { -5, 62 }, { 0, 57 }, { -4, 61 }, { -9, 60 },
  814. { 1, 54 }, { 2, 58 }, { 17, -10 }, { 32, -13 },
  815. { 42, -9 }, { 49, -5 }, { 53, 0 }, { 64, 3 },
  816. { 68, 10 }, { 66, 27 }, { 47, 57 }, { 17, -10 },
  817. { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
  818. { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
  819. { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 },
  820. { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 },
  821. { -4, 67 }, { -7, 82 }, { -5, 85 }, { -6, 81 },
  822. { -10, 77 }, { -7, 81 }, { -17, 80 }, { -18, 73 },
  823. { -4, 74 }, { -10, 83 }, { -9, 71 }, { -9, 67 },
  824. { -1, 61 }, { -8, 66 }, { -14, 66 }, { 0, 59 },
  825. { 2, 59 }, { -3, 81 }, { -3, 76 }, { -7, 72 },
  826. { -6, 78 }, { -12, 72 }, { -14, 68 }, { -3, 70 },
  827. { -6, 76 }, { -5, 66 }, { -5, 62 }, { 0, 57 },
  828. { -4, 61 }, { -9, 60 }, { 1, 54 }, { 2, 58 },
  829. { 17, -10 }, { 32, -13 }, { 42, -9 }, { 49, -5 },
  830. { 53, 0 }, { 64, 3 }, { 68, 10 }, { 66, 27 },
  831. { 47, 57 }, { 17, -10 }, { 32, -13 }, { 42, -9 },
  832. { 49, -5 }, { 53, 0 }, { 64, 3 }, { 68, 10 },
  833. { 66, 27 }, { 47, 57 }, { -5, 71 }, { 0, 24 },
  834. { -1, 36 }, { -2, 42 }, { -2, 52 }, { -9, 57 },
  835. { -6, 63 }, { -4, 65 }, { -4, 67 }, { -7, 82 },
  836. { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
  837. { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
  838. { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
  839. { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
  840. { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
  841. { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
  842. { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
  843. { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
  844. { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
  845. { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
  846. { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
  847. { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 },
  848. { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 },
  849. { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 },
  850. { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 },
  851. { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 },
  852. { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 },
  853. { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 },
  854. { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 },
  855. { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 },
  856. { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 },
  857. { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 },
  858. { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
  859. { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
  860. { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
  861. { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
  862. { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
  863. { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
  864. { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
  865. { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
  866. { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
  867. { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
  868. { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
  869. { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 },
  870. { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 },
  871. { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 },
  872. { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 },
  873. { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 },
  874. { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 },
  875. { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 },
  876. { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 },
  877. { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 },
  878. { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 },
  879. { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 },
  880. { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 },
  881. { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 },
  882. { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 },
  883. { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 },
  884. { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 },
  885. { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 },
  886. { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 },
  887. { -5, 74 }, { -9, 86 }, { -23, 112 }, { -15, 71 },
  888. { -7, 61 }, { 0, 53 }, { -5, 66 }, { -11, 77 },
  889. { -9, 80 }, { -9, 84 }, { -10, 87 }, { -34, 127 },
  890. { -21, 101 }, { -3, 39 }, { -5, 53 }, { -7, 61 },
  891. { -11, 75 }, { -15, 77 }, { -17, 91 }, { -25, 107 },
  892. { -25, 111 }, { -28, 122 }, { -11, 76 }, { -10, 44 },
  893. { -10, 52 }, { -10, 57 }, { -9, 58 }, { -16, 72 },
  894. { -7, 69 }, { -4, 69 }, { -5, 74 }, { -9, 86 },
  895. { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
  896. { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 },
  897. { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 }
  898. },
  899. /* i_cabac_init_idc == 2 */
  900. {
  901. /* 0 - 10 */
  902. { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
  903. { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 },
  904. { -6, 53 }, { -1, 54 }, { 7, 51 },
  905. /* 11 - 23 */
  906. { 29, 16 }, { 25, 0 }, { 14, 0 }, { -10, 51 },
  907. { -3, 62 }, { -27, 99 }, { 26, 16 }, { -4, 85 },
  908. { -24, 102 }, { 5, 57 }, { 6, 57 }, { -17, 73 },
  909. { 14, 57 },
  910. /* 24 - 39 */
  911. { 20, 40 }, { 20, 10 }, { 29, 0 }, { 54, 0 },
  912. { 37, 42 }, { 12, 97 }, { -32, 127 }, { -22, 117 },
  913. { -2, 74 }, { -4, 85 }, { -24, 102 }, { 5, 57 },
  914. { -6, 93 }, { -14, 88 }, { -6, 44 }, { 4, 55 },
  915. /* 40 - 53 */
  916. { -11, 89 },{ -15, 103 },{ -21, 116 },{ 19, 57 },
  917. { 20, 58 },{ 4, 84 },{ 6, 96 },{ 1, 63 },
  918. { -5, 85 },{ -13, 106 },{ 5, 63 },{ 6, 75 },
  919. { -3, 90 },{ -1, 101 },
  920. /* 54 - 59 */
  921. { 3, 55 },{ -4, 79 },{ -2, 75 },{ -12, 97 },
  922. { -7, 50 },{ 1, 60 },
  923. /* 60 - 69 */
  924. { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 },
  925. { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 },
  926. { 13, 41 }, { 3, 62 },
  927. /* 70 - 104 */
  928. { 7, 34 }, { -9, 88 }, { -20, 127 }, { -36, 127 },
  929. { -17, 91 }, { -14, 95 }, { -25, 84 }, { -25, 86 },
  930. { -12, 89 }, { -17, 91 }, { -31, 127 }, { -14, 76 },
  931. { -18, 103 }, { -13, 90 }, { -37, 127 }, { 11, 80 },
  932. { 5, 76 }, { 2, 84 }, { 5, 78 }, { -6, 55 },
  933. { 4, 61 }, { -14, 83 }, { -37, 127 }, { -5, 79 },
  934. { -11, 104 }, { -11, 91 }, { -30, 127 }, { 0, 65 },
  935. { -2, 79 }, { 0, 72 }, { -4, 92 }, { -6, 56 },
  936. { 3, 68 }, { -8, 71 }, { -13, 98 },
  937. /* 105 -> 165 */
  938. { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
  939. { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
  940. { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
  941. { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
  942. { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
  943. { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
  944. { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
  945. { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
  946. { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
  947. { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
  948. { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
  949. { 3, 65 }, { -7, 69 }, { 8, 77 }, { -10, 66 },
  950. { 3, 62 }, { -3, 68 }, { -20, 81 }, { 0, 30 },
  951. { 1, 7 }, { -3, 23 }, { -21, 74 }, { 16, 66 },
  952. { -23, 124 }, { 17, 37 }, { 44, -18 }, { 50, -34 },
  953. { -22, 127 },
  954. /* 166 - 226 */
  955. { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
  956. { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
  957. { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
  958. { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
  959. { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
  960. { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
  961. { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
  962. { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
  963. { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
  964. { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
  965. { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
  966. { 20, 34 }, { 19, 31 }, { 27, 44 }, { 19, 16 },
  967. { 15, 36 }, { 15, 36 }, { 21, 28 }, { 25, 21 },
  968. { 30, 20 }, { 31, 12 }, { 27, 16 }, { 24, 42 },
  969. { 0, 93 }, { 14, 56 }, { 15, 57 }, { 26, 38 },
  970. { -24, 127 },
  971. /* 227 - 275 */
  972. { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 },
  973. { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 },
  974. { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 },
  975. { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 },
  976. { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 },
  977. { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 },
  978. { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 },
  979. { -12, 92 }, { -18, 108 }, { -4, 79 }, { -22, 69 },
  980. { -16, 75 }, { -2, 58 }, { 1, 58 }, { -13, 78 },
  981. { -9, 83 }, { -4, 81 }, { -13, 99 }, { -13, 81 },
  982. { -6, 38 }, { -13, 62 }, { -6, 58 }, { -2, 59 },
  983. { -16, 73 }, { -10, 76 }, { -13, 86 }, { -9, 83 },
  984. { -10, 87 },
  985. /* 276 a bit special (not used, bypass is used instead) */
  986. { 0, 0 },
  987. /* 277 - 337 */
  988. { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
  989. { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
  990. { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
  991. { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
  992. { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
  993. { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
  994. { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
  995. { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
  996. { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
  997. { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
  998. { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
  999. { -2, 76 }, { -18, 86 }, { 12, 70 }, { 5, 64 },
  1000. { -12, 70 }, { 11, 55 }, { 5, 56 }, { 0, 69 },
  1001. { 2, 65 }, { -6, 74 }, { 5, 54 }, { 7, 54 },
  1002. { -6, 76 }, { -11, 82 }, { -2, 77 }, { -2, 77 },
  1003. { 25, 42 },
  1004. /* 338 - 398 */
  1005. { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
  1006. { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
  1007. { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
  1008. { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
  1009. { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
  1010. { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
  1011. { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
  1012. { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
  1013. { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
  1014. { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
  1015. { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
  1016. { 18, 31 }, { 19, 26 }, { 36, 24 }, { 24, 23 },
  1017. { 27, 16 }, { 24, 30 }, { 31, 29 }, { 22, 41 },
  1018. { 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 },
  1019. { 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 },
  1020. { 25, 61 },
  1021. /* 399 - 435 */
  1022. { 21, 33 }, { 19, 50 }, { 17, 61 },
  1023. { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
  1024. { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
  1025. { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
  1026. { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 },
  1027. { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
  1028. { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
  1029. { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 },
  1030. { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 },
  1031. { -6, 68 }, { -10, 79 },
  1032. /* 436 - 459 */
  1033. { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
  1034. { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
  1035. { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
  1036. { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 },
  1037. { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
  1038. { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
  1039. /* 460 - 1024 */
  1040. { 11, 80 }, { 5, 76 }, { 2, 84 }, { 5, 78 },
  1041. { -6, 55 }, { 4, 61 }, { -14, 83 }, { -37, 127 },
  1042. { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
  1043. { 11, 80 }, { 5, 76 }, { 2, 84 }, { 5, 78 },
  1044. { -6, 55 }, { 4, 61 }, { -14, 83 }, { -37, 127 },
  1045. { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
  1046. { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
  1047. { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
  1048. { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
  1049. { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
  1050. { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
  1051. { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
  1052. { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
  1053. { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
  1054. { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
  1055. { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
  1056. { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
  1057. { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 },
  1058. { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 },
  1059. { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 },
  1060. { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 },
  1061. { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 },
  1062. { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 },
  1063. { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 },
  1064. { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 },
  1065. { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 },
  1066. { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 },
  1067. { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 },
  1068. { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
  1069. { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
  1070. { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
  1071. { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
  1072. { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
  1073. { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
  1074. { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
  1075. { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
  1076. { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
  1077. { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
  1078. { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
  1079. { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 },
  1080. { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 },
  1081. { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 },
  1082. { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 },
  1083. { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 },
  1084. { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 },
  1085. { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 },
  1086. { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 },
  1087. { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 },
  1088. { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 },
  1089. { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 },
  1090. { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
  1091. { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
  1092. { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
  1093. { -14, 59 }, { -9, 52 }, { -11, 68 }, { -3, 78 },
  1094. { -8, 74 }, { -9, 72 }, { -10, 72 }, { -18, 75 },
  1095. { -12, 71 }, { -11, 63 }, { -5, 70 }, { -17, 75 },
  1096. { -14, 72 }, { -16, 67 }, { -8, 53 }, { -14, 59 },
  1097. { -9, 52 }, { -11, 68 }, { 9, -2 }, { 30, -10 },
  1098. { 31, -4 }, { 33, -1 }, { 33, 7 }, { 31, 12 },
  1099. { 37, 23 }, { 31, 38 }, { 20, 64 }, { 9, -2 },
  1100. { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
  1101. { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
  1102. { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 },
  1103. { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 },
  1104. { -6, 68 }, { -10, 79 }, { -3, 78 }, { -8, 74 },
  1105. { -9, 72 }, { -10, 72 }, { -18, 75 }, { -12, 71 },
  1106. { -11, 63 }, { -5, 70 }, { -17, 75 }, { -14, 72 },
  1107. { -16, 67 }, { -8, 53 }, { -14, 59 }, { -9, 52 },
  1108. { -11, 68 }, { -3, 78 }, { -8, 74 }, { -9, 72 },
  1109. { -10, 72 }, { -18, 75 }, { -12, 71 }, { -11, 63 },
  1110. { -5, 70 }, { -17, 75 }, { -14, 72 }, { -16, 67 },
  1111. { -8, 53 }, { -14, 59 }, { -9, 52 }, { -11, 68 },
  1112. { 9, -2 }, { 30, -10 }, { 31, -4 }, { 33, -1 },
  1113. { 33, 7 }, { 31, 12 }, { 37, 23 }, { 31, 38 },
  1114. { 20, 64 }, { 9, -2 }, { 30, -10 }, { 31, -4 },
  1115. { 33, -1 }, { 33, 7 }, { 31, 12 }, { 37, 23 },
  1116. { 31, 38 }, { 20, 64 }, { -9, 71 }, { -7, 37 },
  1117. { -8, 44 }, { -11, 49 }, { -10, 56 }, { -12, 59 },
  1118. { -8, 63 }, { -9, 67 }, { -6, 68 }, { -10, 79 },
  1119. { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
  1120. { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
  1121. { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
  1122. { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
  1123. { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
  1124. { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
  1125. { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
  1126. { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
  1127. { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
  1128. { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
  1129. { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
  1130. { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 },
  1131. { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 },
  1132. { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 },
  1133. { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 },
  1134. { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 },
  1135. { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 },
  1136. { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 },
  1137. { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 },
  1138. { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 },
  1139. { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 },
  1140. { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 },
  1141. { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
  1142. { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
  1143. { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
  1144. { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
  1145. { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
  1146. { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
  1147. { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
  1148. { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
  1149. { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
  1150. { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
  1151. { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
  1152. { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 },
  1153. { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 },
  1154. { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 },
  1155. { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 },
  1156. { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 },
  1157. { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 },
  1158. { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 },
  1159. { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 },
  1160. { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 },
  1161. { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 },
  1162. { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 },
  1163. { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 },
  1164. { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 },
  1165. { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 },
  1166. { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 },
  1167. { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 },
  1168. { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 },
  1169. { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 },
  1170. { -12, 92 }, { -18, 108 }, { -24, 115 }, { -22, 82 },
  1171. { -9, 62 }, { 0, 53 }, { 0, 59 }, { -14, 85 },
  1172. { -13, 89 }, { -13, 94 }, { -11, 92 }, { -29, 127 },
  1173. { -21, 100 }, { -14, 57 }, { -12, 67 }, { -11, 71 },
  1174. { -10, 77 }, { -21, 85 }, { -16, 88 }, { -23, 104 },
  1175. { -15, 98 }, { -37, 127 }, { -10, 82 }, { -8, 48 },
  1176. { -8, 61 }, { -8, 66 }, { -7, 70 }, { -14, 75 },
  1177. { -10, 79 }, { -9, 83 }, { -12, 92 }, { -18, 108 },
  1178. { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
  1179. { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 },
  1180. { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 }
  1181. }
  1182. };
  1183. void ff_h264_init_cabac_states(H264Context *h) {
  1184. MpegEncContext * const s = &h->s;
  1185. int i;
  1186. const int8_t (*tab)[2];
  1187. const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51);
  1188. if( h->slice_type_nos == AV_PICTURE_TYPE_I ) tab = cabac_context_init_I;
  1189. else tab = cabac_context_init_PB[h->cabac_init_idc];
  1190. /* calculate pre-state */
  1191. for( i= 0; i < 1024; i++ ) {
  1192. int pre = 2*(((tab[i][0] * slice_qp) >>4 ) + tab[i][1]) - 127;
  1193. pre^= pre>>31;
  1194. if(pre > 124)
  1195. pre= 124 + (pre&1);
  1196. h->cabac_state[i] = pre;
  1197. }
  1198. }
  1199. static int decode_cabac_field_decoding_flag(H264Context *h) {
  1200. MpegEncContext * const s = &h->s;
  1201. const long mbb_xy = h->mb_xy - 2L*s->mb_stride;
  1202. unsigned long ctx = 0;
  1203. 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);
  1204. ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
  1205. return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] );
  1206. }
  1207. static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) {
  1208. uint8_t *state= &h->cabac_state[ctx_base];
  1209. int mb_type;
  1210. if(intra_slice){
  1211. int ctx=0;
  1212. if( h->left_type[LTOP] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM))
  1213. ctx++;
  1214. if( h->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM))
  1215. ctx++;
  1216. if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 )
  1217. return 0; /* I4x4 */
  1218. state += 2;
  1219. }else{
  1220. if( get_cabac_noinline( &h->cabac, state ) == 0 )
  1221. return 0; /* I4x4 */
  1222. }
  1223. if( get_cabac_terminate( &h->cabac ) )
  1224. return 25; /* PCM */
  1225. mb_type = 1; /* I16x16 */
  1226. mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */
  1227. if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */
  1228. mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] );
  1229. mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] );
  1230. mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] );
  1231. return mb_type;
  1232. }
  1233. static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
  1234. MpegEncContext * const s = &h->s;
  1235. int mba_xy, mbb_xy;
  1236. int ctx = 0;
  1237. if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches?
  1238. int mb_xy = mb_x + (mb_y&~1)*s->mb_stride;
  1239. mba_xy = mb_xy - 1;
  1240. if( (mb_y&1)
  1241. && h->slice_table[mba_xy] == h->slice_num
  1242. && MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) )
  1243. mba_xy += s->mb_stride;
  1244. if( MB_FIELD ){
  1245. mbb_xy = mb_xy - s->mb_stride;
  1246. if( !(mb_y&1)
  1247. && h->slice_table[mbb_xy] == h->slice_num
  1248. && IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) )
  1249. mbb_xy -= s->mb_stride;
  1250. }else
  1251. mbb_xy = mb_x + (mb_y-1)*s->mb_stride;
  1252. }else{
  1253. int mb_xy = h->mb_xy;
  1254. mba_xy = mb_xy - 1;
  1255. mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE);
  1256. }
  1257. if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] ))
  1258. ctx++;
  1259. if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] ))
  1260. ctx++;
  1261. if( h->slice_type_nos == AV_PICTURE_TYPE_B )
  1262. ctx += 13;
  1263. return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] );
  1264. }
  1265. static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) {
  1266. int mode = 0;
  1267. if( get_cabac( &h->cabac, &h->cabac_state[68] ) )
  1268. return pred_mode;
  1269. mode += 1 * get_cabac( &h->cabac, &h->cabac_state[69] );
  1270. mode += 2 * get_cabac( &h->cabac, &h->cabac_state[69] );
  1271. mode += 4 * get_cabac( &h->cabac, &h->cabac_state[69] );
  1272. return mode + ( mode >= pred_mode );
  1273. }
  1274. static int decode_cabac_mb_chroma_pre_mode( H264Context *h) {
  1275. const int mba_xy = h->left_mb_xy[0];
  1276. const int mbb_xy = h->top_mb_xy;
  1277. int ctx = 0;
  1278. /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */
  1279. if( h->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0 )
  1280. ctx++;
  1281. if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 )
  1282. ctx++;
  1283. if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 )
  1284. return 0;
  1285. if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 )
  1286. return 1;
  1287. if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 )
  1288. return 2;
  1289. else
  1290. return 3;
  1291. }
  1292. static int decode_cabac_mb_cbp_luma( H264Context *h) {
  1293. int cbp_b, cbp_a, ctx, cbp = 0;
  1294. cbp_a = h->left_cbp;
  1295. cbp_b = h->top_cbp;
  1296. ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04);
  1297. cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]);
  1298. ctx = !(cbp & 0x01) + 2 * !(cbp_b & 0x08);
  1299. cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 1;
  1300. ctx = !(cbp_a & 0x08) + 2 * !(cbp & 0x01);
  1301. cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 2;
  1302. ctx = !(cbp & 0x04) + 2 * !(cbp & 0x02);
  1303. cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 3;
  1304. return cbp;
  1305. }
  1306. static int decode_cabac_mb_cbp_chroma( H264Context *h) {
  1307. int ctx;
  1308. int cbp_a, cbp_b;
  1309. cbp_a = (h->left_cbp>>4)&0x03;
  1310. cbp_b = (h-> top_cbp>>4)&0x03;
  1311. ctx = 0;
  1312. if( cbp_a > 0 ) ctx++;
  1313. if( cbp_b > 0 ) ctx += 2;
  1314. if( get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 )
  1315. return 0;
  1316. ctx = 4;
  1317. if( cbp_a == 2 ) ctx++;
  1318. if( cbp_b == 2 ) ctx += 2;
  1319. return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] );
  1320. }
  1321. static int decode_cabac_p_mb_sub_type( H264Context *h ) {
  1322. if( get_cabac( &h->cabac, &h->cabac_state[21] ) )
  1323. return 0; /* 8x8 */
  1324. if( !get_cabac( &h->cabac, &h->cabac_state[22] ) )
  1325. return 1; /* 8x4 */
  1326. if( get_cabac( &h->cabac, &h->cabac_state[23] ) )
  1327. return 2; /* 4x8 */
  1328. return 3; /* 4x4 */
  1329. }
  1330. static int decode_cabac_b_mb_sub_type( H264Context *h ) {
  1331. int type;
  1332. if( !get_cabac( &h->cabac, &h->cabac_state[36] ) )
  1333. return 0; /* B_Direct_8x8 */
  1334. if( !get_cabac( &h->cabac, &h->cabac_state[37] ) )
  1335. return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */
  1336. type = 3;
  1337. if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) {
  1338. if( get_cabac( &h->cabac, &h->cabac_state[39] ) )
  1339. return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */
  1340. type += 4;
  1341. }
  1342. type += 2*get_cabac( &h->cabac, &h->cabac_state[39] );
  1343. type += get_cabac( &h->cabac, &h->cabac_state[39] );
  1344. return type;
  1345. }
  1346. static int decode_cabac_mb_ref( H264Context *h, int list, int n ) {
  1347. int refa = h->ref_cache[list][scan8[n] - 1];
  1348. int refb = h->ref_cache[list][scan8[n] - 8];
  1349. int ref = 0;
  1350. int ctx = 0;
  1351. if( h->slice_type_nos == AV_PICTURE_TYPE_B) {
  1352. if( refa > 0 && !(h->direct_cache[scan8[n] - 1]&(MB_TYPE_DIRECT2>>1)) )
  1353. ctx++;
  1354. if( refb > 0 && !(h->direct_cache[scan8[n] - 8]&(MB_TYPE_DIRECT2>>1)) )
  1355. ctx += 2;
  1356. } else {
  1357. if( refa > 0 )
  1358. ctx++;
  1359. if( refb > 0 )
  1360. ctx += 2;
  1361. }
  1362. while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) {
  1363. ref++;
  1364. ctx = (ctx>>2)+4;
  1365. if(ref >= 32 /*h->ref_list[list]*/){
  1366. return -1;
  1367. }
  1368. }
  1369. return ref;
  1370. }
  1371. static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda) {
  1372. int mvd;
  1373. if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+((amvd-3)>>(INT_BIT-1))+((amvd-33)>>(INT_BIT-1))+2])){
  1374. // if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+(amvd>2)+(amvd>32)])){
  1375. *mvda= 0;
  1376. return 0;
  1377. }
  1378. mvd= 1;
  1379. ctxbase+= 3;
  1380. while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase] ) ) {
  1381. if( mvd < 4 )
  1382. ctxbase++;
  1383. mvd++;
  1384. }
  1385. if( mvd >= 9 ) {
  1386. int k = 3;
  1387. while( get_cabac_bypass( &h->cabac ) ) {
  1388. mvd += 1 << k;
  1389. k++;
  1390. if(k>24){
  1391. av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n");
  1392. return INT_MIN;
  1393. }
  1394. }
  1395. while( k-- ) {
  1396. mvd += get_cabac_bypass( &h->cabac )<<k;
  1397. }
  1398. *mvda=mvd < 70 ? mvd : 70;
  1399. }else
  1400. *mvda=mvd;
  1401. return get_cabac_bypass_sign( &h->cabac, -mvd );
  1402. }
  1403. #define DECODE_CABAC_MB_MVD( h, list, n )\
  1404. {\
  1405. int amvd0 = h->mvd_cache[list][scan8[n] - 1][0] +\
  1406. h->mvd_cache[list][scan8[n] - 8][0];\
  1407. int amvd1 = h->mvd_cache[list][scan8[n] - 1][1] +\
  1408. h->mvd_cache[list][scan8[n] - 8][1];\
  1409. \
  1410. mx += decode_cabac_mb_mvd( h, 40, amvd0, &mpx );\
  1411. my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\
  1412. }
  1413. static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int max_coeff, int is_dc ) {
  1414. int nza, nzb;
  1415. int ctx = 0;
  1416. static const uint16_t base_ctx[14] = {85,89,93,97,101,1012,460,464,468,1016,472,476,480,1020};
  1417. if( is_dc ) {
  1418. if( cat == 3 ) {
  1419. idx -= CHROMA_DC_BLOCK_INDEX;
  1420. nza = (h->left_cbp>>(6+idx))&0x01;
  1421. nzb = (h-> top_cbp>>(6+idx))&0x01;
  1422. } else {
  1423. idx -= LUMA_DC_BLOCK_INDEX;
  1424. nza = h->left_cbp&(0x100<<idx);
  1425. nzb = h-> top_cbp&(0x100<<idx);
  1426. }
  1427. } else {
  1428. nza = h->non_zero_count_cache[scan8[idx] - 1];
  1429. nzb = h->non_zero_count_cache[scan8[idx] - 8];
  1430. }
  1431. if( nza > 0 )
  1432. ctx++;
  1433. if( nzb > 0 )
  1434. ctx += 2;
  1435. return base_ctx[cat] + ctx;
  1436. }
  1437. DECLARE_ASM_CONST(1, uint8_t, last_coeff_flag_offset_8x8)[63] = {
  1438. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1439. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  1440. 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
  1441. 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
  1442. };
  1443. static av_always_inline void
  1444. decode_cabac_residual_internal(H264Context *h, DCTELEM *block,
  1445. int cat, int n, const uint8_t *scantable,
  1446. const uint32_t *qmul, int max_coeff,
  1447. int is_dc, int chroma422)
  1448. {
  1449. static const int significant_coeff_flag_offset[2][14] = {
  1450. { 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 },
  1451. { 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 }
  1452. };
  1453. static const int last_coeff_flag_offset[2][14] = {
  1454. { 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 },
  1455. { 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 }
  1456. };
  1457. static const int coeff_abs_level_m1_offset[14] = {
  1458. 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
  1459. };
  1460. static const uint8_t significant_coeff_flag_offset_8x8[2][63] = {
  1461. { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
  1462. 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
  1463. 7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
  1464. 12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12 },
  1465. { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
  1466. 6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
  1467. 9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
  1468. 9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 }
  1469. };
  1470. static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 };
  1471. /* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0).
  1472. * 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter).
  1473. * map node ctx => cabac ctx for level=1 */
  1474. static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 };
  1475. /* map node ctx => cabac ctx for level>1 */
  1476. static const uint8_t coeff_abs_levelgt1_ctx[2][8] = {
  1477. { 5, 5, 5, 5, 6, 7, 8, 9 },
  1478. { 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case
  1479. };
  1480. static const uint8_t coeff_abs_level_transition[2][8] = {
  1481. /* update node ctx after decoding a level=1 */
  1482. { 1, 2, 3, 3, 4, 5, 6, 7 },
  1483. /* update node ctx after decoding a level>1 */
  1484. { 4, 4, 4, 4, 5, 6, 7, 7 }
  1485. };
  1486. int index[64];
  1487. int av_unused last;
  1488. int coeff_count = 0;
  1489. int node_ctx = 0;
  1490. uint8_t *significant_coeff_ctx_base;
  1491. uint8_t *last_coeff_ctx_base;
  1492. uint8_t *abs_level_m1_ctx_base;
  1493. #if !ARCH_X86
  1494. #define CABAC_ON_STACK
  1495. #endif
  1496. #ifdef CABAC_ON_STACK
  1497. #define CC &cc
  1498. CABACContext cc;
  1499. cc.range = h->cabac.range;
  1500. cc.low = h->cabac.low;
  1501. cc.bytestream= h->cabac.bytestream;
  1502. #else
  1503. #define CC &h->cabac
  1504. #endif
  1505. significant_coeff_ctx_base = h->cabac_state
  1506. + significant_coeff_flag_offset[MB_FIELD][cat];
  1507. last_coeff_ctx_base = h->cabac_state
  1508. + last_coeff_flag_offset[MB_FIELD][cat];
  1509. abs_level_m1_ctx_base = h->cabac_state
  1510. + coeff_abs_level_m1_offset[cat];
  1511. if( !is_dc && max_coeff == 64 ) {
  1512. #define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \
  1513. for(last= 0; last < coefs; last++) { \
  1514. uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \
  1515. if( get_cabac( CC, sig_ctx )) { \
  1516. uint8_t *last_ctx = last_coeff_ctx_base + last_off; \
  1517. index[coeff_count++] = last; \
  1518. if( get_cabac( CC, last_ctx ) ) { \
  1519. last= max_coeff; \
  1520. break; \
  1521. } \
  1522. } \
  1523. }\
  1524. if( last == max_coeff -1 ) {\
  1525. index[coeff_count++] = last;\
  1526. }
  1527. const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
  1528. #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
  1529. coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index,
  1530. last_coeff_ctx_base, sig_off);
  1531. } else {
  1532. if (is_dc && chroma422) { // dc 422
  1533. DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
  1534. } else {
  1535. coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index,
  1536. last_coeff_ctx_base-significant_coeff_ctx_base);
  1537. }
  1538. #else
  1539. DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] );
  1540. } else {
  1541. if (is_dc && chroma422) { // dc 422
  1542. DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]);
  1543. } else {
  1544. DECODE_SIGNIFICANCE(max_coeff - 1, last, last);
  1545. }
  1546. #endif
  1547. }
  1548. assert(coeff_count > 0);
  1549. if( is_dc ) {
  1550. if( cat == 3 )
  1551. h->cbp_table[h->mb_xy] |= 0x40 << (n - CHROMA_DC_BLOCK_INDEX);
  1552. else
  1553. h->cbp_table[h->mb_xy] |= 0x100 << (n - LUMA_DC_BLOCK_INDEX);
  1554. h->non_zero_count_cache[scan8[n]] = coeff_count;
  1555. } else {
  1556. if( max_coeff == 64 )
  1557. fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1);
  1558. else {
  1559. assert( cat == 1 || cat == 2 || cat == 4 || cat == 7 || cat == 8 || cat == 11 || cat == 12 );
  1560. h->non_zero_count_cache[scan8[n]] = coeff_count;
  1561. }
  1562. }
  1563. #define STORE_BLOCK(type) \
  1564. do { \
  1565. uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; \
  1566. \
  1567. int j= scantable[index[--coeff_count]]; \
  1568. \
  1569. if( get_cabac( CC, ctx ) == 0 ) { \
  1570. node_ctx = coeff_abs_level_transition[0][node_ctx]; \
  1571. if( is_dc ) { \
  1572. ((type*)block)[j] = get_cabac_bypass_sign( CC, -1); \
  1573. }else{ \
  1574. ((type*)block)[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; \
  1575. } \
  1576. } else { \
  1577. int coeff_abs = 2; \
  1578. ctx = coeff_abs_levelgt1_ctx[is_dc && chroma422][node_ctx] + abs_level_m1_ctx_base; \
  1579. node_ctx = coeff_abs_level_transition[1][node_ctx]; \
  1580. \
  1581. while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \
  1582. coeff_abs++; \
  1583. } \
  1584. \
  1585. if( coeff_abs >= 15 ) { \
  1586. int j = 0; \
  1587. while( get_cabac_bypass( CC ) ) { \
  1588. j++; \
  1589. } \
  1590. \
  1591. coeff_abs=1; \
  1592. while( j-- ) { \
  1593. coeff_abs += coeff_abs + get_cabac_bypass( CC ); \
  1594. } \
  1595. coeff_abs+= 14; \
  1596. } \
  1597. \
  1598. if( is_dc ) { \
  1599. ((type*)block)[j] = get_cabac_bypass_sign( CC, -coeff_abs ); \
  1600. }else{ \
  1601. ((type*)block)[j] = ((int)(get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32)) >> 6; \
  1602. } \
  1603. } \
  1604. } while ( coeff_count );
  1605. if (h->pixel_shift) {
  1606. STORE_BLOCK(int32_t)
  1607. } else {
  1608. STORE_BLOCK(int16_t)
  1609. }
  1610. #ifdef CABAC_ON_STACK
  1611. h->cabac.range = cc.range ;
  1612. h->cabac.low = cc.low ;
  1613. h->cabac.bytestream= cc.bytestream;
  1614. #endif
  1615. }
  1616. static void decode_cabac_residual_dc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) {
  1617. decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0);
  1618. }
  1619. static void decode_cabac_residual_dc_internal_422(H264Context *h, DCTELEM *block,
  1620. int cat, int n, const uint8_t *scantable,
  1621. int max_coeff)
  1622. {
  1623. decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1);
  1624. }
  1625. 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 ) {
  1626. decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0);
  1627. }
  1628. /* cat: 0-> DC 16x16 n = 0
  1629. * 1-> AC 16x16 n = luma4x4idx
  1630. * 2-> Luma4x4 n = luma4x4idx
  1631. * 3-> DC Chroma n = iCbCr
  1632. * 4-> AC Chroma n = 16 + 4 * iCbCr + chroma4x4idx
  1633. * 5-> Luma8x8 n = 4 * luma8x8idx */
  1634. /* Partially inline the CABAC residual decode: inline the coded block flag.
  1635. * This has very little impact on binary size and improves performance
  1636. * because it allows improved constant propagation into get_cabac_cbf_ctx,
  1637. * as well as because most blocks have zero CBFs. */
  1638. static av_always_inline void decode_cabac_residual_dc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) {
  1639. /* read coded block flag */
  1640. if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 1 ) ] ) == 0 ) {
  1641. h->non_zero_count_cache[scan8[n]] = 0;
  1642. return;
  1643. }
  1644. decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff );
  1645. }
  1646. static av_always_inline void
  1647. decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block,
  1648. int cat, int n, const uint8_t *scantable,
  1649. int max_coeff)
  1650. {
  1651. /* read coded block flag */
  1652. if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) {
  1653. h->non_zero_count_cache[scan8[n]] = 0;
  1654. return;
  1655. }
  1656. decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff);
  1657. }
  1658. 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 ) {
  1659. /* read coded block flag */
  1660. if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
  1661. if( max_coeff == 64 ) {
  1662. fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1);
  1663. } else {
  1664. h->non_zero_count_cache[scan8[n]] = 0;
  1665. }
  1666. return;
  1667. }
  1668. decode_cabac_residual_nondc_internal( h, block, cat, n, scantable, qmul, max_coeff );
  1669. }
  1670. 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 )
  1671. {
  1672. static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}};
  1673. const uint32_t *qmul;
  1674. int i8x8, i4x4;
  1675. MpegEncContext * const s = &h->s;
  1676. int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1];
  1677. if( IS_INTRA16x16( mb_type ) ) {
  1678. //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" );
  1679. AV_ZERO128(h->mb_luma_dc[p]+0);
  1680. AV_ZERO128(h->mb_luma_dc[p]+8);
  1681. AV_ZERO128(h->mb_luma_dc[p]+16);
  1682. AV_ZERO128(h->mb_luma_dc[p]+24);
  1683. decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16);
  1684. if( cbp&15 ) {
  1685. qmul = h->dequant4_coeff[p][qscale];
  1686. for( i4x4 = 0; i4x4 < 16; i4x4++ ) {
  1687. const int index = 16*p + i4x4;
  1688. //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", index );
  1689. decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15);
  1690. }
  1691. } else {
  1692. fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1);
  1693. }
  1694. } else {
  1695. int cqm = (IS_INTRA( mb_type ) ? 0:3) + p;
  1696. for( i8x8 = 0; i8x8 < 4; i8x8++ ) {
  1697. if( cbp & (1<<i8x8) ) {
  1698. if( IS_8x8DCT(mb_type) ) {
  1699. const int index = 16*p + 4*i8x8;
  1700. decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[3][p], index,
  1701. scan8x8, h->dequant8_coeff[cqm][qscale], 64);
  1702. } else {
  1703. qmul = h->dequant4_coeff[cqm][qscale];
  1704. for( i4x4 = 0; i4x4 < 4; i4x4++ ) {
  1705. const int index = 16*p + 4*i8x8 + i4x4;
  1706. //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index );
  1707. //START_TIMER
  1708. decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16);
  1709. //STOP_TIMER("decode_residual")
  1710. }
  1711. }
  1712. } else {
  1713. fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1);
  1714. }
  1715. }
  1716. }
  1717. }
  1718. /**
  1719. * decodes a macroblock
  1720. * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed
  1721. */
  1722. int ff_h264_decode_mb_cabac(H264Context *h) {
  1723. MpegEncContext * const s = &h->s;
  1724. int mb_xy;
  1725. int mb_type, partition_count, cbp = 0;
  1726. int dct8x8_allowed= h->pps.transform_8x8_mode;
  1727. int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;
  1728. const int pixel_shift = h->pixel_shift;
  1729. mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
  1730. tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
  1731. if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {
  1732. int skip;
  1733. /* a skipped mb needs the aff flag from the following mb */
  1734. if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )
  1735. skip = h->next_mb_skipped;
  1736. else
  1737. skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );
  1738. /* read skip flags */
  1739. if( skip ) {
  1740. if( FRAME_MBAFF && (s->mb_y&1)==0 ){
  1741. s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP;
  1742. h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );
  1743. if(!h->next_mb_skipped)
  1744. h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
  1745. }
  1746. decode_mb_skip(h);
  1747. h->cbp_table[mb_xy] = 0;
  1748. h->chroma_pred_mode_table[mb_xy] = 0;
  1749. h->last_qscale_diff = 0;
  1750. return 0;
  1751. }
  1752. }
  1753. if(FRAME_MBAFF){
  1754. if( (s->mb_y&1) == 0 )
  1755. h->mb_mbaff =
  1756. h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
  1757. }
  1758. h->prev_mb_skipped = 0;
  1759. fill_decode_neighbors(h, -(MB_FIELD));
  1760. if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
  1761. int ctx = 0;
  1762. assert(h->slice_type_nos == AV_PICTURE_TYPE_B);
  1763. if( !IS_DIRECT( h->left_type[LTOP]-1 ) )
  1764. ctx++;
  1765. if( !IS_DIRECT( h->top_type-1 ) )
  1766. ctx++;
  1767. if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){
  1768. mb_type= 0; /* B_Direct_16x16 */
  1769. }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {
  1770. mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */
  1771. }else{
  1772. int bits;
  1773. bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;
  1774. bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;
  1775. bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;
  1776. bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );
  1777. if( bits < 8 ){
  1778. mb_type= bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */
  1779. }else if( bits == 13 ){
  1780. mb_type= decode_cabac_intra_mb_type(h, 32, 0);
  1781. goto decode_intra_mb;
  1782. }else if( bits == 14 ){
  1783. mb_type= 11; /* B_L1_L0_8x16 */
  1784. }else if( bits == 15 ){
  1785. mb_type= 22; /* B_8x8 */
  1786. }else{
  1787. bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );
  1788. mb_type= bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */
  1789. }
  1790. }
  1791. partition_count= b_mb_type_info[mb_type].partition_count;
  1792. mb_type= b_mb_type_info[mb_type].type;
  1793. } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {
  1794. if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {
  1795. /* P-type */
  1796. if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {
  1797. /* P_L0_D16x16, P_8x8 */
  1798. mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );
  1799. } else {
  1800. /* P_L0_D8x16, P_L0_D16x8 */
  1801. mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );
  1802. }
  1803. partition_count= p_mb_type_info[mb_type].partition_count;
  1804. mb_type= p_mb_type_info[mb_type].type;
  1805. } else {
  1806. mb_type= decode_cabac_intra_mb_type(h, 17, 0);
  1807. goto decode_intra_mb;
  1808. }
  1809. } else {
  1810. mb_type= decode_cabac_intra_mb_type(h, 3, 1);
  1811. if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)
  1812. mb_type--;
  1813. assert(h->slice_type_nos == AV_PICTURE_TYPE_I);
  1814. decode_intra_mb:
  1815. partition_count = 0;
  1816. cbp= i_mb_type_info[mb_type].cbp;
  1817. h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
  1818. mb_type= i_mb_type_info[mb_type].type;
  1819. }
  1820. if(MB_FIELD)
  1821. mb_type |= MB_TYPE_INTERLACED;
  1822. h->slice_table[ mb_xy ]= h->slice_num;
  1823. if(IS_INTRA_PCM(mb_type)) {
  1824. static const uint16_t mb_sizes[4] = {256,384,512,768};
  1825. const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;
  1826. const uint8_t *ptr;
  1827. // We assume these blocks are very rare so we do not optimize it.
  1828. // FIXME The two following lines get the bitstream position in the cabac
  1829. // decode, I think it should be done by a function in cabac.h (or cabac.c).
  1830. ptr= h->cabac.bytestream;
  1831. if(h->cabac.low&0x1) ptr--;
  1832. if(CABAC_BITS==16){
  1833. if(h->cabac.low&0x1FF) ptr--;
  1834. }
  1835. // The pixels are stored in the same order as levels in h->mb array.
  1836. memcpy(h->mb, ptr, mb_size); ptr+=mb_size;
  1837. ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
  1838. // All blocks are present
  1839. h->cbp_table[mb_xy] = 0xf7ef;
  1840. h->chroma_pred_mode_table[mb_xy] = 0;
  1841. // In deblocking, the quantizer is 0
  1842. s->current_picture.f.qscale_table[mb_xy] = 0;
  1843. // All coeffs are present
  1844. memset(h->non_zero_count[mb_xy], 16, 48);
  1845. s->current_picture.f.mb_type[mb_xy] = mb_type;
  1846. h->last_qscale_diff = 0;
  1847. return 0;
  1848. }
  1849. if(MB_MBAFF){
  1850. h->ref_count[0] <<= 1;
  1851. h->ref_count[1] <<= 1;
  1852. }
  1853. fill_decode_caches(h, mb_type);
  1854. if( IS_INTRA( mb_type ) ) {
  1855. int i, pred_mode;
  1856. if( IS_INTRA4x4( mb_type ) ) {
  1857. if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {
  1858. mb_type |= MB_TYPE_8x8DCT;
  1859. for( i = 0; i < 16; i+=4 ) {
  1860. int pred = pred_intra_mode( h, i );
  1861. int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );
  1862. fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );
  1863. }
  1864. } else {
  1865. for( i = 0; i < 16; i++ ) {
  1866. int pred = pred_intra_mode( h, i );
  1867. h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );
  1868. //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] );
  1869. }
  1870. }
  1871. write_back_intra_pred_mode(h);
  1872. if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;
  1873. } else {
  1874. h->intra16x16_pred_mode= ff_h264_check_intra16x16_pred_mode( h, h->intra16x16_pred_mode );
  1875. if( h->intra16x16_pred_mode < 0 ) return -1;
  1876. }
  1877. if(decode_chroma){
  1878. h->chroma_pred_mode_table[mb_xy] =
  1879. pred_mode = decode_cabac_mb_chroma_pre_mode( h );
  1880. pred_mode= ff_h264_check_intra_chroma_pred_mode( h, pred_mode );
  1881. if( pred_mode < 0 ) return -1;
  1882. h->chroma_pred_mode= pred_mode;
  1883. } else {
  1884. h->chroma_pred_mode= DC_128_PRED8x8;
  1885. }
  1886. } else if( partition_count == 4 ) {
  1887. int i, j, sub_partition_count[4], list, ref[2][4];
  1888. if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
  1889. for( i = 0; i < 4; i++ ) {
  1890. h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );
  1891. sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
  1892. h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
  1893. }
  1894. if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |
  1895. h->sub_mb_type[2] | h->sub_mb_type[3]) ) {
  1896. ff_h264_pred_direct_motion(h, &mb_type);
  1897. h->ref_cache[0][scan8[4]] =
  1898. h->ref_cache[1][scan8[4]] =
  1899. h->ref_cache[0][scan8[12]] =
  1900. h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
  1901. for( i = 0; i < 4; i++ )
  1902. fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );
  1903. }
  1904. } else {
  1905. for( i = 0; i < 4; i++ ) {
  1906. h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );
  1907. sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
  1908. h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;
  1909. }
  1910. }
  1911. for( list = 0; list < h->list_count; list++ ) {
  1912. for( i = 0; i < 4; i++ ) {
  1913. if(IS_DIRECT(h->sub_mb_type[i])) continue;
  1914. if(IS_DIR(h->sub_mb_type[i], 0, list)){
  1915. if( h->ref_count[list] > 1 ){
  1916. ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );
  1917. if(ref[list][i] >= (unsigned)h->ref_count[list]){
  1918. av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], h->ref_count[list]);
  1919. return -1;
  1920. }
  1921. }else
  1922. ref[list][i] = 0;
  1923. } else {
  1924. ref[list][i] = -1;
  1925. }
  1926. h->ref_cache[list][ scan8[4*i]+1 ]=
  1927. h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
  1928. }
  1929. }
  1930. if(dct8x8_allowed)
  1931. dct8x8_allowed = get_dct8x8_allowed(h);
  1932. for(list=0; list<h->list_count; list++){
  1933. for(i=0; i<4; i++){
  1934. h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];
  1935. if(IS_DIRECT(h->sub_mb_type[i])){
  1936. fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);
  1937. continue;
  1938. }
  1939. if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){
  1940. const int sub_mb_type= h->sub_mb_type[i];
  1941. const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
  1942. for(j=0; j<sub_partition_count[i]; j++){
  1943. int mpx, mpy;
  1944. int mx, my;
  1945. const int index= 4*i + block_width*j;
  1946. int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
  1947. uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];
  1948. pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
  1949. DECODE_CABAC_MB_MVD( h, list, index)
  1950. tprintf(s->avctx, "final mv:%d %d\n", mx, my);
  1951. if(IS_SUB_8X8(sub_mb_type)){
  1952. mv_cache[ 1 ][0]=
  1953. mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
  1954. mv_cache[ 1 ][1]=
  1955. mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
  1956. mvd_cache[ 1 ][0]=
  1957. mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;
  1958. mvd_cache[ 1 ][1]=
  1959. mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;
  1960. }else if(IS_SUB_8X4(sub_mb_type)){
  1961. mv_cache[ 1 ][0]= mx;
  1962. mv_cache[ 1 ][1]= my;
  1963. mvd_cache[ 1 ][0]= mpx;
  1964. mvd_cache[ 1 ][1]= mpy;
  1965. }else if(IS_SUB_4X8(sub_mb_type)){
  1966. mv_cache[ 8 ][0]= mx;
  1967. mv_cache[ 8 ][1]= my;
  1968. mvd_cache[ 8 ][0]= mpx;
  1969. mvd_cache[ 8 ][1]= mpy;
  1970. }
  1971. mv_cache[ 0 ][0]= mx;
  1972. mv_cache[ 0 ][1]= my;
  1973. mvd_cache[ 0 ][0]= mpx;
  1974. mvd_cache[ 0 ][1]= mpy;
  1975. }
  1976. }else{
  1977. fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);
  1978. fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);
  1979. }
  1980. }
  1981. }
  1982. } else if( IS_DIRECT(mb_type) ) {
  1983. ff_h264_pred_direct_motion(h, &mb_type);
  1984. fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);
  1985. fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);
  1986. dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
  1987. } else {
  1988. int list, i;
  1989. if(IS_16X16(mb_type)){
  1990. for(list=0; list<h->list_count; list++){
  1991. if(IS_DIR(mb_type, 0, list)){
  1992. int ref;
  1993. if(h->ref_count[list] > 1){
  1994. ref= decode_cabac_mb_ref(h, list, 0);
  1995. if(ref >= (unsigned)h->ref_count[list]){
  1996. av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]);
  1997. return -1;
  1998. }
  1999. }else
  2000. ref=0;
  2001. fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);
  2002. }
  2003. }
  2004. for(list=0; list<h->list_count; list++){
  2005. if(IS_DIR(mb_type, 0, list)){
  2006. int mx,my,mpx,mpy;
  2007. pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
  2008. DECODE_CABAC_MB_MVD( h, list, 0)
  2009. tprintf(s->avctx, "final mv:%d %d\n", mx, my);
  2010. fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);
  2011. fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
  2012. }
  2013. }
  2014. }
  2015. else if(IS_16X8(mb_type)){
  2016. for(list=0; list<h->list_count; list++){
  2017. for(i=0; i<2; i++){
  2018. if(IS_DIR(mb_type, i, list)){
  2019. int ref;
  2020. if(h->ref_count[list] > 1){
  2021. ref= decode_cabac_mb_ref( h, list, 8*i );
  2022. if(ref >= (unsigned)h->ref_count[list]){
  2023. av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]);
  2024. return -1;
  2025. }
  2026. }else
  2027. ref=0;
  2028. fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);
  2029. }else
  2030. fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);
  2031. }
  2032. }
  2033. for(list=0; list<h->list_count; list++){
  2034. for(i=0; i<2; i++){
  2035. if(IS_DIR(mb_type, i, list)){
  2036. int mx,my,mpx,mpy;
  2037. pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
  2038. DECODE_CABAC_MB_MVD( h, list, 8*i)
  2039. tprintf(s->avctx, "final mv:%d %d\n", mx, my);
  2040. fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);
  2041. fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
  2042. }else{
  2043. fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);
  2044. fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
  2045. }
  2046. }
  2047. }
  2048. }else{
  2049. assert(IS_8X16(mb_type));
  2050. for(list=0; list<h->list_count; list++){
  2051. for(i=0; i<2; i++){
  2052. if(IS_DIR(mb_type, i, list)){ //FIXME optimize
  2053. int ref;
  2054. if(h->ref_count[list] > 1){
  2055. ref= decode_cabac_mb_ref( h, list, 4*i );
  2056. if(ref >= (unsigned)h->ref_count[list]){
  2057. av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]);
  2058. return -1;
  2059. }
  2060. }else
  2061. ref=0;
  2062. fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);
  2063. }else
  2064. fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);
  2065. }
  2066. }
  2067. for(list=0; list<h->list_count; list++){
  2068. for(i=0; i<2; i++){
  2069. if(IS_DIR(mb_type, i, list)){
  2070. int mx,my,mpx,mpy;
  2071. pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
  2072. DECODE_CABAC_MB_MVD( h, list, 4*i)
  2073. tprintf(s->avctx, "final mv:%d %d\n", mx, my);
  2074. fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);
  2075. fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
  2076. }else{
  2077. fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);
  2078. fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
  2079. }
  2080. }
  2081. }
  2082. }
  2083. }
  2084. if( IS_INTER( mb_type ) ) {
  2085. h->chroma_pred_mode_table[mb_xy] = 0;
  2086. write_back_motion( h, mb_type );
  2087. }
  2088. if( !IS_INTRA16x16( mb_type ) ) {
  2089. cbp = decode_cabac_mb_cbp_luma( h );
  2090. if(decode_chroma)
  2091. cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;
  2092. }
  2093. h->cbp_table[mb_xy] = h->cbp = cbp;
  2094. if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {
  2095. mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );
  2096. }
  2097. /* It would be better to do this in fill_decode_caches, but we don't know
  2098. * the transform mode of the current macroblock there. */
  2099. if (CHROMA444 && IS_8x8DCT(mb_type)){
  2100. int i;
  2101. uint8_t *nnz_cache = h->non_zero_count_cache;
  2102. for (i = 0; i < 2; i++){
  2103. if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){
  2104. nnz_cache[3+8* 1 + 2*8*i]=
  2105. nnz_cache[3+8* 2 + 2*8*i]=
  2106. nnz_cache[3+8* 6 + 2*8*i]=
  2107. nnz_cache[3+8* 7 + 2*8*i]=
  2108. nnz_cache[3+8*11 + 2*8*i]=
  2109. nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;
  2110. }
  2111. }
  2112. if (h->top_type && !IS_8x8DCT(h->top_type)){
  2113. uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
  2114. AV_WN32A(&nnz_cache[4+8* 0], top_empty);
  2115. AV_WN32A(&nnz_cache[4+8* 5], top_empty);
  2116. AV_WN32A(&nnz_cache[4+8*10], top_empty);
  2117. }
  2118. }
  2119. s->current_picture.f.mb_type[mb_xy] = mb_type;
  2120. if( cbp || IS_INTRA16x16( mb_type ) ) {
  2121. const uint8_t *scan, *scan8x8;
  2122. const uint32_t *qmul;
  2123. if(IS_INTERLACED(mb_type)){
  2124. scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;
  2125. scan= s->qscale ? h->field_scan : h->field_scan_q0;
  2126. }else{
  2127. scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;
  2128. scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
  2129. }
  2130. // decode_cabac_mb_dqp
  2131. if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){
  2132. int val = 1;
  2133. int ctx= 2;
  2134. const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
  2135. while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
  2136. ctx= 3;
  2137. val++;
  2138. if(val > 2*max_qp){ //prevent infinite loop
  2139. av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y);
  2140. return -1;
  2141. }
  2142. }
  2143. if( val&0x01 )
  2144. val= (val + 1)>>1 ;
  2145. else
  2146. val= -((val + 1)>>1);
  2147. h->last_qscale_diff = val;
  2148. s->qscale += val;
  2149. if(((unsigned)s->qscale) > max_qp){
  2150. if(s->qscale<0) s->qscale+= max_qp+1;
  2151. else s->qscale-= max_qp+1;
  2152. }
  2153. h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
  2154. h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
  2155. }else
  2156. h->last_qscale_diff=0;
  2157. decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);
  2158. if(CHROMA444){
  2159. decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);
  2160. decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);
  2161. } else if (CHROMA422) {
  2162. if( cbp&0x30 ){
  2163. int c;
  2164. for( c = 0; c < 2; c++ ) {
  2165. //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
  2166. decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3,
  2167. CHROMA_DC_BLOCK_INDEX + c,
  2168. chroma422_dc_scan, 8);
  2169. }
  2170. }
  2171. if( cbp&0x20 ) {
  2172. int c, i, i8x8;
  2173. for( c = 0; c < 2; c++ ) {
  2174. DCTELEM *mb = h->mb + (16*(16 + 16*c) << pixel_shift);
  2175. qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
  2176. for (i8x8 = 0; i8x8 < 2; i8x8++) {
  2177. for (i = 0; i < 4; i++) {
  2178. const int index = 16 + 16 * c + 8*i8x8 + i;
  2179. //av_log(s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16);
  2180. decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15);
  2181. mb += 16<<pixel_shift;
  2182. }
  2183. }
  2184. }
  2185. } else {
  2186. fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
  2187. fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
  2188. }
  2189. } else /* yuv420 */ {
  2190. if( cbp&0x30 ){
  2191. int c;
  2192. for( c = 0; c < 2; c++ ) {
  2193. //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c );
  2194. decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);
  2195. }
  2196. }
  2197. if( cbp&0x20 ) {
  2198. int c, i;
  2199. for( c = 0; c < 2; c++ ) {
  2200. qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];
  2201. for( i = 0; i < 4; i++ ) {
  2202. const int index = 16 + 16 * c + i;
  2203. //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 );
  2204. decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);
  2205. }
  2206. }
  2207. } else {
  2208. fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
  2209. fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
  2210. }
  2211. }
  2212. } else {
  2213. fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);
  2214. fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);
  2215. fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);
  2216. h->last_qscale_diff = 0;
  2217. }
  2218. s->current_picture.f.qscale_table[mb_xy] = s->qscale;
  2219. write_back_non_zero_count(h);
  2220. if(MB_MBAFF){
  2221. h->ref_count[0] >>= 1;
  2222. h->ref_count[1] >>= 1;
  2223. }
  2224. return 0;
  2225. }