vc1data.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * VC-1 and WMV3 decoder
  3. * copyright (c) 2006 Konstantin Shishkov
  4. * (c) 2005 anonymous, Alex Beregszaszi, Michael Niedermayer
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file libavcodec/vc1data.c
  24. * VC-1 tables.
  25. */
  26. #include "avcodec.h"
  27. #include "vc1.h"
  28. #include "vc1data.h"
  29. /** Table for conversion between TTBLK and TTMB */
  30. const int ff_vc1_ttblk_to_tt[3][8] = {
  31. { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
  32. { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
  33. { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
  34. };
  35. const int ff_vc1_ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 };
  36. /** MV P mode - the 5th element is only used for mode 1 */
  37. const uint8_t ff_vc1_mv_pmode_table[2][5] = {
  38. { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV },
  39. { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN }
  40. };
  41. const uint8_t ff_vc1_mv_pmode_table2[2][4] = {
  42. { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV },
  43. { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN }
  44. };
  45. const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 },
  46. ff_vc1_fps_dr[2] = { 1000, 1001 };
  47. const uint8_t ff_vc1_pquant_table[3][32] = {
  48. { /* Implicit quantizer */
  49. 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12,
  50. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31
  51. },
  52. { /* Explicit quantizer, pquantizer uniform */
  53. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  54. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
  55. },
  56. { /* Explicit quantizer, pquantizer non-uniform */
  57. 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  58. 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31
  59. }
  60. };
  61. /** @name VC-1 VLC tables and defines
  62. * @todo TODO move this into the context
  63. */
  64. //@{
  65. #define VC1_BFRACTION_VLC_BITS 7
  66. VLC ff_vc1_bfraction_vlc;
  67. #define VC1_IMODE_VLC_BITS 4
  68. VLC ff_vc1_imode_vlc;
  69. #define VC1_NORM2_VLC_BITS 3
  70. VLC ff_vc1_norm2_vlc;
  71. #define VC1_NORM6_VLC_BITS 9
  72. VLC ff_vc1_norm6_vlc;
  73. /* Could be optimized, one table only needs 8 bits */
  74. #define VC1_TTMB_VLC_BITS 9 //12
  75. VLC ff_vc1_ttmb_vlc[3];
  76. #define VC1_MV_DIFF_VLC_BITS 9 //15
  77. VLC ff_vc1_mv_diff_vlc[4];
  78. #define VC1_CBPCY_P_VLC_BITS 9 //14
  79. VLC ff_vc1_cbpcy_p_vlc[4];
  80. #define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
  81. VLC ff_vc1_4mv_block_pattern_vlc[4];
  82. #define VC1_TTBLK_VLC_BITS 5
  83. VLC ff_vc1_ttblk_vlc[3];
  84. #define VC1_SUBBLKPAT_VLC_BITS 6
  85. VLC ff_vc1_subblkpat_vlc[3];
  86. VLC ff_vc1_ac_coeff_table[8];
  87. //@}
  88. #if B_FRACTION_DEN==840 //original bfraction from vc9data.h, not conforming to standard
  89. /* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */
  90. const int16_t ff_vc1_bfraction_lut[23] = {
  91. 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/,
  92. 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/,
  93. 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/,
  94. 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/,
  95. 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/,
  96. 525 /*5/8*/, 735 /*7/8*/,
  97. -1 /*inv.*/, 0 /*BI fm*/
  98. };
  99. #else
  100. /* pre-computed scales for all bfractions and base=256 */
  101. const int16_t ff_vc1_bfraction_lut[23] = {
  102. 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/,
  103. 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/,
  104. 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/,
  105. 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/,
  106. 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/,
  107. 160 /*5/8*/, 224 /*7/8*/,
  108. -1 /*inv.*/, 0 /*BI fm*/
  109. };
  110. #endif
  111. const uint8_t ff_vc1_bfraction_bits[23] = {
  112. 3, 3, 3, 3,
  113. 3, 3, 3,
  114. 7, 7, 7, 7,
  115. 7, 7, 7, 7,
  116. 7, 7, 7, 7,
  117. 7, 7,
  118. 7, 7
  119. };
  120. const uint8_t ff_vc1_bfraction_codes[23] = {
  121. 0, 1, 2, 3,
  122. 4, 5, 6,
  123. 112, 113, 114, 115,
  124. 116, 117, 118, 119,
  125. 120, 121, 122, 123,
  126. 124, 125,
  127. 126, 127
  128. };
  129. //Same as H.264
  130. const AVRational ff_vc1_pixel_aspect[16]={
  131. {0, 1},
  132. {1, 1},
  133. {12, 11},
  134. {10, 11},
  135. {16, 11},
  136. {40, 33},
  137. {24, 11},
  138. {20, 11},
  139. {32, 11},
  140. {80, 33},
  141. {18, 11},
  142. {15, 11},
  143. {64, 33},
  144. {160, 99},
  145. {0, 1},
  146. {0, 1}
  147. };
  148. /* BitPlane IMODE - such a small table... */
  149. const uint8_t ff_vc1_imode_codes[7] = {
  150. 0, 2, 1, 3, 1, 2, 3
  151. };
  152. const uint8_t ff_vc1_imode_bits[7] = {
  153. 4, 2, 3, 2, 4, 3, 3
  154. };
  155. /* Normal-2 imode */
  156. const uint8_t ff_vc1_norm2_codes[4] = {
  157. 0, 4, 5, 3
  158. };
  159. const uint8_t ff_vc1_norm2_bits[4] = {
  160. 1, 3, 3, 2
  161. };
  162. const uint16_t ff_vc1_norm6_codes[64] = {
  163. 0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E,
  164. 0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037,
  165. 0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036,
  166. 0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007,
  167. };
  168. const uint8_t ff_vc1_norm6_bits[64] = {
  169. 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13,
  170. 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
  171. 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9,
  172. 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6,
  173. };
  174. #if 0
  175. /* Normal-6 imode */
  176. const uint8_t ff_vc1_norm6_spec[64][5] = {
  177. { 0, 1, 1 },
  178. { 1, 2, 4 },
  179. { 2, 3, 4 },
  180. { 3, 0, 8 },
  181. { 4, 4, 4 },
  182. { 5, 1, 8 },
  183. { 6, 2, 8 },
  184. { 7, 2, 5, 7, 5 },
  185. { 8, 5, 4 },
  186. { 9, 3, 8 },
  187. {10, 4, 8 },
  188. {11, 2, 5, 11, 5 },
  189. {12, 5, 8 },
  190. {13, 2, 5, 13, 5 },
  191. {14, 2, 5, 14, 5 },
  192. {15, 3, 5, 14, 8 },
  193. {16, 6, 4 },
  194. {17, 6, 8 },
  195. {18, 7, 8 },
  196. {19, 2, 5, 19, 5 },
  197. {20, 8, 8 },
  198. {21, 2, 5, 21, 5 },
  199. {22, 2, 5, 22, 5 },
  200. {23, 3, 5, 13, 8 },
  201. {24, 9, 8 },
  202. {25, 2, 5, 25, 5 },
  203. {26, 2, 5, 26, 5 },
  204. {27, 3, 5, 12, 8 },
  205. {28, 2, 5, 28, 5 },
  206. {29, 3, 5, 11, 8 },
  207. {30, 3, 5, 10, 8 },
  208. {31, 3, 5, 7, 4 },
  209. {32, 7, 4 },
  210. {33, 10, 8 },
  211. {34, 11, 8 },
  212. {35, 2, 5, 3, 5 },
  213. {36, 12, 8 },
  214. {37, 2, 5, 5, 5 },
  215. {38, 2, 5, 6, 5 },
  216. {39, 3, 5, 9, 8 },
  217. {40, 13, 8 },
  218. {41, 2, 5, 9, 5 },
  219. {42, 2, 5, 10, 5 },
  220. {43, 3, 5, 8, 8 },
  221. {44, 2, 5, 12, 5 },
  222. {45, 3, 5, 7, 8 },
  223. {46, 3, 5, 6, 8 },
  224. {47, 3, 5, 6, 4 },
  225. {48, 14, 8 },
  226. {49, 2, 5, 17, 5 },
  227. {50, 2, 5, 18, 5 },
  228. {51, 3, 5, 5, 8 },
  229. {52, 2, 5, 20, 5 },
  230. {53, 3, 5, 4, 8 },
  231. {54, 3, 5, 3, 8 },
  232. {55, 3, 5, 5, 4 },
  233. {56, 2, 5, 24, 5 },
  234. {57, 3, 5, 2, 8 },
  235. {58, 3, 5, 1, 8 },
  236. {59, 3, 5, 4, 4 },
  237. {60, 3, 5, 0, 8 },
  238. {61, 3, 5, 3, 4 },
  239. {62, 3, 5, 2, 4 },
  240. {63, 3, 5, 1, 1 },
  241. };
  242. #endif
  243. /* 4MV Block pattern VLC tables */
  244. const uint8_t ff_vc1_4mv_block_pattern_codes[4][16] = {
  245. { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2},
  246. { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0},
  247. { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0},
  248. { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10}
  249. };
  250. const uint8_t ff_vc1_4mv_block_pattern_bits[4][16] = {
  251. { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2},
  252. { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2},
  253. { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3},
  254. { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4}
  255. };
  256. const uint8_t wmv3_dc_scale_table[32]={
  257. 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21
  258. };
  259. /* P-Picture CBPCY VLC tables */
  260. #if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV?
  261. const uint16_t ff_vc1_cbpcy_p_codes[4][64] = {
  262. {
  263. 0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119,
  264. 1, 54, 96, 8, 10, 111, 5, 15, 12, 10, 2, 12, 13, 115, 53, 63,
  265. 1, 7, 1, 7, 14, 12, 4, 14, 1, 9, 97, 11, 7, 58, 52, 62,
  266. 4, 103, 1, 9, 11, 56, 101, 118, 4, 110, 100, 30, 2, 5, 4, 3
  267. },
  268. {
  269. 0, 9, 1, 18, 5, 14, 237, 26, 3, 121, 3, 22, 13, 16, 6, 30,
  270. 2, 10, 1, 20, 12, 241, 5, 28, 16, 12, 3, 24, 28, 124, 239, 247,
  271. 1, 240, 1, 19, 18, 15, 4, 27, 1, 122, 2, 23, 1, 17, 7, 31,
  272. 1, 11, 2, 21, 19, 246, 238, 29, 17, 13, 236, 25, 58, 63, 8, 125
  273. },
  274. {
  275. 0, 201, 25, 231, 5, 221, 1, 3, 2, 414, 2, 241, 16, 225, 195, 492,
  276. 2, 412, 1, 240, 7, 224, 98, 245, 1, 220, 96, 5, 9, 230, 101, 247,
  277. 1, 102, 1, 415, 24, 3, 2, 244, 3, 54, 3, 484, 17, 114, 200, 493,
  278. 3, 413, 1, 4, 13, 113, 99, 485, 4, 111, 194, 243, 5, 29, 26, 31
  279. },
  280. {
  281. 0, 28, 12, 44, 3, 36, 20, 52, 2, 32, 16, 48, 8, 40, 24, 28,
  282. 1, 30, 14, 46, 6, 38, 22, 54, 3, 34, 18, 50, 10, 42, 26, 30,
  283. 1, 29, 13, 45, 5, 37, 21, 53, 2, 33, 17, 49, 9, 41, 25, 29,
  284. 1, 31, 15, 47, 7, 39, 23, 55, 4, 35, 19, 51, 11, 43, 27, 31
  285. }
  286. };
  287. const uint8_t ff_vc1_cbpcy_p_bits[4][64] = {
  288. {
  289. 13, 13, 7, 13, 7, 13, 13, 12, 6, 13, 7, 12, 6, 8, 8, 8,
  290. 5, 7, 8, 12, 6, 8, 13, 12, 7, 13, 13, 12, 6, 8, 7, 7,
  291. 6, 13, 8, 12, 7, 13, 13, 12, 7, 13, 8, 12, 5, 7, 7, 7,
  292. 6, 8, 13, 12, 6, 7, 8, 8, 5, 8, 8, 6, 3, 3, 3, 2
  293. },
  294. {
  295. 14, 13, 8, 13, 3, 13, 8, 13, 3, 7, 8, 13, 4, 13, 13, 13,
  296. 3, 13, 13, 13, 4, 8, 13, 13, 5, 13, 13, 13, 5, 7, 8, 8,
  297. 3, 8, 14, 13, 5, 13, 13, 13, 4, 7, 13, 13, 6, 13, 13, 13,
  298. 5, 13, 8, 13, 5, 8, 8, 13, 5, 13, 8, 13, 6, 6, 13, 7
  299. },
  300. {
  301. 13, 8, 6, 8, 4, 8, 13, 12, 4, 9, 8, 8, 5, 8, 8, 9,
  302. 5, 9, 10, 8, 4, 8, 7, 8, 6, 8, 7, 13, 4, 8, 7, 8,
  303. 5, 7, 8, 9, 6, 13, 13, 8, 4, 6, 8, 9, 5, 7, 8, 9,
  304. 5, 9, 9, 13, 5, 7, 7, 9, 4, 7, 8, 8, 3, 5, 5, 5
  305. },
  306. {
  307. 9, 9, 9, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 8,
  308. 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  309. 2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  310. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8
  311. }
  312. };
  313. #else
  314. const uint16_t ff_vc1_cbpcy_p_codes[4][64] = {
  315. {
  316. 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2,
  317. 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4,
  318. 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5,
  319. 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3
  320. },
  321. {
  322. 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58,
  323. 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8,
  324. 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63,
  325. 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125
  326. },
  327. {
  328. 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5,
  329. 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26,
  330. 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29,
  331. 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31
  332. },
  333. {
  334. 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11,
  335. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
  336. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
  337. 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31
  338. }
  339. };
  340. const uint8_t ff_vc1_cbpcy_p_bits[4][64] = {
  341. {
  342. 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3,
  343. 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3,
  344. 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3,
  345. 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2
  346. },
  347. {
  348. 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6,
  349. 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13,
  350. 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6,
  351. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7
  352. },
  353. {
  354. 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3,
  355. 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5,
  356. 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5,
  357. 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5
  358. },
  359. {
  360. 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9,
  361. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  362. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  363. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8
  364. }
  365. };
  366. #endif
  367. /* MacroBlock Transform Type: 7.1.3.11, p89
  368. * 8x8:B
  369. * 8x4:B:btm 8x4:B:top 8x4:B:both,
  370. * 4x8:B:right 4x8:B:left 4x8:B:both
  371. * 4x4:B 8x8:MB
  372. * 8x4:MB:btm 8x4:MB:top 8x4,MB,both
  373. * 4x8,MB,right 4x8,MB,left
  374. * 4x4,MB */
  375. const uint16_t ff_vc1_ttmb_codes[3][16] = {
  376. {
  377. 0x0003,
  378. 0x002E, 0x005F, 0x0000,
  379. 0x0016, 0x0015, 0x0001,
  380. 0x0004, 0x0014,
  381. 0x02F1, 0x0179, 0x017B,
  382. 0x0BC0, 0x0BC1, 0x05E1,
  383. 0x017A
  384. },
  385. {
  386. 0x0006,
  387. 0x0006, 0x0003, 0x0007,
  388. 0x000F, 0x000E, 0x0000,
  389. 0x0002, 0x0002,
  390. 0x0014, 0x0011, 0x000B,
  391. 0x0009, 0x0021, 0x0015,
  392. 0x0020
  393. },
  394. {
  395. 0x0006,
  396. 0x0000, 0x000E, 0x0005,
  397. 0x0002, 0x0003, 0x0003,
  398. 0x000F, 0x0002,
  399. 0x0081, 0x0021, 0x0009,
  400. 0x0101, 0x0041, 0x0011,
  401. 0x0100
  402. }
  403. };
  404. const uint8_t ff_vc1_ttmb_bits[3][16] = {
  405. {
  406. 2,
  407. 6, 7, 2,
  408. 5, 5, 2,
  409. 3, 5,
  410. 10, 9, 9,
  411. 12, 12, 11,
  412. 9
  413. },
  414. {
  415. 3,
  416. 4, 4, 4,
  417. 4, 4, 3,
  418. 3, 2,
  419. 7, 7, 6,
  420. 6, 8, 7,
  421. 8
  422. },
  423. {
  424. 3,
  425. 3, 4, 5,
  426. 3, 3, 4,
  427. 4, 2,
  428. 10, 8, 6,
  429. 11, 9, 7,
  430. 11
  431. }
  432. };
  433. /* TTBLK (Transform Type per Block) tables */
  434. const uint8_t ff_vc1_ttblk_codes[3][8] = {
  435. { 0, 1, 3, 5, 16, 17, 18, 19},
  436. { 3, 0, 1, 2, 3, 5, 8, 9},
  437. { 1, 0, 1, 4, 6, 7, 10, 11}
  438. };
  439. const uint8_t ff_vc1_ttblk_bits[3][8] = {
  440. { 2, 2, 2, 3, 5, 5, 5, 5},
  441. { 2, 3, 3, 3, 3, 3, 4, 4},
  442. { 2, 3, 3, 3, 3, 3, 4, 4}
  443. };
  444. /* SUBBLKPAT tables, p93-94, reordered */
  445. const uint8_t ff_vc1_subblkpat_codes[3][15] = {
  446. { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1},
  447. { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1},
  448. { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15}
  449. };
  450. const uint8_t ff_vc1_subblkpat_bits[3][15] = {
  451. { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1},
  452. { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2},
  453. { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4}
  454. };
  455. /* MV differential tables, p265 */
  456. const uint16_t ff_vc1_mv_diff_codes[4][73] = {
  457. {
  458. 0, 2, 3, 8, 576, 3, 2, 6,
  459. 5, 577, 578, 7, 8, 9, 40, 19,
  460. 37, 82, 21, 22, 23, 579, 580, 166,
  461. 96, 167, 49, 194, 195, 581, 582, 583,
  462. 292, 293, 294, 13, 2, 7, 24, 50,
  463. 102, 295, 13, 7, 8, 18, 50, 103,
  464. 38, 20, 21, 22, 39, 204, 103, 23,
  465. 24, 25, 104, 410, 105, 106, 107, 108,
  466. 109, 220, 411, 442, 222, 443, 446, 447,
  467. 7 /* 73 elements */
  468. },
  469. {
  470. 0, 4, 5, 3, 4, 3, 4, 5,
  471. 20, 6, 21, 44, 45, 46, 3008, 95,
  472. 112, 113, 57, 3009, 3010, 116, 117, 3011,
  473. 118, 3012, 3013, 3014, 3015, 3016, 3017, 3018,
  474. 3019, 3020, 3021, 3022, 1, 4, 15, 160,
  475. 161, 41, 6, 11, 42, 162, 43, 119,
  476. 56, 57, 58, 163, 236, 237, 3023, 119,
  477. 120, 242, 122, 486, 1512, 487, 246, 494,
  478. 1513, 495, 1514, 1515, 1516, 1517, 1518, 1519,
  479. 31 /* 73 elements */
  480. },
  481. {
  482. 0, 512, 513, 514, 515, 2, 3, 258,
  483. 259, 260, 261, 262, 263, 264, 265, 266,
  484. 267, 268, 269, 270, 271, 272, 273, 274,
  485. 275, 276, 277, 278, 279, 280, 281, 282,
  486. 283, 284, 285, 286, 1, 5, 287, 288,
  487. 289, 290, 6, 7, 291, 292, 293, 294,
  488. 295, 296, 297, 298, 299, 300, 301, 302,
  489. 303, 304, 305, 306, 307, 308, 309, 310,
  490. 311, 312, 313, 314, 315, 316, 317, 318,
  491. 319 /* 73 elements */
  492. },
  493. {
  494. 0, 1, 1, 2, 3, 4, 1, 5,
  495. 4, 3, 5, 8, 6, 9, 10, 11,
  496. 12, 7, 104, 14, 105, 4, 10, 15,
  497. 11, 6, 14, 8, 106, 107, 108, 15,
  498. 109, 9, 55, 10, 1, 2, 1, 2,
  499. 3, 12, 6, 2, 6, 7, 28, 7,
  500. 15, 8, 5, 18, 29, 152, 77, 24,
  501. 25, 26, 39, 108, 13, 109, 55, 56,
  502. 57, 116, 11, 153, 234, 235, 118, 119,
  503. 15 /* 73 elements */
  504. }
  505. };
  506. const uint8_t ff_vc1_mv_diff_bits[4][73] = {
  507. {
  508. 6, 7, 7, 8, 14, 6, 5, 6, 7, 14, 14, 6, 6, 6, 8, 9,
  509. 10, 9, 7, 7, 7, 14, 14, 10, 9, 10, 8, 10, 10, 14, 14, 14,
  510. 13, 13, 13, 6, 3, 5, 6, 8, 9, 13, 5, 4, 4, 5, 7, 9,
  511. 6, 5, 5, 5, 6, 9, 8, 5, 5, 5, 7, 10, 7, 7, 7, 7,
  512. 7, 8, 10, 9, 8, 9, 9, 9, 3 /* 73 elements */
  513. },
  514. {
  515. 5, 7, 7, 6, 6, 5, 5, 6, 7, 5, 7, 8, 8, 8, 14, 9,
  516. 9, 9, 8, 14, 14, 9, 9, 14, 9, 14, 14, 14, 14, 14, 14, 14,
  517. 14, 14, 14, 14, 2, 3, 6, 8, 8, 6, 3, 4, 6, 8, 6, 9,
  518. 6, 6, 6, 8, 8, 8, 14, 7, 7, 8, 7, 9, 13, 9, 8, 9,
  519. 13, 9, 13, 13, 13, 13, 13, 13, 5 /* 73 elements */
  520. },
  521. {
  522. 3, 12, 12, 12, 12, 3, 4, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  523. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  524. 11, 11, 11, 11, 1, 5, 11, 11, 11, 11, 4, 4, 11, 11, 11, 11,
  525. 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  526. 11, 11, 11, 11, 11, 11, 11, 11, 11 /* 73 elements */
  527. },
  528. {
  529. 15, 11, 15, 15, 15, 15, 12, 15, 12, 11, 12, 12, 15, 12, 12, 12,
  530. 12, 15, 15, 12, 15, 10, 11, 12, 11, 10, 11, 10, 15, 15, 15, 11,
  531. 15, 10, 14, 10, 4, 4, 5, 7, 8, 9, 5, 3, 4, 5, 6, 8,
  532. 5, 4, 3, 5, 6, 8, 7, 5, 5, 5, 6, 7, 9, 7, 6, 6,
  533. 6, 7, 10, 8, 8, 8, 7, 7, 4 /* 73 elements */
  534. }
  535. };
  536. /* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
  537. /* Table 232 */
  538. const int8_t ff_vc1_simple_progressive_4x4_zz [16] =
  539. {
  540. 0, 8, 16, 1,
  541. 9, 24, 17, 2,
  542. 10, 18, 25, 3,
  543. 11, 26, 19, 27
  544. };
  545. const int8_t ff_vc1_adv_progressive_8x4_zz [32] = /* Table 233 */
  546. {
  547. 0, 8, 1, 16, 2, 9, 10, 3,
  548. 24, 17, 4, 11, 18, 12, 5, 19,
  549. 25, 13, 20, 26, 27, 6, 21, 28,
  550. 14, 22, 29, 7, 30, 15, 23, 31
  551. };
  552. const int8_t ff_vc1_adv_progressive_4x8_zz [32] = /* Table 234 */
  553. {
  554. 0, 1, 8, 2,
  555. 9, 16, 17, 24,
  556. 10, 32, 25, 18,
  557. 40, 3, 33, 26,
  558. 48, 11, 56, 41,
  559. 34, 49, 57, 42,
  560. 19, 50, 27, 58,
  561. 35, 43, 51, 59
  562. };
  563. const int8_t ff_vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */
  564. {
  565. 0, 8, 1, 16, 24, 9, 2, 32,
  566. 40, 48, 56, 17, 10, 3, 25, 18,
  567. 11, 4, 33, 41, 49, 57, 26, 34,
  568. 42, 50, 58, 19, 12, 5, 27, 20,
  569. 13, 6, 35, 28, 21, 14, 7, 15,
  570. 22, 29, 36, 43, 51, 59, 60, 52,
  571. 44, 37, 30, 23, 31, 38, 45, 53,
  572. 61, 62, 54, 46, 39, 47, 55, 63
  573. };
  574. const int8_t ff_vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */
  575. {
  576. 0, 8, 16, 24, 1, 9, 2, 17,
  577. 25, 10, 3, 18, 26, 4, 11, 19,
  578. 12, 5, 13, 20, 27, 6, 21, 28,
  579. 14, 22, 29, 7, 30, 15, 23, 31
  580. };
  581. const int8_t ff_vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */
  582. {
  583. 0, 1, 2, 8,
  584. 16, 9, 24, 17,
  585. 10, 3, 32, 40,
  586. 48, 56, 25, 18,
  587. 33, 26, 41, 34,
  588. 49, 57, 11, 42,
  589. 19, 50, 27, 58,
  590. 35, 43, 51, 59
  591. };
  592. const int8_t ff_vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */
  593. {
  594. 0, 8, 16, 24,
  595. 1, 9, 17, 2,
  596. 25, 10, 18, 3,
  597. 26, 11, 19, 27
  598. };
  599. /* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
  600. const int32_t ff_vc1_dqscale[63] = {
  601. 0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000,
  602. 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000,
  603. 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB,
  604. 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000,
  605. 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A,
  606. 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555,
  607. 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249,
  608. 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000
  609. };