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.

119 lines
4.4KB

  1. /*
  2. * Copyright (c) 2015-2016 Kieran Kunhya <kieran@kunhya.com>
  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 "libavutil/attributes.h"
  21. #include "libavutil/common.h"
  22. #include "libavutil/avassert.h"
  23. #include "cfhddsp.h"
  24. static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride,
  25. const int16_t *low, ptrdiff_t low_stride,
  26. const int16_t *high, ptrdiff_t high_stride,
  27. int len, int clip)
  28. {
  29. int16_t tmp;
  30. int i;
  31. tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3;
  32. output[(2*0+0)*out_stride] = (tmp + high[0*high_stride]) >> 1;
  33. if (clip)
  34. output[(2*0+0)*out_stride] = av_clip_uintp2_c(output[(2*0+0)*out_stride], clip);
  35. tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3;
  36. output[(2*0+1)*out_stride] = (tmp - high[0*high_stride]) >> 1;
  37. if (clip)
  38. output[(2*0+1)*out_stride] = av_clip_uintp2_c(output[(2*0+1)*out_stride], clip);
  39. for (i = 1; i < len - 1; i++) {
  40. tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3;
  41. output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1;
  42. if (clip)
  43. output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip);
  44. tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3;
  45. output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1;
  46. if (clip)
  47. output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip);
  48. }
  49. tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3;
  50. output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1;
  51. if (clip)
  52. output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip);
  53. tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3;
  54. output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1;
  55. if (clip)
  56. output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip);
  57. }
  58. static void vert_filter(int16_t *output, ptrdiff_t out_stride,
  59. const int16_t *low, ptrdiff_t low_stride,
  60. const int16_t *high, ptrdiff_t high_stride,
  61. int width, int height)
  62. {
  63. for (int i = 0; i < width; i++) {
  64. filter(output, out_stride, low, low_stride, high, high_stride, height, 0);
  65. low++;
  66. high++;
  67. output++;
  68. }
  69. }
  70. static void horiz_filter(int16_t *output, ptrdiff_t ostride,
  71. const int16_t *low, ptrdiff_t lstride,
  72. const int16_t *high, ptrdiff_t hstride,
  73. int width, int height)
  74. {
  75. for (int i = 0; i < height; i++) {
  76. filter(output, 1, low, 1, high, 1, width, 0);
  77. low += lstride;
  78. high += hstride;
  79. output += ostride * 2;
  80. }
  81. }
  82. static void horiz_filter_clip(int16_t *output, const int16_t *low, const int16_t *high,
  83. int width, int clip)
  84. {
  85. filter(output, 1, low, 1, high, 1, width, clip);
  86. }
  87. static void horiz_filter_clip_bayer(int16_t *output, const int16_t *low, const int16_t *high,
  88. int width, int clip)
  89. {
  90. filter(output, 2, low, 1, high, 1, width, clip);
  91. }
  92. av_cold void ff_cfhddsp_init(CFHDDSPContext *c, int depth, int bayer)
  93. {
  94. c->horiz_filter = horiz_filter;
  95. c->vert_filter = vert_filter;
  96. if (bayer)
  97. c->horiz_filter_clip = horiz_filter_clip_bayer;
  98. else
  99. c->horiz_filter_clip = horiz_filter_clip;
  100. if (ARCH_X86)
  101. ff_cfhddsp_init_x86(c, depth, bayer);
  102. }