avgblur.cl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2018 Dylan Fernando
  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. __kernel void avgblur_horiz(__write_only image2d_t dst,
  21. __read_only image2d_t src,
  22. int rad)
  23. {
  24. const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
  25. CLK_FILTER_NEAREST);
  26. int2 loc = (int2)(get_global_id(0), get_global_id(1));
  27. int2 size = (int2)(get_global_size(0), get_global_size(1));
  28. int count = 0;
  29. float4 acc = (float4)(0,0,0,0);
  30. for (int xx = max(0, loc.x - rad); xx < min(loc.x + rad + 1, size.x); xx++) {
  31. count++;
  32. acc += read_imagef(src, sampler, (int2)(xx, loc.y));
  33. }
  34. write_imagef(dst, loc, acc / count);
  35. }
  36. __kernel void avgblur_vert(__write_only image2d_t dst,
  37. __read_only image2d_t src,
  38. int radv)
  39. {
  40. const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
  41. CLK_FILTER_NEAREST);
  42. int2 loc = (int2)(get_global_id(0), get_global_id(1));
  43. int2 size = (int2)(get_global_size(0), get_global_size(1));
  44. int count = 0;
  45. float4 acc = (float4)(0,0,0,0);
  46. for (int yy = max(0, loc.y - radv); yy < min(loc.y + radv + 1, size.y); yy++) {
  47. count++;
  48. acc += read_imagef(src, sampler, (int2)(loc.x, yy));
  49. }
  50. write_imagef(dst, loc, acc / count);
  51. }