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.

160 lines
7.2KB

  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... decoder
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #undef MCFUNC
  22. #if CHROMA_IDC == 1
  23. # define MCFUNC(n) FUNC(n ## _420)
  24. #elif CHROMA_IDC == 2
  25. # define MCFUNC(n) FUNC(n ## _422)
  26. #elif CHROMA_IDC == 3
  27. # define MCFUNC(n) FUNC(n ## _444)
  28. #endif
  29. #undef mc_part
  30. #define mc_part MCFUNC(mc_part)
  31. static void mc_part(H264Context *h, int n, int square,
  32. int height, int delta,
  33. uint8_t *dest_y, uint8_t *dest_cb,
  34. uint8_t *dest_cr,
  35. int x_offset, int y_offset,
  36. qpel_mc_func *qpix_put,
  37. h264_chroma_mc_func chroma_put,
  38. qpel_mc_func *qpix_avg,
  39. h264_chroma_mc_func chroma_avg,
  40. h264_weight_func *weight_op,
  41. h264_biweight_func *weight_avg,
  42. int list0, int list1)
  43. {
  44. if ((h->use_weight == 2 && list0 && list1 &&
  45. (h->implicit_weight[h->ref_cache[0][scan8[n]]][h->ref_cache[1][scan8[n]]][h->mb_y & 1] != 32)) ||
  46. h->use_weight == 1)
  47. mc_part_weighted(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
  48. x_offset, y_offset, qpix_put, chroma_put,
  49. weight_op[0], weight_op[1], weight_avg[0],
  50. weight_avg[1], list0, list1, PIXEL_SHIFT, CHROMA_IDC);
  51. else
  52. mc_part_std(h, n, square, height, delta, dest_y, dest_cb, dest_cr,
  53. x_offset, y_offset, qpix_put, chroma_put, qpix_avg,
  54. chroma_avg, list0, list1, PIXEL_SHIFT, CHROMA_IDC);
  55. }
  56. static void MCFUNC(hl_motion)(H264Context *h, uint8_t *dest_y,
  57. uint8_t *dest_cb, uint8_t *dest_cr,
  58. qpel_mc_func(*qpix_put)[16],
  59. h264_chroma_mc_func(*chroma_put),
  60. qpel_mc_func(*qpix_avg)[16],
  61. h264_chroma_mc_func(*chroma_avg),
  62. h264_weight_func *weight_op,
  63. h264_biweight_func *weight_avg)
  64. {
  65. const int mb_xy = h->mb_xy;
  66. const int mb_type = h->cur_pic.mb_type[mb_xy];
  67. assert(IS_INTER(mb_type));
  68. if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))
  69. await_references(h);
  70. prefetch_motion(h, 0, PIXEL_SHIFT, CHROMA_IDC);
  71. if (IS_16X16(mb_type)) {
  72. mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
  73. qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
  74. weight_op, weight_avg,
  75. IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
  76. } else if (IS_16X8(mb_type)) {
  77. mc_part(h, 0, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 0,
  78. qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
  79. weight_op, weight_avg,
  80. IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
  81. mc_part(h, 8, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 4,
  82. qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
  83. weight_op, weight_avg,
  84. IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
  85. } else if (IS_8X16(mb_type)) {
  86. mc_part(h, 0, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,
  87. qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
  88. &weight_op[1], &weight_avg[1],
  89. IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
  90. mc_part(h, 4, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
  91. qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
  92. &weight_op[1], &weight_avg[1],
  93. IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
  94. } else {
  95. int i;
  96. assert(IS_8X8(mb_type));
  97. for (i = 0; i < 4; i++) {
  98. const int sub_mb_type = h->sub_mb_type[i];
  99. const int n = 4 * i;
  100. int x_offset = (i & 1) << 2;
  101. int y_offset = (i & 2) << 1;
  102. if (IS_SUB_8X8(sub_mb_type)) {
  103. mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr,
  104. x_offset, y_offset,
  105. qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
  106. &weight_op[1], &weight_avg[1],
  107. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  108. } else if (IS_SUB_8X4(sub_mb_type)) {
  109. mc_part(h, n, 0, 4, 4 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr,
  110. x_offset, y_offset,
  111. qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
  112. &weight_op[1], &weight_avg[1],
  113. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  114. mc_part(h, n + 2, 0, 4, 4 << PIXEL_SHIFT,
  115. dest_y, dest_cb, dest_cr, x_offset, y_offset + 2,
  116. qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
  117. &weight_op[1], &weight_avg[1],
  118. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  119. } else if (IS_SUB_4X8(sub_mb_type)) {
  120. mc_part(h, n, 0, 8, 4 * h->mb_linesize,
  121. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  122. qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
  123. &weight_op[2], &weight_avg[2],
  124. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  125. mc_part(h, n + 1, 0, 8, 4 * h->mb_linesize,
  126. dest_y, dest_cb, dest_cr, x_offset + 2, y_offset,
  127. qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
  128. &weight_op[2], &weight_avg[2],
  129. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  130. } else {
  131. int j;
  132. assert(IS_SUB_4X4(sub_mb_type));
  133. for (j = 0; j < 4; j++) {
  134. int sub_x_offset = x_offset + 2 * (j & 1);
  135. int sub_y_offset = y_offset + (j & 2);
  136. mc_part(h, n + j, 1, 4, 0,
  137. dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
  138. qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
  139. &weight_op[2], &weight_avg[2],
  140. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  141. }
  142. }
  143. }
  144. }
  145. prefetch_motion(h, 1, PIXEL_SHIFT, CHROMA_IDC);
  146. }