-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStereoCommon.h
More file actions
97 lines (81 loc) · 2.67 KB
/
StereoCommon.h
File metadata and controls
97 lines (81 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include "stdlib.h"
#include "stdint.h"
#include <algorithm>
#include <limits.h>
// Types
typedef float float32;
typedef double float64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef int8_t sint8;
typedef int16_t sint16;
typedef int32_t sint32;
// Defines
#define SINT32_MAX ((sint32) 2147483647)
#define SINT16_MAX ((sint16)0x7fff)
#ifdef WIN32
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#define NAN (*(const float *) __nan)
#endif
#define FORCEINLINE __forceinline
#define ALIGN16 __declspec(align(16))
#define ALIGN32 __declspec(align(32))
#define ASSERT(x) assert(x)
#else
#define FORCEINLINE inline __attribute__((always_inline))
#define ALIGN16 __attribute__ ((aligned(16)))
#define UINT16_MAX ((uint16)0xffffU)
#define ALIGN32 __attribute__ ((aligned(32)))
#define ASSERT(x) assert(x)
#endif
#define UNUSED(x) (void)(x)
// Macros and inlines
#ifdef MAX
#undef MAX
#endif
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define ROUND(x) ( ((x) >= 0.0f) ? ((sint32)((x) + 0.5f)) : ((sint32)((x) - 0.5f)) )
#define SIGN(u,v) ( ((v)>=0.0) ? ABS(u) : -ABS(u) )
#define ABS(x) abs(x)
//inline float rangeCut(float min, float value, float max) {
// if (value<min)
// value = min;
// if (value>max)
// value = max;
// return value;
//}
// saturate casts
template<typename _Tp> static inline _Tp saturate_cast(uint8 v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(sint8 v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(uint16 v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(sint16 v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(uint32 v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(sint32 v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(float32 v) { return _Tp(v); }
template<> inline uint16 saturate_cast<uint16>(sint8 v)
{
return (uint16)std::max((int)v, 0);
}
template<> inline uint16 saturate_cast<uint16>(sint16 v)
{
return (uint16)std::max((int)v, 0);
}
template<> inline uint16 saturate_cast<uint16>(sint32 v)
{
return (uint16)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0);
}
template<> inline uint16 saturate_cast<uint16>(uint32 v)
{
return (uint16)std::min(v, (unsigned)USHRT_MAX);
}
template<> inline uint16 saturate_cast<uint16>(float v)
{
int iv = ROUND(v); return saturate_cast<uint16>(iv);
}