1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #include "precomp.hpp"
44
45 using namespace cv;
46 using namespace cv::cuda;
47
48 #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
49
blendLinear(InputArray,InputArray,InputArray,InputArray,OutputArray,Stream &)50 void cv::cuda::blendLinear(InputArray, InputArray, InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
51
52 #else
53
54 ////////////////////////////////////////////////////////////////////////
55 // blendLinear
56
57 namespace cv { namespace cuda { namespace device
58 {
59 namespace blend
60 {
61 template <typename T>
62 void blendLinearCaller(int rows, int cols, int cn, PtrStep<T> img1, PtrStep<T> img2, PtrStepf weights1, PtrStepf weights2, PtrStep<T> result, cudaStream_t stream);
63
64 void blendLinearCaller8UC4(int rows, int cols, PtrStepb img1, PtrStepb img2, PtrStepf weights1, PtrStepf weights2, PtrStepb result, cudaStream_t stream);
65 }
66 }}}
67
68 using namespace ::cv::cuda::device::blend;
69
blendLinear(InputArray _img1,InputArray _img2,InputArray _weights1,InputArray _weights2,OutputArray _result,Stream & stream)70 void cv::cuda::blendLinear(InputArray _img1, InputArray _img2, InputArray _weights1, InputArray _weights2,
71 OutputArray _result, Stream& stream)
72 {
73 GpuMat img1 = _img1.getGpuMat();
74 GpuMat img2 = _img2.getGpuMat();
75
76 GpuMat weights1 = _weights1.getGpuMat();
77 GpuMat weights2 = _weights2.getGpuMat();
78
79 CV_Assert( img1.size() == img2.size() );
80 CV_Assert( img1.type() == img2.type() );
81 CV_Assert( weights1.size() == img1.size() );
82 CV_Assert( weights2.size() == img2.size() );
83 CV_Assert( weights1.type() == CV_32FC1 );
84 CV_Assert( weights2.type() == CV_32FC1 );
85
86 const Size size = img1.size();
87 const int depth = img1.depth();
88 const int cn = img1.channels();
89
90 _result.create(size, CV_MAKE_TYPE(depth, cn));
91 GpuMat result = _result.getGpuMat();
92
93 switch (depth)
94 {
95 case CV_8U:
96 if (cn != 4)
97 blendLinearCaller<uchar>(size.height, size.width, cn, img1, img2, weights1, weights2, result, StreamAccessor::getStream(stream));
98 else
99 blendLinearCaller8UC4(size.height, size.width, img1, img2, weights1, weights2, result, StreamAccessor::getStream(stream));
100 break;
101 case CV_32F:
102 blendLinearCaller<float>(size.height, size.width, cn, img1, img2, weights1, weights2, result, StreamAccessor::getStream(stream));
103 break;
104 default:
105 CV_Error(cv::Error::StsUnsupportedFormat, "bad image depth in linear blending function");
106 }
107 }
108
109 #endif
110