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 #if !defined HAVE_CUDA || defined(CUDA_DISABLER)
46
resize(InputArray,OutputArray,Size,double,double,int,Stream &)47 void cv::cuda::resize(InputArray, OutputArray, Size, double, double, int, Stream&) { throw_no_cuda(); }
48
49 #else // HAVE_CUDA
50
51 namespace cv { namespace cuda { namespace device
52 {
53 template <typename T>
54 void resize(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
55 }}}
56
resize(InputArray _src,OutputArray _dst,Size dsize,double fx,double fy,int interpolation,Stream & stream)57 void cv::cuda::resize(InputArray _src, OutputArray _dst, Size dsize, double fx, double fy, int interpolation, Stream& stream)
58 {
59 GpuMat src = _src.getGpuMat();
60
61 typedef void (*func_t)(const PtrStepSzb& src, const PtrStepSzb& srcWhole, int yoff, int xoff, const PtrStepSzb& dst, float fy, float fx, int interpolation, cudaStream_t stream);
62 static const func_t funcs[6][4] =
63 {
64 {device::resize<uchar> , 0 /*device::resize<uchar2>*/ , device::resize<uchar3> , device::resize<uchar4> },
65 {0 /*device::resize<schar>*/, 0 /*device::resize<char2>*/ , 0 /*device::resize<char3>*/, 0 /*device::resize<char4>*/},
66 {device::resize<ushort> , 0 /*device::resize<ushort2>*/, device::resize<ushort3> , device::resize<ushort4> },
67 {device::resize<short> , 0 /*device::resize<short2>*/ , device::resize<short3> , device::resize<short4> },
68 {0 /*device::resize<int>*/ , 0 /*device::resize<int2>*/ , 0 /*device::resize<int3>*/ , 0 /*device::resize<int4>*/ },
69 {device::resize<float> , 0 /*device::resize<float2>*/ , device::resize<float3> , device::resize<float4> }
70 };
71
72 CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 );
73 CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC || interpolation == INTER_AREA );
74 CV_Assert( !(dsize == Size()) || (fx > 0 && fy > 0) );
75
76 if (dsize == Size())
77 {
78 dsize = Size(saturate_cast<int>(src.cols * fx), saturate_cast<int>(src.rows * fy));
79 }
80 else
81 {
82 fx = static_cast<double>(dsize.width) / src.cols;
83 fy = static_cast<double>(dsize.height) / src.rows;
84 }
85
86 _dst.create(dsize, src.type());
87 GpuMat dst = _dst.getGpuMat();
88
89 if (dsize == src.size())
90 {
91 src.copyTo(dst, stream);
92 return;
93 }
94
95 const func_t func = funcs[src.depth()][src.channels() - 1];
96
97 if (!func)
98 CV_Error(Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
99
100 Size wholeSize;
101 Point ofs;
102 src.locateROI(wholeSize, ofs);
103 PtrStepSzb wholeSrc(wholeSize.height, wholeSize.width, src.datastart, src.step);
104
105 func(src, wholeSrc, ofs.y, ofs.x, dst, static_cast<float>(1.0 / fy), static_cast<float>(1.0 / fx), interpolation, StreamAccessor::getStream(stream));
106 }
107
108 #endif // HAVE_CUDA
109