SMIL  0.9.1
DTypes.hpp
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _D_TYPES_HPP
31 #define _D_TYPES_HPP
32 
33 #ifndef _MSC_VER
34 #include <stdint.h>
35 #endif // _MSC_VER
36 #include <limits>
37 
38 #include "Core/include/private/DMemory.hpp"
39 
40 #include <sstream>
41 
42 using namespace std;
43 
44 namespace smil
45 {
46  typedef int INT;
47  typedef unsigned int UINT;
48  typedef unsigned char UINT8;
49  typedef unsigned short UINT16;
50  typedef unsigned int UINT32;
51 #ifdef _MSC_VER
52  typedef unsigned __int64 UINT64;
53 #else
54  typedef uint64_t UINT64;
55 #endif
56 
57  // typedef unsigned char __attribute__ ((vector_size (16))) alUINT8;
58 
59  // Why this directive for msvc (windows) ?
60  //#ifndef _MSC_VER
61  typedef signed char INT8;
62  //#endif // _MSC_VER
63  typedef short INT16;
64  typedef int INT32;
65 
66 
67  #ifndef CHAR_BIT
68  #define CHAR_BIT 8
69  #endif
70 
71  enum DType
72  {
73  DtUINT8, DtUINT16, DtUINT32, DtUINT64, DtINT, DtUINT
74  };
75 
76 
77  template <class T>
78  struct ImDtTypes
79  {
80  typedef T pixelType;
81  typedef pixelType *lineType;
82 #ifndef SWIG
83  typedef pixelType * __restrict restrictLineType;
84 #endif // SWIG
85  typedef lineType *sliceType;
86  typedef sliceType *volType;
87 
88  typedef std::vector<T, Allocator<T> > vectorType;
89 // typedef std::vector<T> vectorType;
90  typedef std::vector< vectorType > matrixType;
91 
92  typedef double floatType;
93 
94  static inline pixelType min() { return numeric_limits<T>::min(); }
95  static inline pixelType max() { return numeric_limits<T>::max(); }
96  static inline size_t cardinal() { return max()-min()+1; }
97  static inline lineType createLine(size_t lineLen) { return createAlignedBuffer<T>(lineLen); }
98  static inline void deleteLine(lineType line) { deleteAlignedBuffer<T>(line); }
99  static inline size_t ptrOffset(lineType p, size_t n=SIMD_VEC_SIZE) { return ((size_t)p) & (n-1); }
100  static inline std::string toString(const T &val)
101  {
102  stringstream str;
103  str << double(val);
104  return str.str();
105  }
106  };
107 
108 
109 
110  template <class T>
111  inline const char *getDataTypeAsString(T * /*val*/ =(T*)NULL)
112  {
113  return "Unknown";
114  }
115 
116 
117  #define DECL_DATA_TYPE_STR(_type) \
118  template <> \
119  inline const char *getDataTypeAsString(_type *) { return #_type; }
120 
121  DECL_DATA_TYPE_STR(UINT8)
122  DECL_DATA_TYPE_STR(UINT16)
123  DECL_DATA_TYPE_STR(INT8)
124  DECL_DATA_TYPE_STR(INT16)
125  DECL_DATA_TYPE_STR(int)
126  DECL_DATA_TYPE_STR(float)
127  DECL_DATA_TYPE_STR(double)
128 
129 } // namespace smil
130 
131 
132 #endif // _D_TYPES_HPP
Definition: DColorConvert.h:38
Definition: DTypes.hpp:78