Path: blob/master/modules/stitching/src/opencl/warpers.cl
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.13// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// @Authors17// Peng Xiao, pengxiao@multicorewareinc.com18//19// Redistribution and use in source and binary forms, with or without modification,20// are permitted provided that the following conditions are met:21//22// * Redistribution's of source code must retain the above copyright notice,23// this list of conditions and the following disclaimer.24//25// * Redistribution's in binary form must reproduce the above copyright notice,26// this list of conditions and the following disclaimer in the documentation27// and/or other materials provided with the distribution.28//29// * The name of the copyright holders may not be used to endorse or promote products30// derived from this software without specific prior written permission.31//32// This software is provided by the copyright holders and contributors as is and33// any express or implied warranties, including, but not limited to, the implied34// warranties of merchantability and fitness for a particular purpose are disclaimed.35// In no event shall the Intel Corporation or contributors be liable for any direct,36// indirect, incidental, special, exemplary, or consequential damages37// (including, but not limited to, procurement of substitute goods or services;38// loss of use, data, or profits; or business interruption) however caused39// and on any theory of liability, whether in contract, strict liability,40// or tort (including negligence or otherwise) arising in any way out of41// the use of this software, even if advised of the possibility of such damage.42//43//M*/4445__kernel void buildWarpPlaneMaps(__global uchar * xmapptr, int xmap_step, int xmap_offset,46__global uchar * ymapptr, int ymap_step, int ymap_offset, int rows, int cols,47__constant float * ck_rinv, __constant float * ct,48int tl_u, int tl_v, float scale, int rowsPerWI)49{50int du = get_global_id(0);51int dv0 = get_global_id(1) * rowsPerWI;5253if (du < cols)54{55int xmap_index = mad24(dv0, xmap_step, mad24(du, (int)sizeof(float), xmap_offset));56int ymap_index = mad24(dv0, ymap_step, mad24(du, (int)sizeof(float), ymap_offset));5758float u = tl_u + du;59float x_ = fma(u, scale, -ct[0]);60float ct1 = 1 - ct[2];6162for (int dv = dv0, dv1 = min(rows, dv0 + rowsPerWI); dv < dv1; ++dv, xmap_index += xmap_step,63ymap_index += ymap_step)64{65__global float * xmap = (__global float *)(xmapptr + xmap_index);66__global float * ymap = (__global float *)(ymapptr + ymap_index);6768float v = tl_v + dv;69float y_ = fma(v, scale, -ct[1]);7071float x = fma(ck_rinv[0], x_, fma(ck_rinv[1], y_, ck_rinv[2] * ct1));72float y = fma(ck_rinv[3], x_, fma(ck_rinv[4], y_, ck_rinv[5] * ct1));73float z = fma(ck_rinv[6], x_, fma(ck_rinv[7], y_, ck_rinv[8] * ct1));7475if (z != 0)76x /= z, y /= z;77else78x = y = -1;7980xmap[0] = x;81ymap[0] = y;82}83}84}8586__kernel void buildWarpCylindricalMaps(__global uchar * xmapptr, int xmap_step, int xmap_offset,87__global uchar * ymapptr, int ymap_step, int ymap_offset, int rows, int cols,88__constant float * ck_rinv, int tl_u, int tl_v, float scale, int rowsPerWI)89{90int du = get_global_id(0);91int dv0 = get_global_id(1) * rowsPerWI;9293if (du < cols)94{95int xmap_index = mad24(dv0, xmap_step, mad24(du, (int)sizeof(float), xmap_offset));96int ymap_index = mad24(dv0, ymap_step, mad24(du, (int)sizeof(float), ymap_offset));9798float u = (tl_u + du) * scale;99float x_, z_;100x_ = sincos(u, &z_);101102for (int dv = dv0, dv1 = min(rows, dv0 + rowsPerWI); dv < dv1; ++dv, xmap_index += xmap_step,103ymap_index += ymap_step)104{105__global float * xmap = (__global float *)(xmapptr + xmap_index);106__global float * ymap = (__global float *)(ymapptr + ymap_index);107108float y_ = (tl_v + dv) * scale;109110float x, y, z;111x = fma(ck_rinv[0], x_, fma(ck_rinv[1], y_, ck_rinv[2] * z_));112y = fma(ck_rinv[3], x_, fma(ck_rinv[4], y_, ck_rinv[5] * z_));113z = fma(ck_rinv[6], x_, fma(ck_rinv[7], y_, ck_rinv[8] * z_));114115if (z > 0)116x /= z, y /= z;117else118x = y = -1;119120xmap[0] = x;121ymap[0] = y;122}123}124}125126__kernel void buildWarpSphericalMaps(__global uchar * xmapptr, int xmap_step, int xmap_offset,127__global uchar * ymapptr, int ymap_step, int ymap_offset, int rows, int cols,128__constant float * ck_rinv, int tl_u, int tl_v, float scale, int rowsPerWI)129{130int du = get_global_id(0);131int dv0 = get_global_id(1) * rowsPerWI;132133if (du < cols)134{135int xmap_index = mad24(dv0, xmap_step, mad24(du, (int)sizeof(float), xmap_offset));136int ymap_index = mad24(dv0, ymap_step, mad24(du, (int)sizeof(float), ymap_offset));137138float u = (tl_u + du) * scale;139float cosu, sinu = sincos(u, &cosu);140141for (int dv = dv0, dv1 = min(rows, dv0 + rowsPerWI); dv < dv1; ++dv, xmap_index += xmap_step,142ymap_index += ymap_step)143{144__global float * xmap = (__global float *)(xmapptr + xmap_index);145__global float * ymap = (__global float *)(ymapptr + ymap_index);146147float v = (tl_v + dv) * scale;148149float cosv, sinv = sincos(v, &cosv);150float x_ = sinv * sinu;151float y_ = -cosv;152float z_ = sinv * cosu;153154float x, y, z;155x = fma(ck_rinv[0], x_, fma(ck_rinv[1], y_, ck_rinv[2] * z_));156y = fma(ck_rinv[3], x_, fma(ck_rinv[4], y_, ck_rinv[5] * z_));157z = fma(ck_rinv[6], x_, fma(ck_rinv[7], y_, ck_rinv[8] * z_));158159if (z > 0)160x /= z, y /= z;161else162x = y = -1;163164xmap[0] = x;165ymap[0] = y;166}167}168}169170171