macroblock.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*****************************************************************************
  2. * macroblock.h: macroblock common functions
  3. *****************************************************************************
  4. * Copyright (C) 2005-2018 x264 project
  5. *
  6. * Authors: Loren Merritt <lorenm@u.washington.edu>
  7. * Laurent Aimar <fenrir@via.ecp.fr>
  8. * Fiona Glaser <fiona@x264.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  23. *
  24. * This program is also available under a commercial proprietary license.
  25. * For more information, contact us at licensing@x264.com.
  26. *****************************************************************************/
  27. #ifndef X264_MACROBLOCK_H
  28. #define X264_MACROBLOCK_H
  29. enum macroblock_position_e
  30. {
  31. MB_LEFT = 0x01,
  32. MB_TOP = 0x02,
  33. MB_TOPRIGHT = 0x04,
  34. MB_TOPLEFT = 0x08,
  35. MB_PRIVATE = 0x10,
  36. ALL_NEIGHBORS = 0xf,
  37. };
  38. static const uint8_t x264_pred_i4x4_neighbors[12] =
  39. {
  40. MB_TOP, // I_PRED_4x4_V
  41. MB_LEFT, // I_PRED_4x4_H
  42. MB_LEFT | MB_TOP, // I_PRED_4x4_DC
  43. MB_TOP | MB_TOPRIGHT, // I_PRED_4x4_DDL
  44. MB_LEFT | MB_TOPLEFT | MB_TOP, // I_PRED_4x4_DDR
  45. MB_LEFT | MB_TOPLEFT | MB_TOP, // I_PRED_4x4_VR
  46. MB_LEFT | MB_TOPLEFT | MB_TOP, // I_PRED_4x4_HD
  47. MB_TOP | MB_TOPRIGHT, // I_PRED_4x4_VL
  48. MB_LEFT, // I_PRED_4x4_HU
  49. MB_LEFT, // I_PRED_4x4_DC_LEFT
  50. MB_TOP, // I_PRED_4x4_DC_TOP
  51. 0 // I_PRED_4x4_DC_128
  52. };
  53. /* XXX mb_type isn't the one written in the bitstream -> only internal usage */
  54. #define IS_INTRA(type) ( (type) == I_4x4 || (type) == I_8x8 || (type) == I_16x16 || (type) == I_PCM )
  55. #define IS_SKIP(type) ( (type) == P_SKIP || (type) == B_SKIP )
  56. #define IS_DIRECT(type) ( (type) == B_DIRECT )
  57. enum mb_class_e
  58. {
  59. I_4x4 = 0,
  60. I_8x8 = 1,
  61. I_16x16 = 2,
  62. I_PCM = 3,
  63. P_L0 = 4,
  64. P_8x8 = 5,
  65. P_SKIP = 6,
  66. B_DIRECT = 7,
  67. B_L0_L0 = 8,
  68. B_L0_L1 = 9,
  69. B_L0_BI = 10,
  70. B_L1_L0 = 11,
  71. B_L1_L1 = 12,
  72. B_L1_BI = 13,
  73. B_BI_L0 = 14,
  74. B_BI_L1 = 15,
  75. B_BI_BI = 16,
  76. B_8x8 = 17,
  77. B_SKIP = 18,
  78. X264_MBTYPE_MAX = 19
  79. };
  80. static const uint8_t x264_mb_type_fix[X264_MBTYPE_MAX] =
  81. {
  82. I_4x4, I_4x4, I_16x16, I_PCM,
  83. P_L0, P_8x8, P_SKIP,
  84. B_DIRECT, B_L0_L0, B_L0_L1, B_L0_BI, B_L1_L0, B_L1_L1,
  85. B_L1_BI, B_BI_L0, B_BI_L1, B_BI_BI, B_8x8, B_SKIP
  86. };
  87. static const uint8_t x264_mb_type_list_table[X264_MBTYPE_MAX][2][2] =
  88. {
  89. {{0,0},{0,0}}, {{0,0},{0,0}}, {{0,0},{0,0}}, {{0,0},{0,0}}, /* INTRA */
  90. {{1,1},{0,0}}, /* P_L0 */
  91. {{0,0},{0,0}}, /* P_8x8 */
  92. {{1,1},{0,0}}, /* P_SKIP */
  93. {{0,0},{0,0}}, /* B_DIRECT */
  94. {{1,1},{0,0}}, {{1,0},{0,1}}, {{1,1},{0,1}}, /* B_L0_* */
  95. {{0,1},{1,0}}, {{0,0},{1,1}}, {{0,1},{1,1}}, /* B_L1_* */
  96. {{1,1},{1,0}}, {{1,0},{1,1}}, {{1,1},{1,1}}, /* B_BI_* */
  97. {{0,0},{0,0}}, /* B_8x8 */
  98. {{0,0},{0,0}} /* B_SKIP */
  99. };
  100. #define IS_SUB4x4(type) ( (type == D_L0_4x4)||(type == D_L1_4x4)||(type == D_BI_4x4) )
  101. #define IS_SUB4x8(type) ( (type == D_L0_4x8)||(type == D_L1_4x8)||(type == D_BI_4x8) )
  102. #define IS_SUB8x4(type) ( (type == D_L0_8x4)||(type == D_L1_8x4)||(type == D_BI_8x4) )
  103. #define IS_SUB8x8(type) ( (type == D_L0_8x8)||(type == D_L1_8x8)||(type == D_BI_8x8)||(type == D_DIRECT_8x8) )
  104. enum mb_partition_e
  105. {
  106. /* sub partition type for P_8x8 and B_8x8 */
  107. D_L0_4x4 = 0,
  108. D_L0_8x4 = 1,
  109. D_L0_4x8 = 2,
  110. D_L0_8x8 = 3,
  111. /* sub partition type for B_8x8 only */
  112. D_L1_4x4 = 4,
  113. D_L1_8x4 = 5,
  114. D_L1_4x8 = 6,
  115. D_L1_8x8 = 7,
  116. D_BI_4x4 = 8,
  117. D_BI_8x4 = 9,
  118. D_BI_4x8 = 10,
  119. D_BI_8x8 = 11,
  120. D_DIRECT_8x8 = 12,
  121. /* partition */
  122. D_8x8 = 13,
  123. D_16x8 = 14,
  124. D_8x16 = 15,
  125. D_16x16 = 16,
  126. X264_PARTTYPE_MAX = 17,
  127. };
  128. static const uint8_t x264_mb_partition_listX_table[2][17] =
  129. {{
  130. 1, 1, 1, 1, /* D_L0_* */
  131. 0, 0, 0, 0, /* D_L1_* */
  132. 1, 1, 1, 1, /* D_BI_* */
  133. 0, /* D_DIRECT_8x8 */
  134. 0, 0, 0, 0 /* 8x8 .. 16x16 */
  135. },
  136. {
  137. 0, 0, 0, 0, /* D_L0_* */
  138. 1, 1, 1, 1, /* D_L1_* */
  139. 1, 1, 1, 1, /* D_BI_* */
  140. 0, /* D_DIRECT_8x8 */
  141. 0, 0, 0, 0 /* 8x8 .. 16x16 */
  142. }};
  143. static const uint8_t x264_mb_partition_count_table[17] =
  144. {
  145. /* sub L0 */
  146. 4, 2, 2, 1,
  147. /* sub L1 */
  148. 4, 2, 2, 1,
  149. /* sub BI */
  150. 4, 2, 2, 1,
  151. /* Direct */
  152. 1,
  153. /* Partition */
  154. 4, 2, 2, 1
  155. };
  156. static const uint8_t x264_mb_partition_pixel_table[17] =
  157. {
  158. PIXEL_4x4, PIXEL_8x4, PIXEL_4x8, PIXEL_8x8, /* D_L0_* */
  159. PIXEL_4x4, PIXEL_8x4, PIXEL_4x8, PIXEL_8x8, /* D_L1_* */
  160. PIXEL_4x4, PIXEL_8x4, PIXEL_4x8, PIXEL_8x8, /* D_BI_* */
  161. PIXEL_8x8, /* D_DIRECT_8x8 */
  162. PIXEL_8x8, PIXEL_16x8, PIXEL_8x16, PIXEL_16x16, /* 8x8 .. 16x16 */
  163. };
  164. /* zigzags are transposed with respect to the tables in the standard */
  165. static const uint8_t x264_zigzag_scan4[2][16] =
  166. {{ // frame
  167. 0, 4, 1, 2, 5, 8, 12, 9, 6, 3, 7, 10, 13, 14, 11, 15
  168. },
  169. { // field
  170. 0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  171. }};
  172. static const uint8_t x264_zigzag_scan8[2][64] =
  173. {{
  174. 0, 8, 1, 2, 9, 16, 24, 17, 10, 3, 4, 11, 18, 25, 32, 40,
  175. 33, 26, 19, 12, 5, 6, 13, 20, 27, 34, 41, 48, 56, 49, 42, 35,
  176. 28, 21, 14, 7, 15, 22, 29, 36, 43, 50, 57, 58, 51, 44, 37, 30,
  177. 23, 31, 38, 45, 52, 59, 60, 53, 46, 39, 47, 54, 61, 62, 55, 63
  178. },
  179. {
  180. 0, 1, 2, 8, 9, 3, 4, 10, 16, 11, 5, 6, 7, 12, 17, 24,
  181. 18, 13, 14, 15, 19, 25, 32, 26, 20, 21, 22, 23, 27, 33, 40, 34,
  182. 28, 29, 30, 31, 35, 41, 48, 42, 36, 37, 38, 39, 43, 49, 50, 44,
  183. 45, 46, 47, 51, 56, 57, 52, 53, 54, 55, 58, 59, 60, 61, 62, 63
  184. }};
  185. static const uint8_t block_idx_x[16] =
  186. {
  187. 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3
  188. };
  189. static const uint8_t block_idx_y[16] =
  190. {
  191. 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3
  192. };
  193. static const uint8_t block_idx_xy[4][4] =
  194. {
  195. { 0, 2, 8, 10 },
  196. { 1, 3, 9, 11 },
  197. { 4, 6, 12, 14 },
  198. { 5, 7, 13, 15 }
  199. };
  200. static const uint8_t block_idx_xy_1d[16] =
  201. {
  202. 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15
  203. };
  204. static const uint8_t block_idx_yx_1d[16] =
  205. {
  206. 0, 4, 1, 5, 8, 12, 9, 13, 2, 6, 3, 7, 10, 14, 11, 15
  207. };
  208. static const uint8_t block_idx_xy_fenc[16] =
  209. {
  210. 0*4 + 0*4*FENC_STRIDE, 1*4 + 0*4*FENC_STRIDE,
  211. 0*4 + 1*4*FENC_STRIDE, 1*4 + 1*4*FENC_STRIDE,
  212. 2*4 + 0*4*FENC_STRIDE, 3*4 + 0*4*FENC_STRIDE,
  213. 2*4 + 1*4*FENC_STRIDE, 3*4 + 1*4*FENC_STRIDE,
  214. 0*4 + 2*4*FENC_STRIDE, 1*4 + 2*4*FENC_STRIDE,
  215. 0*4 + 3*4*FENC_STRIDE, 1*4 + 3*4*FENC_STRIDE,
  216. 2*4 + 2*4*FENC_STRIDE, 3*4 + 2*4*FENC_STRIDE,
  217. 2*4 + 3*4*FENC_STRIDE, 3*4 + 3*4*FENC_STRIDE
  218. };
  219. static const uint16_t block_idx_xy_fdec[16] =
  220. {
  221. 0*4 + 0*4*FDEC_STRIDE, 1*4 + 0*4*FDEC_STRIDE,
  222. 0*4 + 1*4*FDEC_STRIDE, 1*4 + 1*4*FDEC_STRIDE,
  223. 2*4 + 0*4*FDEC_STRIDE, 3*4 + 0*4*FDEC_STRIDE,
  224. 2*4 + 1*4*FDEC_STRIDE, 3*4 + 1*4*FDEC_STRIDE,
  225. 0*4 + 2*4*FDEC_STRIDE, 1*4 + 2*4*FDEC_STRIDE,
  226. 0*4 + 3*4*FDEC_STRIDE, 1*4 + 3*4*FDEC_STRIDE,
  227. 2*4 + 2*4*FDEC_STRIDE, 3*4 + 2*4*FDEC_STRIDE,
  228. 2*4 + 3*4*FDEC_STRIDE, 3*4 + 3*4*FDEC_STRIDE
  229. };
  230. #define QP(qP) ( (qP)+QP_BD_OFFSET )
  231. static const uint8_t i_chroma_qp_table[QP_MAX+1+12*2] =
  232. {
  233. 0, 0, 0, 0, 0, 0,
  234. 0, 0, 0, 0, 0, 0,
  235. #if BIT_DEPTH > 9
  236. QP(-12),QP(-11),QP(-10), QP(-9), QP(-8), QP(-7),
  237. #endif
  238. #if BIT_DEPTH > 8
  239. QP(-6), QP(-5), QP(-4), QP(-3), QP(-2), QP(-1),
  240. #endif
  241. QP(0), QP(1), QP(2), QP(3), QP(4), QP(5),
  242. QP(6), QP(7), QP(8), QP(9), QP(10), QP(11),
  243. QP(12), QP(13), QP(14), QP(15), QP(16), QP(17),
  244. QP(18), QP(19), QP(20), QP(21), QP(22), QP(23),
  245. QP(24), QP(25), QP(26), QP(27), QP(28), QP(29),
  246. QP(29), QP(30), QP(31), QP(32), QP(32), QP(33),
  247. QP(34), QP(34), QP(35), QP(35), QP(36), QP(36),
  248. QP(37), QP(37), QP(37), QP(38), QP(38), QP(38),
  249. QP(39), QP(39), QP(39), QP(39),
  250. QP(39), QP(39), QP(39), QP(39), QP(39), QP(39),
  251. QP(39), QP(39), QP(39), QP(39), QP(39), QP(39),
  252. };
  253. #undef QP
  254. enum cabac_ctx_block_cat_e
  255. {
  256. DCT_LUMA_DC = 0,
  257. DCT_LUMA_AC = 1,
  258. DCT_LUMA_4x4 = 2,
  259. DCT_CHROMA_DC = 3,
  260. DCT_CHROMA_AC = 4,
  261. DCT_LUMA_8x8 = 5,
  262. DCT_CHROMAU_DC = 6,
  263. DCT_CHROMAU_AC = 7,
  264. DCT_CHROMAU_4x4 = 8,
  265. DCT_CHROMAU_8x8 = 9,
  266. DCT_CHROMAV_DC = 10,
  267. DCT_CHROMAV_AC = 11,
  268. DCT_CHROMAV_4x4 = 12,
  269. DCT_CHROMAV_8x8 = 13,
  270. };
  271. static const uint8_t ctx_cat_plane[6][3] =
  272. {
  273. { DCT_LUMA_DC, DCT_CHROMAU_DC, DCT_CHROMAV_DC},
  274. { DCT_LUMA_AC, DCT_CHROMAU_AC, DCT_CHROMAV_AC},
  275. {DCT_LUMA_4x4, DCT_CHROMAU_4x4, DCT_CHROMAV_4x4},
  276. {0},
  277. {0},
  278. {DCT_LUMA_8x8, DCT_CHROMAU_8x8, DCT_CHROMAV_8x8}
  279. };
  280. /* Per-frame allocation: is allocated per-thread only in frame-threads mode. */
  281. #define x264_macroblock_cache_allocate x264_template(macroblock_cache_allocate)
  282. int x264_macroblock_cache_allocate( x264_t *h );
  283. #define x264_macroblock_cache_free x264_template(macroblock_cache_free)
  284. void x264_macroblock_cache_free( x264_t *h );
  285. /* Per-thread allocation: is allocated per-thread even in sliced-threads mode. */
  286. #define x264_macroblock_thread_allocate x264_template(macroblock_thread_allocate)
  287. int x264_macroblock_thread_allocate( x264_t *h, int b_lookahead );
  288. #define x264_macroblock_thread_free x264_template(macroblock_thread_free)
  289. void x264_macroblock_thread_free( x264_t *h, int b_lookahead );
  290. #define x264_macroblock_slice_init x264_template(macroblock_slice_init)
  291. void x264_macroblock_slice_init( x264_t *h );
  292. #define x264_macroblock_thread_init x264_template(macroblock_thread_init)
  293. void x264_macroblock_thread_init( x264_t *h );
  294. #define x264_macroblock_cache_load_interlaced x264_template(macroblock_cache_load_interlaced)
  295. void x264_macroblock_cache_load_progressive( x264_t *h, int mb_x, int mb_y );
  296. #define x264_macroblock_cache_load_progressive x264_template(macroblock_cache_load_progressive)
  297. void x264_macroblock_cache_load_interlaced( x264_t *h, int mb_x, int mb_y );
  298. #define x264_macroblock_deblock_strength x264_template(macroblock_deblock_strength)
  299. void x264_macroblock_deblock_strength( x264_t *h );
  300. #define x264_macroblock_cache_save x264_template(macroblock_cache_save)
  301. void x264_macroblock_cache_save( x264_t *h );
  302. #define x264_macroblock_bipred_init x264_template(macroblock_bipred_init)
  303. void x264_macroblock_bipred_init( x264_t *h );
  304. #define x264_prefetch_fenc x264_template(prefetch_fenc)
  305. void x264_prefetch_fenc( x264_t *h, x264_frame_t *fenc, int i_mb_x, int i_mb_y );
  306. #define x264_copy_column8 x264_template(copy_column8)
  307. void x264_copy_column8( pixel *dst, pixel *src );
  308. /* x264_mb_predict_mv_16x16:
  309. * set mvp with predicted mv for D_16x16 block
  310. * h->mb. need only valid values from other blocks */
  311. #define x264_mb_predict_mv_16x16 x264_template(mb_predict_mv_16x16)
  312. void x264_mb_predict_mv_16x16( x264_t *h, int i_list, int i_ref, int16_t mvp[2] );
  313. /* x264_mb_predict_mv_pskip:
  314. * set mvp with predicted mv for P_SKIP
  315. * h->mb. need only valid values from other blocks */
  316. #define x264_mb_predict_mv_pskip x264_template(mb_predict_mv_pskip)
  317. void x264_mb_predict_mv_pskip( x264_t *h, int16_t mv[2] );
  318. /* x264_mb_predict_mv:
  319. * set mvp with predicted mv for all blocks except SKIP and DIRECT
  320. * h->mb. need valid ref/partition/sub of current block to be valid
  321. * and valid mv/ref from other blocks. */
  322. #define x264_mb_predict_mv x264_template(mb_predict_mv)
  323. void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int16_t mvp[2] );
  324. /* x264_mb_predict_mv_direct16x16:
  325. * set h->mb.cache.mv and h->mb.cache.ref for B_SKIP or B_DIRECT
  326. * h->mb. need only valid values from other blocks.
  327. * return 1 on success, 0 on failure.
  328. * if b_changed != NULL, set it to whether refs or mvs differ from
  329. * before this functioncall. */
  330. #define x264_mb_predict_mv_direct16x16 x264_template(mb_predict_mv_direct16x16)
  331. int x264_mb_predict_mv_direct16x16( x264_t *h, int *b_changed );
  332. /* x264_mb_predict_mv_ref16x16:
  333. * set mvc with D_16x16 prediction.
  334. * uses all neighbors, even those that didn't end up using this ref.
  335. * h->mb. need only valid values from other blocks */
  336. #define x264_mb_predict_mv_ref16x16 x264_template(mb_predict_mv_ref16x16)
  337. void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t mvc[8][2], int *i_mvc );
  338. #define x264_mb_mc x264_template(mb_mc)
  339. void x264_mb_mc( x264_t *h );
  340. #define x264_mb_mc_8x8 x264_template(mb_mc_8x8)
  341. void x264_mb_mc_8x8( x264_t *h, int i8 );
  342. static ALWAYS_INLINE uint32_t pack16to32( uint32_t a, uint32_t b )
  343. {
  344. #if WORDS_BIGENDIAN
  345. return b + (a<<16);
  346. #else
  347. return a + (b<<16);
  348. #endif
  349. }
  350. static ALWAYS_INLINE uint32_t pack8to16( uint32_t a, uint32_t b )
  351. {
  352. #if WORDS_BIGENDIAN
  353. return b + (a<<8);
  354. #else
  355. return a + (b<<8);
  356. #endif
  357. }
  358. static ALWAYS_INLINE uint32_t pack8to32( uint32_t a, uint32_t b, uint32_t c, uint32_t d )
  359. {
  360. #if WORDS_BIGENDIAN
  361. return d + (c<<8) + (b<<16) + (a<<24);
  362. #else
  363. return a + (b<<8) + (c<<16) + (d<<24);
  364. #endif
  365. }
  366. static ALWAYS_INLINE uint32_t pack16to32_mask( int a, int b )
  367. {
  368. #if WORDS_BIGENDIAN
  369. return (b&0xFFFF) + (a<<16);
  370. #else
  371. return (a&0xFFFF) + (b<<16);
  372. #endif
  373. }
  374. static ALWAYS_INLINE uint64_t pack32to64( uint32_t a, uint32_t b )
  375. {
  376. #if WORDS_BIGENDIAN
  377. return b + ((uint64_t)a<<32);
  378. #else
  379. return a + ((uint64_t)b<<32);
  380. #endif
  381. }
  382. #if HIGH_BIT_DEPTH
  383. # define pack_pixel_1to2 pack16to32
  384. # define pack_pixel_2to4 pack32to64
  385. #else
  386. # define pack_pixel_1to2 pack8to16
  387. # define pack_pixel_2to4 pack16to32
  388. #endif
  389. static ALWAYS_INLINE int x264_mb_predict_intra4x4_mode( x264_t *h, int idx )
  390. {
  391. const int ma = h->mb.cache.intra4x4_pred_mode[x264_scan8[idx] - 1];
  392. const int mb = h->mb.cache.intra4x4_pred_mode[x264_scan8[idx] - 8];
  393. const int m = X264_MIN( x264_mb_pred_mode4x4_fix(ma),
  394. x264_mb_pred_mode4x4_fix(mb) );
  395. if( m < 0 )
  396. return I_PRED_4x4_DC;
  397. return m;
  398. }
  399. static ALWAYS_INLINE int x264_mb_predict_non_zero_code( x264_t *h, int idx )
  400. {
  401. const int za = h->mb.cache.non_zero_count[x264_scan8[idx] - 1];
  402. const int zb = h->mb.cache.non_zero_count[x264_scan8[idx] - 8];
  403. int i_ret = za + zb;
  404. if( i_ret < 0x80 )
  405. i_ret = ( i_ret + 1 ) >> 1;
  406. return i_ret & 0x7f;
  407. }
  408. /* intra and skip are disallowed, p8x8 is conditional. */
  409. static const uint8_t x264_transform_allowed[X264_MBTYPE_MAX] =
  410. {
  411. 0,0,0,0,1,2,0,1,1,1,1,1,1,1,1,1,1,1,0
  412. };
  413. /* x264_mb_transform_8x8_allowed:
  414. * check whether any partition is smaller than 8x8 (or at least
  415. * might be, according to just partition type.)
  416. * doesn't check for cbp */
  417. static ALWAYS_INLINE int x264_mb_transform_8x8_allowed( x264_t *h )
  418. {
  419. if( !h->pps->b_transform_8x8_mode )
  420. return 0;
  421. if( h->mb.i_type != P_8x8 )
  422. return x264_transform_allowed[h->mb.i_type];
  423. return M32( h->mb.i_sub_partition ) == D_L0_8x8*0x01010101;
  424. }
  425. #endif