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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/** \file
* \brief Math Operations
*
* See Copyright Notice in im_lib.h
*/
#ifndef __IM_MATH_OP_H
#define __IM_MATH_OP_H
#include "im_complex.h"
//#define IM_NEARZERO 0.0000001f
//#define IM_NEARINF 10000000
/// Crop value to Byte limit
template <class T>
inline T crop_byte(const T& v)
{
return v <= 0? 0: v <= 255? v: 255;
}
/// Generic Addition with 2 template types
template <class T1, class T2>
inline T1 add_op(const T1& v1, const T2& v2)
{
return v2 + v1;
}
/// Generic Subtraction with 2 template types
template <class T1, class T2>
inline T1 sub_op(const T1& v1, const T2& v2)
{
return v2 - v1;
}
/// Generic Multiplication with 2 template types
template <class T1, class T2>
inline T1 mul_op(const T1& v1, const T2& v2)
{
return v2 * v1;
}
/// Generic Division with 2 template types
template <class T1, class T2>
inline T1 div_op(const T1& v1, const T2& v2)
{
// if (v2 == 0) return (T1)IM_NEARINF;
return v1 / v2;
}
/// Generic Invert
template <class T>
inline T inv_op(const T& v)
{
// if (v == 0) return (T)IM_NEARINF;
return 1/v;
}
/// Generic Difference with 2 template types
template <class T1, class T2>
inline T1 diff_op(const T1& v1, const T2& v2)
{
if (v1 <= v2)
return v2 - v1;
return v1 - v2;
}
/// Generic Minimum with 2 template types
template <class T1, class T2>
inline T1 min_op(const T1& v1, const T2& v2)
{
if (v1 <= v2)
return v1;
return v2;
}
/// Generic Maximum with 2 template types
template <class T1, class T2>
inline T1 max_op(const T1& v1, const T2& v2)
{
if (v1 <= v2)
return v2;
return v1;
}
inline imbyte pow_op(const imbyte& v1, const imbyte& v2)
{
return (imbyte)pow((float)v1, v2);
}
inline imushort pow_op(const imushort& v1, const imushort& v2)
{
return (imushort)pow((float)v1, v2);
}
inline int pow_op(const int& v1, const int& v2)
{
return (int)pow((float)v1, v2);
}
/// Generic Power with 2 template types
template <class T1, class T2>
inline T1 pow_op(const T1& v1, const T2& v2)
{
return (T1)pow(v1, v2);
}
/// Generic Abssolute
template <class T>
inline T abs_op(const T& v)
{
if (v <= 0)
return -1*v;
return v;
}
/// Generic Less
template <class T>
inline T less_op(const T& v)
{
return -1*v;
}
/// Generic Square
template <class T>
inline T sqr_op(const T& v)
{
return v*v;
}
inline int sqrt(const int& C)
{
return (int)sqrt(float(C));
}
/// Generic Square Root
template <class T>
inline T sqrt_op(const T& v)
{
return (T)sqrt(v);
}
inline int exp(const int& v)
{
return (int)exp((float)v);
}
/// Generic Exponential
template <class T>
inline T exp_op(const T& v)
{
return (T)exp(v);
}
inline int log(const int& v)
{
return (int)log((float)v);
}
/// Generic Logarithm
template <class T>
inline T log_op(const T& v)
{
// if (v <= 0) return (T)IM_NEARINF;
return (T)log(v);
}
// Dummy sin
inline imcfloat sin(const imcfloat& v)
{
return (v);
}
inline int sin(const int& v)
{
return (int)sin((float)v);
}
/// Generic Sine
template <class T>
inline T sin_op(const T& v)
{
return (T)sin(v);
}
inline int cos(const int& v)
{
return (int)cos((float)v);
}
// Dummy cos
inline imcfloat cos(const imcfloat& v)
{
return (v);
}
/// Generic Cosine
template <class T>
inline T cos_op(const T& v)
{
return (T)cos(v);
}
/// Sets a bit in an array
inline void imDataBitSet(imbyte* data, int index, int bit)
{
if (bit)
data[index / 8] |= (0x01 << (7 - (index % 8)));
else
data[index / 8] &= ~(0x01 << (7 - (index % 8)));
}
/// Gets a bit from an array
inline int imDataBitGet(imbyte* data, int index)
{
return (data[index / 8] >> (7 - (index % 8))) & 0x01;
}
#endif
|