SMIL  1.0.4
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''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
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 /*
45  if NEWTDEFS is set to 1 one have this error :
46 
47  im = sp.Image('UINT16', 10,10)
48  swig/python detected a memory leak of type 'uint16_t *', no destructor found.
49  */
50 #define NEWTDEFS 0
51 
52 namespace smil
53 {
54  typedef int INT;
55  typedef long LONG;
56  typedef unsigned int UINT;
57  typedef unsigned long ULONG;
58 #if NEWTDEFS
59  typedef uint8_t UINT8;
60  typedef uint16_t UINT16;
61  typedef uint32_t UINT32;
62 #else
63  typedef unsigned char UINT8;
64  typedef unsigned short UINT16;
65  typedef unsigned int UINT32;
66 #endif
67 #ifdef _MSC_VER
68  typedef unsigned __int64 UINT64;
69 #else
70  typedef uint64_t UINT64;
71 #endif
72 
73  // typedef unsigned char __attribute__ ((vector_size (16))) alUINT8;
74 
75  // Why this directive for msvc (windows) ?
76  //#ifndef _MSC_VER
77  typedef signed char INT8;
78  //#endif // _MSC_VER
79  typedef short INT16;
80  typedef int INT32;
81 
82 #ifndef CHAR_BIT
83 #define CHAR_BIT 8
84 #endif
85 
86  enum DType { DtUINT8, DtUINT16, DtUINT32, DtUINT64, DtINT, DtUINT };
87 
88  template <class T> struct ImDtTypes {
89  typedef T pixelType;
90  typedef pixelType *lineType;
91 #ifndef SWIG
92  typedef pixelType *restrictLineType;
93  // XXX JOE typedef pixelType * __restrict restrictLineType;
94 #endif // SWIG
95  typedef lineType *sliceType;
96  typedef sliceType *volType;
97 
98  typedef std::vector<T, Allocator<T>> vectorType;
99  // typedef std::vector<T> vectorType;
100  typedef std::vector<vectorType> matrixType;
101 
102  typedef double floatType;
103 
104  static inline pixelType min()
105  {
106  return numeric_limits<T>::min();
107  }
108  static inline pixelType max()
109  {
110  return numeric_limits<T>::max();
111  }
112  static inline size_t cardinal()
113  {
114  return size_t(max() - min()) + 1;
115  }
116  static inline lineType createLine(size_t lineLen)
117  {
118  return createAlignedBuffer<T>(lineLen);
119  }
120  static inline void deleteLine(lineType line)
121  {
122  deleteAlignedBuffer<T>(line);
123  }
124  static inline size_t ptrOffset(lineType p, size_t n = SIMD_VEC_SIZE)
125  {
126  return ((size_t) p) & (n - 1);
127  }
128  static inline std::string toString(const T &val)
129  {
130  stringstream str;
131  str << double(val);
132  return str.str();
133  }
134  };
135 
136  template <class T>
137  inline const char *getDataTypeAsString(T * /*val*/ = (T *) NULL)
138  {
139  return "Unknown";
140  }
141 
142 #define DECL_DATA_TYPE_STR(_type) \
143  template <> inline const char *getDataTypeAsString(_type *) \
144  { \
145  return #_type; \
146  }
147 
148  DECL_DATA_TYPE_STR(UINT8)
149  DECL_DATA_TYPE_STR(UINT16)
150  DECL_DATA_TYPE_STR(UINT32)
151  DECL_DATA_TYPE_STR(INT8)
152  DECL_DATA_TYPE_STR(INT16)
153  // INT32 and int are the same.
154  // DECL_DATA_TYPE_STR(INT32)
155  DECL_DATA_TYPE_STR(int)
156  DECL_DATA_TYPE_STR(float)
157  DECL_DATA_TYPE_STR(double)
158 
159 } // namespace smil
160 
161 #endif // _D_TYPES_HPP
Definition: DTypes.hpp:88