• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
19const sampler_t linear_sampler = (CLK_NORMALIZED_COORDS_FALSE |
20                                  CLK_FILTER_LINEAR);
21
22const sampler_t nearest_sampler = (CLK_NORMALIZED_COORDS_FALSE |
23                                   CLK_FILTER_NEAREST);
24
25__kernel void remap_near(__write_only image2d_t dst,
26                         __read_only  image2d_t src,
27                         __read_only  image2d_t xmapi,
28                         __read_only  image2d_t ymapi,
29                         float4 fill_color)
30{
31    int2 p = (int2)(get_global_id(0), get_global_id(1));
32    int2 dimi = get_image_dim(src);
33    float2 dimf = (float2)(dimi.x, dimi.y);
34    float4 val;
35    int2 mi;
36    float m;
37
38    float4 xmap = read_imagef(xmapi, nearest_sampler, p);
39    float4 ymap = read_imagef(ymapi, nearest_sampler, p);
40    float2 pos  = (float2)(xmap.x, ymap.x);
41    pos.xy = pos.xy * 65535.f;
42
43    mi = ((pos >= (float2)(0.f, 0.f)) * (pos < dimf) * (p <= dimi));
44    m = mi.x && mi.y;
45    val = mix(fill_color, read_imagef(src, nearest_sampler, pos), m);
46
47    write_imagef(dst, p, val);
48}
49
50__kernel void remap_linear(__write_only image2d_t dst,
51                           __read_only  image2d_t src,
52                           __read_only  image2d_t xmapi,
53                           __read_only  image2d_t ymapi,
54                           float4 fill_color)
55{
56    int2 p = (int2)(get_global_id(0), get_global_id(1));
57    int2 dimi = get_image_dim(src);
58    float2 dimf = (float2)(dimi.x, dimi.y);
59    float4 val;
60    int2 mi;
61    float m;
62
63    float4 xmap = read_imagef(xmapi, nearest_sampler, p);
64    float4 ymap = read_imagef(ymapi, nearest_sampler, p);
65    float2 pos  = (float2)(xmap.x, ymap.x);
66    pos.xy = pos.xy * 65535.f;
67
68    mi = ((pos >= (float2)(0.f, 0.f)) * (pos < dimf) * (p <= dimi));
69    m = mi.x && mi.y;
70    val = mix(fill_color, read_imagef(src, linear_sampler, pos), m);
71
72    write_imagef(dst, p, val);
73}
74