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.

2429 lines
112KB

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