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.

2491 lines
116KB

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