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) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
44 #ifndef __OPENCV_CORE_TRAITS_HPP__
45 #define __OPENCV_CORE_TRAITS_HPP__
47 #include "opencv2/core/cvdef.h"
53 Informative template class for OpenCV "scalars".
55 The class is specialized for each primitive numerical type supported by OpenCV (such as unsigned char or float),
56 as well as for more complex types, like cv::Complex<>, std::complex<>, cv::Vec<> etc.
57 The common property of all such types (called "scalars", do not confuse it with cv::Scalar_)
58 is that each of them is basically a tuple of numbers of the same type. Each "scalar" can be represented
59 by the depth id (CV_8U ... CV_64F) and the number of channels.
60 OpenCV matrices, 2D or nD, dense or sparse, can store "scalars",
61 as long as the number of channels does not exceed CV_CN_MAX.
63 template<typename _Tp> class DataType
66 typedef _Tp value_type;
67 typedef value_type work_type;
68 typedef value_type channel_type;
69 typedef value_type vec_type;
70 enum { generic_type = 1,
74 type = CV_MAKETYPE(depth, channels)
78 template<> class DataType<bool>
81 typedef bool value_type;
82 typedef int work_type;
83 typedef value_type channel_type;
84 typedef value_type vec_type;
85 enum { generic_type = 0,
89 type = CV_MAKETYPE(depth, channels)
93 template<> class DataType<uchar>
96 typedef uchar value_type;
97 typedef int work_type;
98 typedef value_type channel_type;
99 typedef value_type vec_type;
100 enum { generic_type = 0,
104 type = CV_MAKETYPE(depth, channels)
108 template<> class DataType<schar>
111 typedef schar value_type;
112 typedef int work_type;
113 typedef value_type channel_type;
114 typedef value_type vec_type;
115 enum { generic_type = 0,
119 type = CV_MAKETYPE(depth, channels)
123 template<> class DataType<char>
126 typedef schar value_type;
127 typedef int work_type;
128 typedef value_type channel_type;
129 typedef value_type vec_type;
130 enum { generic_type = 0,
134 type = CV_MAKETYPE(depth, channels)
138 template<> class DataType<ushort>
141 typedef ushort value_type;
142 typedef int work_type;
143 typedef value_type channel_type;
144 typedef value_type vec_type;
145 enum { generic_type = 0,
149 type = CV_MAKETYPE(depth, channels)
153 template<> class DataType<short>
156 typedef short value_type;
157 typedef int work_type;
158 typedef value_type channel_type;
159 typedef value_type vec_type;
160 enum { generic_type = 0,
164 type = CV_MAKETYPE(depth, channels)
168 template<> class DataType<int>
171 typedef int value_type;
172 typedef value_type work_type;
173 typedef value_type channel_type;
174 typedef value_type vec_type;
175 enum { generic_type = 0,
179 type = CV_MAKETYPE(depth, channels)
183 template<> class DataType<float>
186 typedef float value_type;
187 typedef value_type work_type;
188 typedef value_type channel_type;
189 typedef value_type vec_type;
190 enum { generic_type = 0,
194 type = CV_MAKETYPE(depth, channels)
198 template<> class DataType<double>
201 typedef double value_type;
202 typedef value_type work_type;
203 typedef value_type channel_type;
204 typedef value_type vec_type;
205 enum { generic_type = 0,
209 type = CV_MAKETYPE(depth, channels)
215 A helper class for cv::DataType
217 The class is specialized for each fundamental numerical data type supported by OpenCV.
218 It provides DataDepth<T>::value constant.
220 template<typename _Tp> class DataDepth
225 value = DataType<_Tp>::depth,
226 fmt = DataType<_Tp>::fmt
232 template<int _depth> class TypeDepth
234 enum { depth = CV_USRTYPE1 };
235 typedef void value_type;
238 template<> class TypeDepth<CV_8U>
240 enum { depth = CV_8U };
241 typedef uchar value_type;
244 template<> class TypeDepth<CV_8S>
246 enum { depth = CV_8S };
247 typedef schar value_type;
250 template<> class TypeDepth<CV_16U>
252 enum { depth = CV_16U };
253 typedef ushort value_type;
256 template<> class TypeDepth<CV_16S>
258 enum { depth = CV_16S };
259 typedef short value_type;
262 template<> class TypeDepth<CV_32S>
264 enum { depth = CV_32S };
265 typedef int value_type;
268 template<> class TypeDepth<CV_32F>
270 enum { depth = CV_32F };
271 typedef float value_type;
274 template<> class TypeDepth<CV_64F>
276 enum { depth = CV_64F };
277 typedef double value_type;
282 #endif // __OPENCV_CORE_TRAITS_HPP__