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.

105 lines
4.2KB

  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. __kernel void overlay_no_alpha(__write_only image2d_t dst,
  19. __read_only image2d_t main,
  20. __read_only image2d_t overlay,
  21. int x_position,
  22. int y_position)
  23. {
  24. const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
  25. CLK_FILTER_NEAREST);
  26. int2 overlay_size = get_image_dim(overlay);
  27. int2 loc = (int2)(get_global_id(0), get_global_id(1));
  28. if (loc.x < x_position ||
  29. loc.y < y_position ||
  30. loc.x >= overlay_size.x + x_position ||
  31. loc.y >= overlay_size.y + y_position) {
  32. float4 val = read_imagef(main, sampler, loc);
  33. write_imagef(dst, loc, val);
  34. } else {
  35. int2 loc_overlay = (int2)(x_position, y_position);
  36. float4 val = read_imagef(overlay, sampler, loc - loc_overlay);
  37. write_imagef(dst, loc, val);
  38. }
  39. }
  40. __kernel void overlay_internal_alpha(__write_only image2d_t dst,
  41. __read_only image2d_t main,
  42. __read_only image2d_t overlay,
  43. int x_position,
  44. int y_position)
  45. {
  46. const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
  47. CLK_FILTER_NEAREST);
  48. int2 overlay_size = get_image_dim(overlay);
  49. int2 loc = (int2)(get_global_id(0), get_global_id(1));
  50. if (loc.x < x_position ||
  51. loc.y < y_position ||
  52. loc.x >= overlay_size.x + x_position ||
  53. loc.y >= overlay_size.y + y_position) {
  54. float4 val = read_imagef(main, sampler, loc);
  55. write_imagef(dst, loc, val);
  56. } else {
  57. int2 loc_overlay = (int2)(x_position, y_position);
  58. float4 in_main = read_imagef(main, sampler, loc);
  59. float4 in_overlay = read_imagef(overlay, sampler, loc - loc_overlay);
  60. float4 val = in_overlay * in_overlay.w + in_main * (1.0f - in_overlay.w);
  61. write_imagef(dst, loc, val);
  62. }
  63. }
  64. __kernel void overlay_external_alpha(__write_only image2d_t dst,
  65. __read_only image2d_t main,
  66. __read_only image2d_t overlay,
  67. __read_only image2d_t alpha,
  68. int x_position,
  69. int y_position,
  70. int alpha_adj_x,
  71. int alpha_adj_y)
  72. {
  73. const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
  74. CLK_FILTER_NEAREST);
  75. int2 overlay_size = get_image_dim(overlay);
  76. int2 loc = (int2)(get_global_id(0), get_global_id(1));
  77. if (loc.x < x_position ||
  78. loc.y < y_position ||
  79. loc.x >= overlay_size.x + x_position ||
  80. loc.y >= overlay_size.y + y_position) {
  81. float4 val = read_imagef(main, sampler, loc);
  82. write_imagef(dst, loc, val);
  83. } else {
  84. int2 loc_overlay = (int2)(x_position, y_position);
  85. float4 in_main = read_imagef(main, sampler, loc);
  86. float4 in_overlay = read_imagef(overlay, sampler, loc - loc_overlay);
  87. int2 loc_alpha = (int2)(loc.x * alpha_adj_x,
  88. loc.y * alpha_adj_y) - loc_overlay;
  89. float4 in_alpha = read_imagef(alpha, sampler, loc_alpha);
  90. float4 val = in_overlay * in_alpha.x + in_main * (1.0f - in_alpha.x);
  91. write_imagef(dst, loc, val);
  92. }
  93. }