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
merge(const GpuMat *,size_t,OutputArray,Stream &)50 void cv::cuda::merge(const GpuMat*, size_t, OutputArray, Stream&) { throw_no_cuda(); }
merge(const std::vector<GpuMat> &,OutputArray,Stream &)51 void cv::cuda::merge(const std::vector<GpuMat>&, OutputArray, Stream&) { throw_no_cuda(); }
52
split(InputArray,GpuMat *,Stream &)53 void cv::cuda::split(InputArray, GpuMat*, Stream&) { throw_no_cuda(); }
split(InputArray,std::vector<GpuMat> &,Stream &)54 void cv::cuda::split(InputArray, std::vector<GpuMat>&, Stream&) { throw_no_cuda(); }
55
transpose(InputArray,OutputArray,Stream &)56 void cv::cuda::transpose(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
57
flip(InputArray,OutputArray,int,Stream &)58 void cv::cuda::flip(InputArray, OutputArray, int, Stream&) { throw_no_cuda(); }
59
createLookUpTable(InputArray)60 Ptr<LookUpTable> cv::cuda::createLookUpTable(InputArray) { throw_no_cuda(); return Ptr<LookUpTable>(); }
61
copyMakeBorder(InputArray,OutputArray,int,int,int,int,int,Scalar,Stream &)62 void cv::cuda::copyMakeBorder(InputArray, OutputArray, int, int, int, int, int, Scalar, Stream&) { throw_no_cuda(); }
63
64 #else /* !defined (HAVE_CUDA) */
65
66 ////////////////////////////////////////////////////////////////////////
67 // flip
68
69 namespace
70 {
71 template<int DEPTH> struct NppTypeTraits;
72 template<> struct NppTypeTraits<CV_8U> { typedef Npp8u npp_t; };
73 template<> struct NppTypeTraits<CV_8S> { typedef Npp8s npp_t; };
74 template<> struct NppTypeTraits<CV_16U> { typedef Npp16u npp_t; };
75 template<> struct NppTypeTraits<CV_16S> { typedef Npp16s npp_t; };
76 template<> struct NppTypeTraits<CV_32S> { typedef Npp32s npp_t; };
77 template<> struct NppTypeTraits<CV_32F> { typedef Npp32f npp_t; };
78 template<> struct NppTypeTraits<CV_64F> { typedef Npp64f npp_t; };
79
80 template <int DEPTH> struct NppMirrorFunc
81 {
82 typedef typename NppTypeTraits<DEPTH>::npp_t npp_t;
83
84 typedef NppStatus (*func_t)(const npp_t* pSrc, int nSrcStep, npp_t* pDst, int nDstStep, NppiSize oROI, NppiAxis flip);
85 };
86
87 template <int DEPTH, typename NppMirrorFunc<DEPTH>::func_t func> struct NppMirror
88 {
89 typedef typename NppMirrorFunc<DEPTH>::npp_t npp_t;
90
call__anon495e0c080111::NppMirror91 static void call(const GpuMat& src, GpuMat& dst, int flipCode, cudaStream_t stream)
92 {
93 NppStreamHandler h(stream);
94
95 NppiSize sz;
96 sz.width = src.cols;
97 sz.height = src.rows;
98
99 nppSafeCall( func(src.ptr<npp_t>(), static_cast<int>(src.step),
100 dst.ptr<npp_t>(), static_cast<int>(dst.step), sz,
101 (flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS))) );
102
103 if (stream == 0)
104 cudaSafeCall( cudaDeviceSynchronize() );
105 }
106 };
107 }
108
flip(InputArray _src,OutputArray _dst,int flipCode,Stream & stream)109 void cv::cuda::flip(InputArray _src, OutputArray _dst, int flipCode, Stream& stream)
110 {
111 typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int flipCode, cudaStream_t stream);
112 static const func_t funcs[6][4] =
113 {
114 {NppMirror<CV_8U, nppiMirror_8u_C1R>::call, 0, NppMirror<CV_8U, nppiMirror_8u_C3R>::call, NppMirror<CV_8U, nppiMirror_8u_C4R>::call},
115 {0,0,0,0},
116 {NppMirror<CV_16U, nppiMirror_16u_C1R>::call, 0, NppMirror<CV_16U, nppiMirror_16u_C3R>::call, NppMirror<CV_16U, nppiMirror_16u_C4R>::call},
117 {0,0,0,0},
118 {NppMirror<CV_32S, nppiMirror_32s_C1R>::call, 0, NppMirror<CV_32S, nppiMirror_32s_C3R>::call, NppMirror<CV_32S, nppiMirror_32s_C4R>::call},
119 {NppMirror<CV_32F, nppiMirror_32f_C1R>::call, 0, NppMirror<CV_32F, nppiMirror_32f_C3R>::call, NppMirror<CV_32F, nppiMirror_32f_C4R>::call}
120 };
121
122 GpuMat src = getInputMat(_src, stream);
123
124 CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S || src.depth() == CV_32F);
125 CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4);
126
127 _dst.create(src.size(), src.type());
128 GpuMat dst = getOutputMat(_dst, src.size(), src.type(), stream);
129
130 funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream));
131
132 syncOutput(dst, _dst, stream);
133 }
134
135 #endif /* !defined (HAVE_CUDA) */
136