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.

202 lines
9.0KB

  1. /*
  2. * Copyright (C) 2009 David Conrad
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "dsputil.h"
  21. #include "diracdsp.h"
  22. #include "libavcodec/x86/diracdsp_mmx.h"
  23. #define FILTER(src, stride) \
  24. ((21*((src)[ 0*stride] + (src)[1*stride]) \
  25. -7*((src)[-1*stride] + (src)[2*stride]) \
  26. +3*((src)[-2*stride] + (src)[3*stride]) \
  27. -1*((src)[-3*stride] + (src)[4*stride]) + 16) >> 5)
  28. static void dirac_hpel_filter(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, const uint8_t *src,
  29. int stride, int width, int height)
  30. {
  31. int x, y;
  32. for (y = 0; y < height; y++) {
  33. for (x = -3; x < width+5; x++)
  34. dstv[x] = av_clip_uint8(FILTER(src+x, stride));
  35. for (x = 0; x < width; x++)
  36. dstc[x] = av_clip_uint8(FILTER(dstv+x, 1));
  37. for (x = 0; x < width; x++)
  38. dsth[x] = av_clip_uint8(FILTER(src+x, 1));
  39. src += stride;
  40. dsth += stride;
  41. dstv += stride;
  42. dstc += stride;
  43. }
  44. }
  45. #define PIXOP_BILINEAR(PFX, OP, WIDTH) \
  46. static void ff_ ## PFX ## _dirac_pixels ## WIDTH ## _bilinear_c(uint8_t *dst, const uint8_t *src[5], int stride, int h) \
  47. { \
  48. int x; \
  49. const uint8_t *s0 = src[0]; \
  50. const uint8_t *s1 = src[1]; \
  51. const uint8_t *s2 = src[2]; \
  52. const uint8_t *s3 = src[3]; \
  53. const uint8_t *w = src[4]; \
  54. \
  55. while (h--) { \
  56. for (x = 0; x < WIDTH; x++) { \
  57. OP(dst[x], (s0[x]*w[0] + s1[x]*w[1] + s2[x]*w[2] + s3[x]*w[3] + 8) >> 4); \
  58. } \
  59. \
  60. dst += stride; \
  61. s0 += stride; \
  62. s1 += stride; \
  63. s2 += stride; \
  64. s3 += stride; \
  65. } \
  66. }
  67. #define OP_PUT(dst, val) (dst) = (val)
  68. #define OP_AVG(dst, val) (dst) = (((dst) + (val) + 1)>>1)
  69. PIXOP_BILINEAR(put, OP_PUT, 8)
  70. PIXOP_BILINEAR(put, OP_PUT, 16)
  71. PIXOP_BILINEAR(put, OP_PUT, 32)
  72. PIXOP_BILINEAR(avg, OP_AVG, 8)
  73. PIXOP_BILINEAR(avg, OP_AVG, 16)
  74. PIXOP_BILINEAR(avg, OP_AVG, 32)
  75. #define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + (1<<(log2_denom-1))) >> log2_denom)
  76. #define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + (1<<(log2_denom-1))) >> log2_denom)
  77. #define DIRAC_WEIGHT(W) \
  78. static void weight_dirac_pixels ## W ## _c(uint8_t *block, int stride, int log2_denom, \
  79. int weight, int h) { \
  80. int x; \
  81. while (h--) { \
  82. for (x = 0; x < W; x++) { \
  83. op_scale1(x); \
  84. op_scale1(x+1); \
  85. } \
  86. block += stride; \
  87. } \
  88. } \
  89. static void biweight_dirac_pixels ## W ## _c(uint8_t *dst, const uint8_t *src, int stride, int log2_denom, \
  90. int weightd, int weights, int h) { \
  91. int x; \
  92. while (h--) { \
  93. for (x = 0; x < W; x++) { \
  94. op_scale2(x); \
  95. op_scale2(x+1); \
  96. } \
  97. dst += stride; \
  98. src += stride; \
  99. } \
  100. }
  101. DIRAC_WEIGHT(8)
  102. DIRAC_WEIGHT(16)
  103. DIRAC_WEIGHT(32)
  104. #define ADD_OBMC(xblen) \
  105. static void add_obmc ## xblen ## _c(uint16_t *dst, const uint8_t *src, int stride, \
  106. const uint8_t *obmc_weight, int yblen) \
  107. { \
  108. int x; \
  109. while (yblen--) { \
  110. for (x = 0; x < xblen; x += 2) { \
  111. dst[x ] += src[x ] * obmc_weight[x ]; \
  112. dst[x+1] += src[x+1] * obmc_weight[x+1]; \
  113. } \
  114. dst += stride; \
  115. src += stride; \
  116. obmc_weight += 32; \
  117. } \
  118. }
  119. ADD_OBMC(8)
  120. ADD_OBMC(16)
  121. ADD_OBMC(32)
  122. static void put_signed_rect_clamped_c(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height)
  123. {
  124. int x, y;
  125. for (y = 0; y < height; y++) {
  126. for (x = 0; x < width; x+=4) {
  127. dst[x ] = av_clip_uint8(src[x ] + 128);
  128. dst[x+1] = av_clip_uint8(src[x+1] + 128);
  129. dst[x+2] = av_clip_uint8(src[x+2] + 128);
  130. dst[x+3] = av_clip_uint8(src[x+3] + 128);
  131. }
  132. dst += dst_stride;
  133. src += src_stride;
  134. }
  135. }
  136. static void add_rect_clamped_c(uint8_t *dst, const uint16_t *src, int stride,
  137. const int16_t *idwt, int idwt_stride,
  138. int width, int height)
  139. {
  140. int x, y;
  141. for (y = 0; y < height; y++) {
  142. for (x = 0; x < width; x+=2) {
  143. dst[x ] = av_clip_uint8(((src[x ]+32)>>6) + idwt[x ]);
  144. dst[x+1] = av_clip_uint8(((src[x+1]+32)>>6) + idwt[x+1]);
  145. }
  146. dst += stride;
  147. src += stride;
  148. idwt += idwt_stride;
  149. }
  150. }
  151. #define PIXFUNC(PFX, WIDTH) \
  152. c->PFX ## _dirac_pixels_tab[WIDTH>>4][0] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _c; \
  153. c->PFX ## _dirac_pixels_tab[WIDTH>>4][1] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _l2_c; \
  154. c->PFX ## _dirac_pixels_tab[WIDTH>>4][2] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _l4_c; \
  155. c->PFX ## _dirac_pixels_tab[WIDTH>>4][3] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _bilinear_c
  156. void ff_diracdsp_init(DiracDSPContext *c)
  157. {
  158. c->dirac_hpel_filter = dirac_hpel_filter;
  159. c->add_rect_clamped = add_rect_clamped_c;
  160. c->put_signed_rect_clamped = put_signed_rect_clamped_c;
  161. c->add_dirac_obmc[0] = add_obmc8_c;
  162. c->add_dirac_obmc[1] = add_obmc16_c;
  163. c->add_dirac_obmc[2] = add_obmc32_c;
  164. c->weight_dirac_pixels_tab[0] = weight_dirac_pixels8_c;
  165. c->weight_dirac_pixels_tab[1] = weight_dirac_pixels16_c;
  166. c->weight_dirac_pixels_tab[2] = weight_dirac_pixels32_c;
  167. c->biweight_dirac_pixels_tab[0] = biweight_dirac_pixels8_c;
  168. c->biweight_dirac_pixels_tab[1] = biweight_dirac_pixels16_c;
  169. c->biweight_dirac_pixels_tab[2] = biweight_dirac_pixels32_c;
  170. PIXFUNC(put, 8);
  171. PIXFUNC(put, 16);
  172. PIXFUNC(put, 32);
  173. PIXFUNC(avg, 8);
  174. PIXFUNC(avg, 16);
  175. PIXFUNC(avg, 32);
  176. if (HAVE_MMX && HAVE_YASM) ff_diracdsp_init_mmx(c);
  177. }