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.

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