2
0

mpegvideodsp.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libavutil/attributes.h"
  20. #include "libavutil/common.h"
  21. #include "mpegvideodsp.h"
  22. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h,
  23. int x16, int y16, int rounder)
  24. {
  25. const int A = (16 - x16) * (16 - y16);
  26. const int B = (x16) * (16 - y16);
  27. const int C = (16 - x16) * (y16);
  28. const int D = (x16) * (y16);
  29. int i;
  30. for (i = 0; i < h; i++) {
  31. dst[0] = (A * src[0] + B * src[1] + C * src[stride + 0] + D * src[stride + 1] + rounder) >> 8;
  32. dst[1] = (A * src[1] + B * src[2] + C * src[stride + 1] + D * src[stride + 2] + rounder) >> 8;
  33. dst[2] = (A * src[2] + B * src[3] + C * src[stride + 2] + D * src[stride + 3] + rounder) >> 8;
  34. dst[3] = (A * src[3] + B * src[4] + C * src[stride + 3] + D * src[stride + 4] + rounder) >> 8;
  35. dst[4] = (A * src[4] + B * src[5] + C * src[stride + 4] + D * src[stride + 5] + rounder) >> 8;
  36. dst[5] = (A * src[5] + B * src[6] + C * src[stride + 5] + D * src[stride + 6] + rounder) >> 8;
  37. dst[6] = (A * src[6] + B * src[7] + C * src[stride + 6] + D * src[stride + 7] + rounder) >> 8;
  38. dst[7] = (A * src[7] + B * src[8] + C * src[stride + 7] + D * src[stride + 8] + rounder) >> 8;
  39. dst += stride;
  40. src += stride;
  41. }
  42. }
  43. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  44. int dxx, int dxy, int dyx, int dyy, int shift, int r,
  45. int width, int height)
  46. {
  47. int y, vx, vy;
  48. const int s = 1 << shift;
  49. width--;
  50. height--;
  51. for (y = 0; y < h; y++) {
  52. int x;
  53. vx = ox;
  54. vy = oy;
  55. for (x = 0; x < 8; x++) { // FIXME: optimize
  56. int index;
  57. int src_x = vx >> 16;
  58. int src_y = vy >> 16;
  59. int frac_x = src_x & (s - 1);
  60. int frac_y = src_y & (s - 1);
  61. src_x >>= shift;
  62. src_y >>= shift;
  63. if ((unsigned) src_x < width) {
  64. if ((unsigned) src_y < height) {
  65. index = src_x + src_y * stride;
  66. dst[y * stride + x] =
  67. ((src[index] * (s - frac_x) +
  68. src[index + 1] * frac_x) * (s - frac_y) +
  69. (src[index + stride] * (s - frac_x) +
  70. src[index + stride + 1] * frac_x) * frac_y +
  71. r) >> (shift * 2);
  72. } else {
  73. index = src_x + av_clip(src_y, 0, height) * stride;
  74. dst[y * stride + x] =
  75. ((src[index] * (s - frac_x) +
  76. src[index + 1] * frac_x) * s +
  77. r) >> (shift * 2);
  78. }
  79. } else {
  80. if ((unsigned) src_y < height) {
  81. index = av_clip(src_x, 0, width) + src_y * stride;
  82. dst[y * stride + x] =
  83. ((src[index] * (s - frac_y) +
  84. src[index + stride] * frac_y) * s +
  85. r) >> (shift * 2);
  86. } else {
  87. index = av_clip(src_x, 0, width) +
  88. av_clip(src_y, 0, height) * stride;
  89. dst[y * stride + x] = src[index];
  90. }
  91. }
  92. vx += dxx;
  93. vy += dyx;
  94. }
  95. ox += dxy;
  96. oy += dyy;
  97. }
  98. }
  99. av_cold void ff_mpegvideodsp_init(MpegVideoDSPContext *c)
  100. {
  101. c->gmc1 = gmc1_c;
  102. c->gmc = ff_gmc_c;
  103. if (ARCH_PPC)
  104. ff_mpegvideodsp_init_ppc(c);
  105. if (ARCH_X86)
  106. ff_mpegvideodsp_init_x86(c);
  107. }