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.

104 lines
3.2KB

  1. /*
  2. * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
  3. * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
  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. #include <stdint.h>
  22. #include "libavutil/attributes.h"
  23. #include "avcodec.h"
  24. #include "vp56dsp.h"
  25. #include "libavutil/common.h"
  26. #define VP56_EDGE_FILTER(pfx, suf, pix_inc, line_inc) \
  27. static void pfx ## _edge_filter_ ## suf(uint8_t *yuv, ptrdiff_t stride, \
  28. int t) \
  29. { \
  30. int pix2_inc = 2 * pix_inc; \
  31. int i, v; \
  32. \
  33. for (i=0; i<12; i++) { \
  34. v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4)>>3;\
  35. v = pfx##_adjust(v, t); \
  36. yuv[-pix_inc] = av_clip_uint8(yuv[-pix_inc] + v); \
  37. yuv[0] = av_clip_uint8(yuv[0] - v); \
  38. yuv += line_inc; \
  39. } \
  40. }
  41. #if CONFIG_VP5_DECODER
  42. /* Gives very similar result than the vp6 version except in a few cases */
  43. static int vp5_adjust(int v, int t)
  44. {
  45. int s2, s1 = v >> 31;
  46. v ^= s1;
  47. v -= s1;
  48. v *= v < 2*t;
  49. v -= t;
  50. s2 = v >> 31;
  51. v ^= s2;
  52. v -= s2;
  53. v = t - v;
  54. v += s1;
  55. v ^= s1;
  56. return v;
  57. }
  58. VP56_EDGE_FILTER(vp5, hor, 1, stride)
  59. VP56_EDGE_FILTER(vp5, ver, stride, 1)
  60. av_cold void ff_vp5dsp_init(VP56DSPContext *s)
  61. {
  62. s->edge_filter_hor = vp5_edge_filter_hor;
  63. s->edge_filter_ver = vp5_edge_filter_ver;
  64. }
  65. #endif /* CONFIG_VP5_DECODER */
  66. #if CONFIG_VP6_DECODER
  67. static int vp6_adjust(int v, int t)
  68. {
  69. int V = v, s = v >> 31;
  70. V ^= s;
  71. V -= s;
  72. if (V-t-1 >= (unsigned)(t-1))
  73. return v;
  74. V = 2*t - V;
  75. V += s;
  76. V ^= s;
  77. return V;
  78. }
  79. VP56_EDGE_FILTER(vp6, hor, 1, stride)
  80. VP56_EDGE_FILTER(vp6, ver, stride, 1)
  81. av_cold void ff_vp6dsp_init(VP56DSPContext *s)
  82. {
  83. s->edge_filter_hor = vp6_edge_filter_hor;
  84. s->edge_filter_ver = vp6_edge_filter_ver;
  85. s->vp6_filter_diag4 = ff_vp6_filter_diag4_c;
  86. if (ARCH_ARM)
  87. ff_vp6dsp_init_arm(s);
  88. if (ARCH_X86)
  89. ff_vp6dsp_init_x86(s);
  90. }
  91. #endif /* CONFIG_VP6_DECODER */