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 // Zhang Chunpeng chunpeng@multicorewareinc.com
19 // Yao Wang, yao@multicorewareinc.com
22 // Redistribution and use in source and binary forms, with or without modification,
23 // are permitted provided that the following conditions are met:
25 // * Redistribution's of source code must retain the above copyright notice,
26 // this list of conditions and the following disclaimer.
28 // * Redistribution's in binary form must reproduce the above copyright notice,
29 // this list of conditions and the following disclaimer in the documentation
30 // and/or other materials provided with the distribution.
32 // * The name of the copyright holders may not be used to endorse or promote products
33 // derived from this software without specific prior written permission.
35 // This software is provided by the copyright holders and contributors "as is" and
36 // any express or implied warranties, including, but not limited to, the implied
37 // warranties of merchantability and fitness for a particular purpose are disclaimed.
38 // In no event shall the Intel Corporation or contributors be liable for any direct,
39 // indirect, incidental, special, exemplary, or consequential damages
40 // (including, but not limited to, procurement of substitute goods or services;
41 // loss of use, data, or profits; or business interruption) however caused
42 // and on any theory of liability, whether in contract, strict liability,
43 // or tort (including negligence or otherwise) arising in any way out of
44 // the use of this software, even if advised of the possibility of such damage.
48 #include "precomp.hpp"
49 #include "opencl_kernels.hpp"
52 using namespace cv::ocl;
54 /* Haar features calculation */
61 void pyrUp(const cv::ocl::oclMat &src, cv::ocl::oclMat &dst)
63 int depth = src.depth(), channels = src.channels(), oclChannels = src.oclchannels();
65 CV_Assert(depth == CV_8U || depth == CV_16U || depth == CV_16S || depth == CV_32F);
66 CV_Assert(channels == 1 || channels == 3 || channels == 4);
68 dst.create(src.rows * 2, src.cols * 2, src.type());
70 Context *clCxt = src.clCxt;
72 const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float" };
73 char buildOptions[250], convertString[50];
74 const char * const channelsString = oclChannels == 1 ? "" : "4";
75 sprintf(convertString, "convert_%s%s_sat_rte", typeMap[depth], channelsString);
76 sprintf(buildOptions, "-D Type=%s%s -D floatType=float%s -D convertToType=%s -D convertToFloat=%s",
77 typeMap[depth], channelsString, channelsString,
78 depth == CV_32F ? "" : convertString,
79 oclChannels == 4 ? "convert_float4" : "(float)");
81 const String kernelName = "pyrUp";
82 int dststep = dst.step / dst.elemSize(), srcstep = src.step / src.elemSize();
84 std::vector< std::pair<size_t, const void *> > args;
85 args.push_back( std::make_pair( sizeof(cl_mem), (void *)&src.data));
86 args.push_back( std::make_pair( sizeof(cl_mem), (void *)&dst.data));
87 args.push_back( std::make_pair( sizeof(cl_int), (void *)&src.rows));
88 args.push_back( std::make_pair( sizeof(cl_int), (void *)&dst.rows));
89 args.push_back( std::make_pair( sizeof(cl_int), (void *)&src.cols));
90 args.push_back( std::make_pair( sizeof(cl_int), (void *)&dst.cols));
91 args.push_back( std::make_pair( sizeof(cl_int), (void *)&src.offset));
92 args.push_back( std::make_pair( sizeof(cl_int), (void *)&dst.offset));
93 args.push_back( std::make_pair( sizeof(cl_int), (void *)&srcstep));
94 args.push_back( std::make_pair( sizeof(cl_int), (void *)&dststep));
96 size_t globalThreads[3] = {dst.cols, dst.rows, 1};
97 size_t localThreads[3] = {16, 16, 1};
100 openCLExecuteKernel(clCxt, &pyr_up, kernelName, globalThreads, localThreads, args, -1, -1,