• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
pyrDown(InputArray,OutputArray,Stream &)50 void cv::cuda::pyrDown(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
pyrUp(InputArray,OutputArray,Stream &)51 void cv::cuda::pyrUp(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
52 
53 #else // HAVE_CUDA
54 
55 //////////////////////////////////////////////////////////////////////////////
56 // pyrDown
57 
58 namespace cv { namespace cuda { namespace device
59 {
60     namespace imgproc
61     {
62         template <typename T> void pyrDown_gpu(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
63     }
64 }}}
65 
pyrDown(InputArray _src,OutputArray _dst,Stream & stream)66 void cv::cuda::pyrDown(InputArray _src, OutputArray _dst, Stream& stream)
67 {
68     using namespace cv::cuda::device::imgproc;
69 
70     typedef void (*func_t)(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
71     static const func_t funcs[6][4] =
72     {
73         {pyrDown_gpu<uchar>      , 0 /*pyrDown_gpu<uchar2>*/ , pyrDown_gpu<uchar3>      , pyrDown_gpu<uchar4>      },
74         {0 /*pyrDown_gpu<schar>*/, 0 /*pyrDown_gpu<schar2>*/ , 0 /*pyrDown_gpu<schar3>*/, 0 /*pyrDown_gpu<schar4>*/},
75         {pyrDown_gpu<ushort>     , 0 /*pyrDown_gpu<ushort2>*/, pyrDown_gpu<ushort3>     , pyrDown_gpu<ushort4>     },
76         {pyrDown_gpu<short>      , 0 /*pyrDown_gpu<short2>*/ , pyrDown_gpu<short3>      , pyrDown_gpu<short4>      },
77         {0 /*pyrDown_gpu<int>*/  , 0 /*pyrDown_gpu<int2>*/   , 0 /*pyrDown_gpu<int3>*/  , 0 /*pyrDown_gpu<int4>*/  },
78         {pyrDown_gpu<float>      , 0 /*pyrDown_gpu<float2>*/ , pyrDown_gpu<float3>      , pyrDown_gpu<float4>      }
79     };
80 
81     GpuMat src = _src.getGpuMat();
82 
83     CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
84 
85     const func_t func = funcs[src.depth()][src.channels() - 1];
86     CV_Assert( func != 0 );
87 
88     _dst.create((src.rows + 1) / 2, (src.cols + 1) / 2, src.type());
89     GpuMat dst = _dst.getGpuMat();
90 
91     func(src, dst, StreamAccessor::getStream(stream));
92 }
93 
94 
95 //////////////////////////////////////////////////////////////////////////////
96 // pyrUp
97 
98 namespace cv { namespace cuda { namespace device
99 {
100     namespace imgproc
101     {
102         template <typename T> void pyrUp_gpu(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
103     }
104 }}}
105 
pyrUp(InputArray _src,OutputArray _dst,Stream & stream)106 void cv::cuda::pyrUp(InputArray _src, OutputArray _dst, Stream& stream)
107 {
108     using namespace cv::cuda::device::imgproc;
109 
110     typedef void (*func_t)(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream);
111     static const func_t funcs[6][4] =
112     {
113         {pyrUp_gpu<uchar>      , 0 /*pyrUp_gpu<uchar2>*/ , pyrUp_gpu<uchar3>      , pyrUp_gpu<uchar4>      },
114         {0 /*pyrUp_gpu<schar>*/, 0 /*pyrUp_gpu<schar2>*/ , 0 /*pyrUp_gpu<schar3>*/, 0 /*pyrUp_gpu<schar4>*/},
115         {pyrUp_gpu<ushort>     , 0 /*pyrUp_gpu<ushort2>*/, pyrUp_gpu<ushort3>     , pyrUp_gpu<ushort4>     },
116         {pyrUp_gpu<short>      , 0 /*pyrUp_gpu<short2>*/ , pyrUp_gpu<short3>      , pyrUp_gpu<short4>      },
117         {0 /*pyrUp_gpu<int>*/  , 0 /*pyrUp_gpu<int2>*/   , 0 /*pyrUp_gpu<int3>*/  , 0 /*pyrUp_gpu<int4>*/  },
118         {pyrUp_gpu<float>      , 0 /*pyrUp_gpu<float2>*/ , pyrUp_gpu<float3>      , pyrUp_gpu<float4>      }
119     };
120 
121     GpuMat src = _src.getGpuMat();
122 
123     CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
124 
125     const func_t func = funcs[src.depth()][src.channels() - 1];
126     CV_Assert( func != 0 );
127 
128     _dst.create(src.rows * 2, src.cols * 2, src.type());
129     GpuMat dst = _dst.getGpuMat();
130 
131     func(src, dst, StreamAccessor::getStream(stream));
132 }
133 
134 #endif
135