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, Institute Of Software Chinese Academy Of Science, 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 // Jia Haipeng, jiahaipeng95@gmail.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.
48 #pragma OPENCL EXTENSION cl_amd_fp64:enable
49 #elif defined (cl_khr_fp64)
50 #pragma OPENCL EXTENSION cl_khr_fp64:enable
57 __kernel void arithm_cartToPolar_D5 (__global float *src1, int src1_step, int src1_offset,
58 __global float *src2, int src2_step, int src2_offset,
59 __global float *dst1, int dst1_step, int dst1_offset, // magnitude
60 __global float *dst2, int dst2_step, int dst2_offset, // cartToPolar
63 int x = get_global_id(0);
64 int y = get_global_id(1);
66 if (x < cols && y < rows)
68 int src1_index = mad24(y, src1_step, x + src1_offset);
69 int src2_index = mad24(y, src2_step, x + src2_offset);
71 int dst1_index = mad24(y, dst1_step, x + dst1_offset);
72 int dst2_index = mad24(y, dst2_step, x + dst2_offset);
74 float x = src1[src1_index];
75 float y = src2[src2_index];
80 float magnitude = sqrt(x2 + y2);
82 float tmp = y >= 0 ? 0 : CV_PI*2;
83 tmp = x < 0 ? CV_PI : tmp;
85 float tmp1 = y >= 0 ? CV_PI*0.5f : CV_PI*1.5f;
86 float cartToPolar = y2 <= x2 ? x*y/(x2 + 0.28f*y2 + FLT_EPSILON) + tmp :
87 tmp1 - x*y/(y2 + 0.28f*x2 + FLT_EPSILON);
90 cartToPolar *= (180/CV_PI);
93 dst1[dst1_index] = magnitude;
94 dst2[dst2_index] = cartToPolar;
98 #if defined (DOUBLE_SUPPORT)
100 __kernel void arithm_cartToPolar_D6 (__global double *src1, int src1_step, int src1_offset,
101 __global double *src2, int src2_step, int src2_offset,
102 __global double *dst1, int dst1_step, int dst1_offset,
103 __global double *dst2, int dst2_step, int dst2_offset,
106 int x = get_global_id(0);
107 int y = get_global_id(1);
109 if (x < cols && y < rows)
111 int src1_index = mad24(y, src1_step, x + src1_offset);
112 int src2_index = mad24(y, src2_step, x + src2_offset);
114 int dst1_index = mad24(y, dst1_step, x + dst1_offset);
115 int dst2_index = mad24(y, dst2_step, x + dst2_offset);
117 double x = src1[src1_index];
118 double y = src2[src2_index];
123 double magnitude = sqrt(x2 + y2);
125 float tmp = y >= 0 ? 0 : CV_PI*2;
126 tmp = x < 0 ? CV_PI : tmp;
128 float tmp1 = y >= 0 ? CV_PI*0.5 : CV_PI*1.5;
129 double cartToPolar = y2 <= x2 ? x*y/(x2 + 0.28f*y2 + DBL_EPSILON) + tmp :
130 tmp1 - x*y/(y2 + 0.28f*x2 + DBL_EPSILON);
133 cartToPolar *= (180/CV_PI);
136 dst1[dst1_index] = magnitude;
137 dst2[dst2_index] = cartToPolar;