h264_mc_template.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 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. #include "h264dec.h"
  22. #undef MCFUNC
  23. #if CHROMA_IDC == 1
  24. # define MCFUNC(n) FUNC(n ## _420)
  25. #elif CHROMA_IDC == 2
  26. # define MCFUNC(n) FUNC(n ## _422)
  27. #elif CHROMA_IDC == 3
  28. # define MCFUNC(n) FUNC(n ## _444)
  29. #endif
  30. #undef mc_part
  31. #define mc_part MCFUNC(mc_part)
  32. static void mc_part(const H264Context *h, H264SliceContext *sl,
  33. int n, int square,
  34. int height, int delta,
  35. uint8_t *dest_y, uint8_t *dest_cb,
  36. uint8_t *dest_cr,
  37. int x_offset, int y_offset,
  38. const qpel_mc_func *qpix_put,
  39. h264_chroma_mc_func chroma_put,
  40. const qpel_mc_func *qpix_avg,
  41. h264_chroma_mc_func chroma_avg,
  42. const h264_weight_func *weight_op,
  43. const h264_biweight_func *weight_avg,
  44. int list0, int list1)
  45. {
  46. if ((sl->pwt.use_weight == 2 && list0 && list1 &&
  47. (sl->pwt.implicit_weight[sl->ref_cache[0][scan8[n]]][sl->ref_cache[1][scan8[n]]][sl->mb_y & 1] != 32)) ||
  48. sl->pwt.use_weight == 1)
  49. mc_part_weighted(h, sl, n, square, height, delta, dest_y, dest_cb, dest_cr,
  50. x_offset, y_offset, qpix_put, chroma_put,
  51. weight_op[0], weight_op[1], weight_avg[0],
  52. weight_avg[1], list0, list1, PIXEL_SHIFT, CHROMA_IDC);
  53. else
  54. mc_part_std(h, sl, n, square, height, delta, dest_y, dest_cb, dest_cr,
  55. x_offset, y_offset, qpix_put, chroma_put, qpix_avg,
  56. chroma_avg, list0, list1, PIXEL_SHIFT, CHROMA_IDC);
  57. }
  58. static void MCFUNC(hl_motion)(const H264Context *h, H264SliceContext *sl,
  59. uint8_t *dest_y,
  60. uint8_t *dest_cb, uint8_t *dest_cr,
  61. const qpel_mc_func(*qpix_put)[16],
  62. const h264_chroma_mc_func(*chroma_put),
  63. const qpel_mc_func(*qpix_avg)[16],
  64. const h264_chroma_mc_func(*chroma_avg),
  65. const h264_weight_func *weight_op,
  66. const h264_biweight_func *weight_avg)
  67. {
  68. const int mb_xy = sl->mb_xy;
  69. const int mb_type = h->cur_pic.mb_type[mb_xy];
  70. av_assert2(IS_INTER(mb_type));
  71. if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME))
  72. await_references(h, sl);
  73. if (USES_LIST(mb_type, 0))
  74. prefetch_motion(h, sl, 0, PIXEL_SHIFT, CHROMA_IDC);
  75. if (IS_16X16(mb_type)) {
  76. mc_part(h, sl, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,
  77. qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
  78. weight_op, weight_avg,
  79. IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
  80. } else if (IS_16X8(mb_type)) {
  81. mc_part(h, sl, 0, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 0,
  82. qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
  83. weight_op, weight_avg,
  84. IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
  85. mc_part(h, sl, 8, 0, 8, 8 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr, 0, 4,
  86. qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
  87. weight_op, weight_avg,
  88. IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
  89. } else if (IS_8X16(mb_type)) {
  90. mc_part(h, sl, 0, 0, 16, 8 * sl->mb_linesize, dest_y, dest_cb, dest_cr, 0, 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, 0, 0), IS_DIR(mb_type, 0, 1));
  94. mc_part(h, sl, 4, 0, 16, 8 * sl->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,
  95. qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
  96. &weight_op[1], &weight_avg[1],
  97. IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
  98. } else {
  99. int i;
  100. av_assert2(IS_8X8(mb_type));
  101. for (i = 0; i < 4; i++) {
  102. const int sub_mb_type = sl->sub_mb_type[i];
  103. const int n = 4 * i;
  104. int x_offset = (i & 1) << 2;
  105. int y_offset = (i & 2) << 1;
  106. if (IS_SUB_8X8(sub_mb_type)) {
  107. mc_part(h, sl, n, 1, 8, 0, dest_y, dest_cb, dest_cr,
  108. x_offset, y_offset,
  109. qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
  110. &weight_op[1], &weight_avg[1],
  111. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  112. } else if (IS_SUB_8X4(sub_mb_type)) {
  113. mc_part(h, sl, n, 0, 4, 4 << PIXEL_SHIFT, dest_y, dest_cb, dest_cr,
  114. x_offset, y_offset,
  115. qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
  116. &weight_op[1], &weight_avg[1],
  117. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  118. mc_part(h, sl, n + 2, 0, 4, 4 << PIXEL_SHIFT,
  119. dest_y, dest_cb, dest_cr, x_offset, y_offset + 2,
  120. qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
  121. &weight_op[1], &weight_avg[1],
  122. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  123. } else if (IS_SUB_4X8(sub_mb_type)) {
  124. mc_part(h, sl, n, 0, 8, 4 * sl->mb_linesize,
  125. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  126. qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
  127. &weight_op[2], &weight_avg[2],
  128. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  129. mc_part(h, sl, n + 1, 0, 8, 4 * sl->mb_linesize,
  130. dest_y, dest_cb, dest_cr, x_offset + 2, y_offset,
  131. qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
  132. &weight_op[2], &weight_avg[2],
  133. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  134. } else {
  135. int j;
  136. av_assert2(IS_SUB_4X4(sub_mb_type));
  137. for (j = 0; j < 4; j++) {
  138. int sub_x_offset = x_offset + 2 * (j & 1);
  139. int sub_y_offset = y_offset + (j & 2);
  140. mc_part(h, sl, n + j, 1, 4, 0,
  141. dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
  142. qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
  143. &weight_op[2], &weight_avg[2],
  144. IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
  145. }
  146. }
  147. }
  148. }
  149. if (USES_LIST(mb_type, 1))
  150. prefetch_motion(h, sl, 1, PIXEL_SHIFT, CHROMA_IDC);
  151. }