1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
18 // Jin Ma jin@multicorewareinc.com
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
26 // * Redistribution's in binary form must reproduce the above copyright notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other materials provided with the distribution.
30 // * The name of the copyright holders may not be used to endorse or promote products
31 // derived from this software without specific prior written permission.
33 // This software is provided by the copyright holders and contributors as is and
34 // any express or implied warranties, including, but not limited to, the implied
35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
36 // In no event shall the Intel Corporation or contributors be liable for any direct,
37 // indirect, incidental, special, exemplary, or consequential damages
38 // (including, but not limited to, procurement of substitute goods or services;
39 // loss of use, data, or profits; or business interruption) however caused
40 // and on any theory of liability, whether in contract, strict liability,
41 // or tort (including negligence or otherwise) arising in any way out of
42 // the use of this software, even if advised of the possibility of such damage.
46 __kernel void buildMotionMapsKernel(__global float* forwardMotionX,
47 __global float* forwardMotionY,
48 __global float* backwardMotionX,
49 __global float* backwardMotionY,
50 __global float* forwardMapX,
51 __global float* forwardMapY,
52 __global float* backwardMapX,
53 __global float* backwardMapY,
54 int forwardMotionX_row,
55 int forwardMotionX_col,
56 int forwardMotionX_step,
57 int forwardMotionY_step,
58 int backwardMotionX_step,
59 int backwardMotionY_step,
62 int backwardMapX_step,
66 int x = get_global_id(0);
67 int y = get_global_id(1);
69 if(x < forwardMotionX_col && y < forwardMotionX_row)
71 float fx = forwardMotionX[y * forwardMotionX_step + x];
72 float fy = forwardMotionY[y * forwardMotionY_step + x];
74 float bx = backwardMotionX[y * backwardMotionX_step + x];
75 float by = backwardMotionY[y * backwardMotionY_step + x];
77 forwardMapX[y * forwardMapX_step + x] = x + bx;
78 forwardMapY[y * forwardMapY_step + x] = y + by;
80 backwardMapX[y * backwardMapX_step + x] = x + fx;
81 backwardMapY[y * backwardMapY_step + x] = y + fy;
85 __kernel void upscaleKernel(__global float* src,
95 int x = get_global_id(0);
96 int y = get_global_id(1);
98 if(x < src_col && y < src_row)
102 dst[y * scale * dst_step + x * scale] = src[y * src_step + x];
106 vstore4(vload4(0, src + y * channels * src_step + 4 * x), 0, dst + y * channels * scale * dst_step + 4 * x * scale);
112 float diffSign(float a, float b)
114 return a > b ? 1.0f : a < b ? -1.0f : 0.0f;
117 float4 diffSign4(float4 a, float4 b)
120 pos.x = a.x > b.x ? 1.0f : a.x < b.x ? -1.0f : 0.0f;
121 pos.y = a.y > b.y ? 1.0f : a.y < b.y ? -1.0f : 0.0f;
122 pos.z = a.z > b.z ? 1.0f : a.z < b.z ? -1.0f : 0.0f;
127 __kernel void diffSignKernel(__global float* src1,
128 __global float* src2,
136 int x = get_global_id(0);
137 int y = get_global_id(1);
139 if(x < src1_col && y < src1_row)
141 dst[y * dst_step + x] = diffSign(src1[y * src1_step + x], src2[y * src2_step + x]);
145 __kernel void calcBtvRegularizationKernel(__global float* src,
153 __constant float* c_btvRegWeights
156 int x = get_global_id(0) + ksize;
157 int y = get_global_id(1) + ksize;
159 if ((y < src_row - ksize) && (x < src_col - ksize))
163 const float srcVal = src[y * src_step + x];
166 for (int m = 0, count = 0; m <= ksize; ++m)
168 for (int l = ksize; l + m >= 0; --l, ++count)
170 dstVal = dstVal + c_btvRegWeights[count] * (diffSign(srcVal, src[(y + m) * src_step + (x + l)]) - diffSign(src[(y - m) * src_step + (x - l)], srcVal));
173 dst[y * dst_step + x] = dstVal;
177 float4 srcVal = vload4(0, src + y * src_step + 4 * x);
180 for (int m = 0, count = 0; m <= ksize; ++m)
182 for (int l = ksize; l + m >= 0; --l, ++count)
185 src1.x = src[(y + m) * src_step + 4 * (x + l) + 0];
186 src1.y = src[(y + m) * src_step + 4 * (x + l) + 1];
187 src1.z = src[(y + m) * src_step + 4 * (x + l) + 2];
188 src1.w = src[(y + m) * src_step + 4 * (x + l) + 3];
191 src2.x = src[(y - m) * src_step + 4 * (x - l) + 0];
192 src2.y = src[(y - m) * src_step + 4 * (x - l) + 1];
193 src2.z = src[(y - m) * src_step + 4 * (x - l) + 2];
194 src2.w = src[(y - m) * src_step + 4 * (x - l) + 3];
196 dstVal = dstVal + c_btvRegWeights[count] * (diffSign4(srcVal, src1) - diffSign4(src2, srcVal));
199 vstore4(dstVal, 0, dst + y * dst_step + 4 * x);