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.

146 lines
4.8KB

  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. const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
  19. CLK_FILTER_NEAREST);
  20. __kernel void fade(__write_only image2d_t dst,
  21. __read_only image2d_t src1,
  22. __read_only image2d_t src2,
  23. float progress)
  24. {
  25. int2 p = (int2)(get_global_id(0), get_global_id(1));
  26. float4 val1 = read_imagef(src1, sampler, p);
  27. float4 val2 = read_imagef(src2, sampler, p);
  28. write_imagef(dst, p, mix(val2, val1, progress));
  29. }
  30. __kernel void wipeleft(__write_only image2d_t dst,
  31. __read_only image2d_t src1,
  32. __read_only image2d_t src2,
  33. float progress)
  34. {
  35. int s = (int)(get_image_dim(src1).x * progress);
  36. int2 p = (int2)(get_global_id(0), get_global_id(1));
  37. float4 val1 = read_imagef(src1, sampler, p);
  38. float4 val2 = read_imagef(src2, sampler, p);
  39. write_imagef(dst, p, p.x > s ? val2 : val1);
  40. }
  41. __kernel void wiperight(__write_only image2d_t dst,
  42. __read_only image2d_t src1,
  43. __read_only image2d_t src2,
  44. float progress)
  45. {
  46. int s = (int)(get_image_dim(src1).x * (1.f - progress));
  47. int2 p = (int2)(get_global_id(0), get_global_id(1));
  48. float4 val1 = read_imagef(src1, sampler, p);
  49. float4 val2 = read_imagef(src2, sampler, p);
  50. write_imagef(dst, p, p.x > s ? val1 : val2);
  51. }
  52. __kernel void wipeup(__write_only image2d_t dst,
  53. __read_only image2d_t src1,
  54. __read_only image2d_t src2,
  55. float progress)
  56. {
  57. int s = (int)(get_image_dim(src1).y * progress);
  58. int2 p = (int2)(get_global_id(0), get_global_id(1));
  59. float4 val1 = read_imagef(src1, sampler, p);
  60. float4 val2 = read_imagef(src2, sampler, p);
  61. write_imagef(dst, p, p.y > s ? val2 : val1);
  62. }
  63. __kernel void wipedown(__write_only image2d_t dst,
  64. __read_only image2d_t src1,
  65. __read_only image2d_t src2,
  66. float progress)
  67. {
  68. int s = (int)(get_image_dim(src1).y * (1.f - progress));
  69. int2 p = (int2)(get_global_id(0), get_global_id(1));
  70. float4 val1 = read_imagef(src1, sampler, p);
  71. float4 val2 = read_imagef(src2, sampler, p);
  72. write_imagef(dst, p, p.y > s ? val1 : val2);
  73. }
  74. void slide(__write_only image2d_t dst,
  75. __read_only image2d_t src1,
  76. __read_only image2d_t src2,
  77. float progress,
  78. int2 direction)
  79. {
  80. int w = get_image_dim(src1).x;
  81. int h = get_image_dim(src1).y;
  82. int2 wh = (int2)(w, h);
  83. int2 uv = (int2)(get_global_id(0), get_global_id(1));
  84. int2 pi = (int2)(progress * w, progress * h);
  85. int2 p = uv + pi * direction;
  86. int2 f = p % wh;
  87. f = f + (int2)(w, h) * (int2)(f.x < 0, f.y < 0);
  88. float4 val1 = read_imagef(src1, sampler, f);
  89. float4 val2 = read_imagef(src2, sampler, f);
  90. write_imagef(dst, uv, mix(val1, val2, (p.y >= 0) * (h > p.y) * (p.x >= 0) * (w > p.x)));
  91. }
  92. __kernel void slidedown(__write_only image2d_t dst,
  93. __read_only image2d_t src1,
  94. __read_only image2d_t src2,
  95. float progress)
  96. {
  97. int2 direction = (int2)(0, 1);
  98. slide(dst, src1, src2, progress, direction);
  99. }
  100. __kernel void slideup(__write_only image2d_t dst,
  101. __read_only image2d_t src1,
  102. __read_only image2d_t src2,
  103. float progress)
  104. {
  105. int2 direction = (int2)(0, -1);
  106. slide(dst, src1, src2, progress, direction);
  107. }
  108. __kernel void slideleft(__write_only image2d_t dst,
  109. __read_only image2d_t src1,
  110. __read_only image2d_t src2,
  111. float progress)
  112. {
  113. int2 direction = (int2)(-1, 0);
  114. slide(dst, src1, src2, progress, direction);
  115. }
  116. __kernel void slideright(__write_only image2d_t dst,
  117. __read_only image2d_t src1,
  118. __read_only image2d_t src2,
  119. float progress)
  120. {
  121. int2 direction = (int2)(1, 0);
  122. slide(dst, src1, src2, progress, direction);
  123. }