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.

2423 lines
112KB

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