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.

99 lines
2.8KB

  1. /*
  2. * Copyright (c) 2002-2012 Michael Niedermayer
  3. * Copyright (C) 2012 Ronald S. Bultje
  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 "bit_depth_template.c"
  22. void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
  23. ptrdiff_t linesize_arg,
  24. int block_w, int block_h,
  25. int src_x, int src_y, int w, int h)
  26. {
  27. int x, y;
  28. int start_y, start_x, end_y, end_x;
  29. int linesize = linesize_arg;
  30. if (!w || !h)
  31. return;
  32. if (src_y >= h) {
  33. src -= src_y * linesize;
  34. src += (h - 1) * linesize;
  35. src_y = h - 1;
  36. } else if (src_y <= -block_h) {
  37. src -= src_y * linesize;
  38. src += (1 - block_h) * linesize;
  39. src_y = 1 - block_h;
  40. }
  41. if (src_x >= w) {
  42. src += (w - 1 - src_x) * sizeof(pixel);
  43. src_x = w - 1;
  44. } else if (src_x <= -block_w) {
  45. src += (1 - block_w - src_x) * sizeof(pixel);
  46. src_x = 1 - block_w;
  47. }
  48. start_y = FFMAX(0, -src_y);
  49. start_x = FFMAX(0, -src_x);
  50. end_y = FFMIN(block_h, h-src_y);
  51. end_x = FFMIN(block_w, w-src_x);
  52. av_assert2(start_y < end_y && block_h);
  53. av_assert2(start_x < end_x && block_w);
  54. w = end_x - start_x;
  55. src += start_y * linesize + start_x * sizeof(pixel);
  56. buf += start_x * sizeof(pixel);
  57. // top
  58. for (y = 0; y < start_y; y++) {
  59. memcpy(buf, src, w * sizeof(pixel));
  60. buf += linesize;
  61. }
  62. // copy existing part
  63. for (; y < end_y; y++) {
  64. memcpy(buf, src, w * sizeof(pixel));
  65. src += linesize;
  66. buf += linesize;
  67. }
  68. // bottom
  69. src -= linesize;
  70. for (; y < block_h; y++) {
  71. memcpy(buf, src, w * sizeof(pixel));
  72. buf += linesize;
  73. }
  74. buf -= block_h * linesize + start_x * sizeof(pixel);
  75. while (block_h--) {
  76. pixel *bufp = (pixel *) buf;
  77. // left
  78. for(x = 0; x < start_x; x++) {
  79. bufp[x] = bufp[start_x];
  80. }
  81. // right
  82. for (x = end_x; x < block_w; x++) {
  83. bufp[x] = bufp[end_x - 1];
  84. }
  85. buf += linesize;
  86. }
  87. }